怎样使我的程序总处于屏幕最前方?(Always on top) 如果你想让你的程序处于前方,可以使用以下代码: Form1.ZOrder 配合计时器使用,每隔一段很小的时间间隔调用这种方法可以使窗体Form1处于屏幕前方,但是用户还是可能使别的窗体在短暂的时间里处于Form1的上方。所以这种方法并不能使窗体真正的实现Always on top,而要真正的Always on top可以使用API函数SetWindowPos,代码如下: '声明函数: Declare Function SetWindowPos Lib "user32" _ (ByVal h%, ByVal hb%, ByVal x%, ByVal y%, _ ByVal cx%,ByVal cy%,ByVal f%) As Integer Global Const SWP_NOMOVE = 2 Global Const SWP_NOSIZE = 1 Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Global Const HWND_TOPMOST = -1 Global Const HWND_NOTOPMOST = -2 '把窗体放在最前面: res% = SetWindowPos (Form1.hWnd, HWND_TOPMOST, _ 0, 0, 0, 0, FLAGS) '如果res%=0, 就产生错误 '使窗体恢复普通模式: res% = SetWindowPos (Form1.hWnd, HWND_NOTOPMOST, _ 0, 0, 0, 0, FLAGS)
setwindoowpos me.hwnd,hwnd_topmost,0,0,0,0,flags
Private Const HWND_TOPMOST& = -1Private 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)Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 740, 540, SWP_NOMOVE
End Sub
SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, &H1 Or &H2 '使窗体位于最顶端