VB如何移动一个外部窗体的位置如到右上角,要求代码实现。

来源:百度知道 编辑:UC知道 时间:2024/05/29 03:20:51
VB如何移动一个外部窗体的位置如到右上角,要求代码实现。

我的想法是,能移动一个不在右上角的软件窗体移动到右上角,用软件
的sendmessage之类的能move它吗?别告诉我直接拿鼠标去移动会更方便之类的话,呵呵,我是要求能有编程的方式去实现,有时确实需要用到的。

'在窗体上加入按钮command1,然后复制下面代码,运行,点击command1,即可看到效果。

'======代码部分======
Option Explicit
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub Command1_Click()
Dim Mwnd As Long, MyTmp As Long, rctemp As RECT
Mwnd = Me.hwnd
GetWindowRect Mwnd, rctemp
MoveWindow Mwnd, Screen.Width / Screen.TwipsPerPixelX - (rctemp.Right), 0, rctemp.Right, rctemp.Bottom, 1
End Sub

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, By