What's new

Tutorial Form Alway on TOP VB6

Status
Not open for further replies.

CodeWarrior

Addict
Joined
Feb 16, 2014
Posts
23
Reaction
16
Points
78
Age
39
This simple tutorial demonstrate how to create a form always on top to other
simple but it is useful....

First new project open your VB6

Second Add two command button to the form, command1 change the caption to "TOP MOST", command2 change the caption to "UN TOP"

Third Add Module
On the Module Copy and paste this code

Code:
Public Const ST_UNMOVE = 2
Public Const ST_UNSIZE = 1
Public Const FLAGS = ST_UNMOVE Or ST_UNSIZE
Public Const HWND_ALLTOP = -1
Public Const HWND_UNTOP = -2

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
                                            ByVal hWndInsertAfter As Long, _
                                            ByVal a As Long, _
                                            ByVal b As Long, _
                                            ByVal c As Long, _
                                            ByVal d As Long, _
                                            ByVal eFlags As Long) As Long
                                           

Public Function SetTopWindow(hwnd As Long, Top As Boolean) As Long
         If Top = True Then 'Make the window always top to Other
            SetTopWindow = SetWindowPos(hwnd, HWND_ALLTOP, 0, 0, 0, 0, FLAGS)
         Else
            SetTopWindow = SetWindowPos(hwnd, HWND_UNTOP, 0, 0, 0, 0, FLAGS)
            SetTopWindow = False
         End If
End Function

And the Form1 copy and paste this code

Code:
Option Explicit

Private Sub Command1_Click()
    Dim ATOP As Long
    ATOP = SetTopWindow(Form1.hwnd, True)
End Sub

Private Sub Command2_Click()
    Dim UTOP As Long
    UTOP = SetTopWindow(Form1.hwnd, False)
End Sub

Finally the last press F5 to start debuging...

Click command1 to set the form always on top
Click command2 to set the form as normal mode

Happy Happy Coding....

CodeWarrior :)
 
Status
Not open for further replies.
Back
Top