使窗体保持在最上层
有时应用程序需要一个信息或查询窗体总保持在最上层,即使用读书切换到其他窗体也能看到该窗体,如Microsoft Word中的Find窗体,这是通过调用Windows API函数SetWindowPos()实现的,示例如下:
Option Explicit
Private Declare Function SetWindowPos Lib“User32”(ByValhwnd As Long,ByVal h WndInsertAfter As Long,ByVal x As Long,ByVAl y As Long,ByVal cx As Long,ByVal cy As Long,ByVal wFlags As Long)As Long
Const HWND_TOPMOST=-1
Const SWP_SHOWWINDOW=&H40
Private Sub Form_load()
Dim retValue As Long
RetValue=setWindowPos(me.hwnd,HWND_TOPMOST,Me.CurrentX,Me.CurrentY,300,300,SWP_SHOWWINDOW)
End Sub
Public 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) As Long
Public Const HWND_TOPMOST = -1
Public Function OnTop(ByVal hWnd As Long, ByVal frmlef As Long, ByVal frmtop As Long, ByVal frmwid As Long, ByVal frmhei As Long)
SetWindowPos hWnd, HWND_TOPMOST, frmlef / Screen.TwipsPerPixelX, frmtop \ Screen.TwipsPerPixelY, frmwid \ Screen.TwipsPerPixelX, frmhei \ Screen.TwipsPerPixelY, 0
End Function
窗体:
private sub form_load()
call ontop(me.hwnd,me.left,me.top,me.width,me.height)
end sub