The WM_NCLBUTTON message is
generated by Windows when a user
right-clicks on a window's title bar.
Windows uses this message to determine
whether the window should be moved by
further user actions. If the title bar
does not exist, this message is not
generated. However, it is often useful to
move a window when it doesn't have a
title bar. A window or form in 32-bit
Visual
Basic will not have a title bar under the
following circumstances:
Visual
Basic 4.0
|
Visual
Basic 5.0
|
Caption =
""
|
Caption =
""
|
ControlBox
= False
|
ControlBox
= False
|
MaxButton
= False
|
MinButton
= False
|
The
sample code below illustrates a way of
letting users move a form without a title
bar by simply clicking and dragging it
from anywhere on the form. The code
placed in the MouseMove event procedure
of Form1 may be placed in other event
procedures, if so desired. For example,
the code
could be placed in the MouseDown event
procedure of a Label control allowing
movement of the form by selecting and
dragging from the Label control.
NOTE: In Visual Basic 4.0, a form with a
menu will have the title bar supplied by
default so the method demonstrated below
is not necessary. In Visual Basic 5.0, a
form with a menu will not have a title
bar supplied by default.
Private Declare
Function SendMessage Lib
"User32" Alias
"SendMessageA" (ByVal hWnd As
Long, ByVal wMsg As Long, ByVal wParam As
Long, lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib
"User32" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Private Sub Form_Load()
Command1.Caption = "Exit"
End Sub
Private Sub Form_MouseMove(Button As
Integer, Shift As Integer, X As Single, Y
As Single)
Dim lngReturnValue As Long
If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Me.hWnd,
WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub
Private Sub Command1_Click()
End
End Sub
|