- 中查找“拖动无标题窗口”更多相关内容
- 中查找“拖动无标题窗口”更多相关内容
- ·上一篇文章:往列表框中填入文件目录信息
- ·下一篇文章:图像在图片框中的滚动
拖动无标题窗口
通常我们是拖动标题栏来移动窗口,当没有标题栏时,该如何来拖动窗口呢?方法是 当我们在窗口区按下鼠标左键时,调用ReleaseCapture函数,释放鼠标的俘获,同时 发送移动标题栏的消息,就可以实现窗口的拖动。
下面的例子实现了该功能。
>>步骤1----建立新工程,在窗体上放置CommandButton按钮。
>>步骤2----改变窗体的外观,使BorderStyle = 0(None)
>>步骤3----编写如下代码:
Private Declare Function ReleaseCapture Lib "user32" () As Long
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 Const WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Command1_Click()
End
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
''SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
''上述两种方法都能实现该功能。
End Sub
>>步骤4----编译运行,在窗体上按下鼠标左键,是不是可以拖动了?按下Command1结束。