Sunday, July 10, 2011

How the project always on top?



'Set window to be top most (always on top)
'This code will allow you to toggle your window as
'being always on top or not always 'on top,
'as seen in things like AIM and HTML Help.
Option Explicit

    'declare constants:
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40

    'declare API:
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, _
      ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, _
      ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Private Sub Command1_Click()
      'set topmost:
    SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Command2_Click()
      'set not topmost:
    SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Form_Load()
      'project requires 2 commandbuttons:
    Command1.Caption = "Top Most"
    Command2.Caption = "Not Top Most"
End Sub

No comments:

Post a Comment