VB 如何让一个窗体永远置顶但激活(控件可用)?
VB如何让一个窗体永远置顶但不激活(单击它时也不激活,它上面的控件可用)?就像那个手写输入法的窗口一样,在上面画字但它永不激活从不影响别的窗口的活动状态,请问如何作到?我...
VB 如何让一个窗体永远置顶但不激活(单击它时也不激活,它上面的控件可用)?就像那个手写输入法的窗口一样,在上面画字但它永不激活 从不影响别的窗口的活动状态,请问如何作到?
我的QQ271072330 有空大家一起研究一下啊。。。先谢了 展开
我的QQ271072330 有空大家一起研究一下啊。。。先谢了 展开
展开全部
我看见你这个问题了,研究了半天始终是不太理想,不过我还是告诉你我的答案吧:
用SetWindowPos将窗体至于最前..用SendMessage给窗体发送取消激活的消息可以达到你的要求.
以下是我帮你写的代码:
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) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOPMOST = -1
Private Const WM_NCACTIVATE = &H86
Private Sub Form_Load()
'//将窗体至于最前..
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub
Private Sub Form_Activate()
'//我的问题就在这里:当窗体第一次激活的时候发送取消激活的消息可以成功.但是当这个窗体取消焦点,在获得焦点的时候,怎么也激活不了这里面的代码,没法我只能用循环来解决了...
Do
DoEvents
SendMessage Me.hwnd, WM_NCACTIVATE, 0, 0
Loop
End Sub
我想告诉你的就是 SendMessage Me.hwnd, WM_NCACTIVATE, 0, 0 这句就是取消激活的命令.
用SetWindowPos将窗体至于最前..用SendMessage给窗体发送取消激活的消息可以达到你的要求.
以下是我帮你写的代码:
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) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOPMOST = -1
Private Const WM_NCACTIVATE = &H86
Private Sub Form_Load()
'//将窗体至于最前..
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub
Private Sub Form_Activate()
'//我的问题就在这里:当窗体第一次激活的时候发送取消激活的消息可以成功.但是当这个窗体取消焦点,在获得焦点的时候,怎么也激活不了这里面的代码,没法我只能用循环来解决了...
Do
DoEvents
SendMessage Me.hwnd, WM_NCACTIVATE, 0, 0
Loop
End Sub
我想告诉你的就是 SendMessage Me.hwnd, WM_NCACTIVATE, 0, 0 这句就是取消激活的命令.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询