使用API激活forground的窗口 [英] Activate a window to forground using API
问题描述
我开发了这个模块,互联网上的例子似乎要长得多......
有人可以向我解释为什么我的解决方案不起作用吗?
模块modAPI
声明函数SetForegroundWindow Lib" user32" (ByVal hwnd As Long)作为
长
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle .ToInt32)
End Sub
结束模块
< blockquote>
API声明是错误的。自vb6以来类型已更改。使用整数
而不是long。在这种情况下,我会使用intptr。
声明函数SetForegroundWindow Lib" user32" (ByVal hwnd as intptr)As
整数
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle )
结束子
肯
----------------
" D Witherspoon" < DW ********** @ noway.org>在消息中写道
news:un ************** @ TK2MSFTNGP14.phx.gbl ...
我开发了这个模块,互联网上的例子似乎要长得多......
有人可以向我解释为什么我的解决方案不起作用吗?
模块modAPI >
声明函数SetForegroundWindow Lib" user32" (ByVal hwnd As Long)作为
长
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle .ToInt32)
End Sub
结束模块
模块模块1
公共声明函数SetForegroundWindow Lib" user32" (ByVal hwnd As
整数)作为整数
Public Sub SetForeground(ByVal iHandle As Integer)
SetForegroundWindow(iHandle)< br $>
End Sub
结束模块
用法:
-------
SetForeground(frm.Handle.Int32)
''frm''是设置为前景窗口的窗体
例如:
---------
声明:
--- ---------
Dim frm As New Form2
Button1背后(例如):
------------------------------
frm.Show()
Button2背后(例如):
----------------------- -------
SetForeground(frm.Handle.Int32)
Crouchie1998
BA( HONS)MCP MCSE
" Ken Tucker [MVP]" < VB *** @ bellsouth.net> schrieb:API声明错误。自vb6以来类型已更改。使用整数
而不是long。在这种情况下,我会使用intptr。
声明函数SetForegroundWindow Lib" user32" (ByVal hwnd as intptr)
As
整数
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle)
请注意,只有您的应用程序是活动的
应用程序时,这才有效。否则也需要''AttachThreadInput''。换句话说,
窃取并不容易(而且不推荐)来自另一个
申请的焦点。
-
MS Herfried K. Wagner
MVP < URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
I developed this module, examples on the internet seem to be much longer..
Can someone explain to me why my solution doesn''t work?
Module modAPI
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As
Long
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle.ToInt32)
End Sub
End Module
Hi,
API declare is wrong. Types have changed since vb6. Use integer
instead of long. In this case i would use intptr.
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As intptr) As
integer
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle)
End Sub
Ken
----------------
"D Witherspoon" <dw**********@noway.org> wrote in message
news:un**************@TK2MSFTNGP14.phx.gbl...
I developed this module, examples on the internet seem to be much longer..
Can someone explain to me why my solution doesn''t work?
Module modAPI
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As
Long
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle.ToInt32)
End Sub
End Module
Module Module1
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Integer) As Integer
Public Sub SetForeground(ByVal iHandle As Integer)
SetForegroundWindow(iHandle)
End Sub
End Module
Usage:
-------
SetForeground (frm.Handle.Int32)
''frm'' is the Form to set as the foreground window
Example:
---------
Declaration:
------------
Dim frm As New Form2
Behind Button1 (for example):
------------------------------
frm.Show()
Behind Button2 (for example):
------------------------------
SetForeground (frm.Handle.Int32)
Crouchie1998
BA (HONS) MCP MCSE
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb:API declare is wrong. Types have changed since vb6. Use integer
instead of long. In this case i would use intptr.
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As intptr)
As
integer
Public Sub ActivateAppWindow()
SetForegroundWindow(fMain.Handle)
Note that this will only work as long as your application is the active
application. Otherwise ''AttachThreadInput'' is needed too. In other words,
it''s not as easy (and not recommended) to "steal" the focus from another
application.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于使用API激活forground的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!