搞定:Public Sub TopForm(hwnd As Long, bTop As Boolean) If IsWindow(hwnd) = False Then Exit Sub End If If bTop Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Else SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End If End Sub得到对方窗口的句柄,我是用热键来实现的,你自己也可设定什么时候扫描: Public Function GetHwnd() As Long Dim point As POINTAPI GetCursorPos point GetHwnd = WindowFromPoint(point.x, point.y) End Function
我的程序在VB6.0+WinXp(Sp2)下通过
先取得另外一个程序的窗口的句柄,假设为其句柄为 FrmHandle则使用下面的语句即可使其置顶:函数声明: Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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) As Long使用:Call SetWindowPos(FrmHandle,-1,0,0,0,0,3)
Wai...
就像你启动了一辆汽车A,然后跑到汽车B上把A停掉一样
不知道高手有没有什么好办法
If IsWindow(hwnd) = False Then
Exit Sub
End If
If bTop Then
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Else
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End If
End Sub得到对方窗口的句柄,我是用热键来实现的,你自己也可设定什么时候扫描:
Public Function GetHwnd() As Long
Dim point As POINTAPI
GetCursorPos point
GetHwnd = WindowFromPoint(point.x, point.y)
End Function
Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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) As Long使用:Call SetWindowPos(FrmHandle,-1,0,0,0,0,3)