Private Declare Function SetWindowPos& Lib "user32" (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) Public Sub SetWindowTop(frm As Form) SetWindowPos frm.hwnd, -1, 0, 0, 0, 0, 3 End Sub 用法: call setwindowtop(form1)
Private Declare Function SetWindowPos& Lib "user32" (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) Public Sub SetWindowTop(frm As Form) SetWindowPos frm.hwnd, -1, 0, 0, 0, 0, 3 End Sub 用法: call setwindowtop(form1)
Private Sub Form_load() Dim retValue As Long '注意在 VB 中运行时,可能不行,但编译成EXE后就可以了 retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, 300, 270, SWP_SHOWWINDOW) End Sub
(1)启动API浏览器,通过该浏览器复制“SetWindowPos”函数的声明语句。 (2)启动Visual Basic,新建一个标准EXE工程。 (3)使用“工程”|“添加模块”菜单项,添加一个新的模块文件。 (4)打开模块的代码窗口,将“SetWindowPos”函数的声明语句粘贴进去。 (5)打开Form1窗体的代码窗口,编写如下程序。 Private Sub Form_Load() retnum = SetWindowPos(Me.hwnd, -1, 600, 200, 100, 100, &H40) If retnum = 0 Then MsgBox "顶层窗口设置失败!", vbOKOnly + vbExclamation End If End Sub(6)运行程序。
Private Declare Function SetWindowPos& Lib "user32" (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)
Public Sub SetWindowTop(frm As Form) SetWindowPos frm.hwnd, -1, 0, 0, 0, 0, 3 End Sub
用法:
call setwindowtop(form1)
Public Sub SetWindowTop(frm As Form) SetWindowPos frm.hwnd, -1, 0, 0, 0, 0, 3 End Sub
用法:
call setwindowtop(form1)
Dim retValue As Long '注意在 VB 中运行时,可能不行,但编译成EXE后就可以了
retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, 300, 270, SWP_SHOWWINDOW)
End Sub
(2)启动Visual Basic,新建一个标准EXE工程。
(3)使用“工程”|“添加模块”菜单项,添加一个新的模块文件。
(4)打开模块的代码窗口,将“SetWindowPos”函数的声明语句粘贴进去。
(5)打开Form1窗体的代码窗口,编写如下程序。
Private Sub Form_Load()
retnum = SetWindowPos(Me.hwnd, -1, 600, 200, 100, 100, &H40)
If retnum = 0 Then
MsgBox "顶层窗口设置失败!", vbOKOnly + vbExclamation
End If
End Sub(6)运行程序。