惊现高分:100分悬赏!追加100分!VB如何实现窗体置于最前端,并且不是激活窗体。
1个回答
展开全部
我看见你这个问题了,研究了半天始终是不太理想,不过我还是告诉你我的答案吧:
用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
这句就是取消激活的命令.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询