Win32 API 如何 激活另一个应用程序,如VB的 AppActivate那样?
1. 应用程序A 要激活另一个应用程序B
如果 应用程序B的完整标题为titleB,
VB中语句
AppActivate "titleB"
可激活应用程序B
2. C++(如VC) 如何实现?
---------------------------------------------------
HWND hwnd=
::FindWindow( AppB_WndClassName,NULL);
LPARAM thisThID=AfxGetApp()->m_nThreadID;
::SendMessage( hwnd,WM_ACTIVATEAPP,TRUE,thisThID);
----------------------- 不管用呢!------------------
1. 应用程序A 要激活另一个应用程序B
如果 应用程序B的完整标题为titleB,
VB中语句
AppActivate "titleB"
可激活应用程序B
2. C++(如VC) 如何实现?
---------------------------------------------------
HWND hwnd=
::FindWindow( AppB_WndClassName,NULL);
LPARAM thisThID=AfxGetApp()->m_nThreadID;
::SendMessage( hwnd,WM_ACTIVATEAPP,TRUE,thisThID);
----------------------- 不管用呢!------------------
解决方案 »
- vc++ 如何让窗口一开始显示就在屏幕的最左边?
- vc++在sqlserver数据库中如何存取图片信息
- 菜单项的使能问题!
- 如何将ListCtrl的某一行的颜色设置成Highlight,或...
- 在 WIN平台程序中生成的库用在 WIN MFC程序中出错, HELP!
- 如何实现CFileDialog禁止改变目录
- COM怎么学?Who con告诉我?
- 招聘Windows系统编程高手
- Embeded VC问题:包含CListCtrl,CImageList的模式Dialog第二次显示总报错
- 为什么vc++中读取文本文件时,没有\r\n,而是竖杠...
- UDP模式下的http代理如何使用?对方必须开通TCP端口吗?
- 请问:如何在钩子中及时得到任意窗口中的任意控件的句柄?
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
Parameters
hWnd
Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
Msg
Specifies the message to be sent.
wParam
Specifies additional message-specific information.
lParam
Specifies additional message-specific information. WM_ACTIVATEAPP
fActive = (BOOL) wParam; // activation flag
dwThreadID = (DWORD) lParam: // thread identifier
Parameters
fActive
Value of wParam. Specifies whether the window is being activated or deactivated. This parameter is TRUE if the window is being activated; it is FALSE if the window is being deactivated.
dwThreadID
Value of lParam. Specifies a thread identifier. If the fActive parameter is TRUE, dwThreadID is the identifier of the thread that owns the window being deactivated. If fActive is FALSE, dwThreadID is the identifier of the thread that owns the window being activated.
thisThID 这个应该是对方的 进程ID吧?
不管是"什么"线程id, 经测试,应用程序B总能收到消息
这是程序B对WM_ACTIVATEAPP响应的部分记录:
[ 1]: WM_ACTIVATEAPP,0x1,0xE98
[ 3]: WM_ACTIVATEAPP,0x1,0x680
[ 4]: WM_ACTIVATEAPP,0x0,0x20C
[ 9]: WM_ACTIVATEAPP,0x1,0xE98
[ 12]: WM_ACTIVATEAPP,0x0,0x20C
[ 13]: WM_ACTIVATEAPP,0x1,0x0
[ 16]: WM_ACTIVATEAPP,0x1,0xBF8
[ 29]: WM_ACTIVATEAPP,0x1,0x680
可见,问题不是
::SendMessage( hwnd,WM_ACTIVATEAPP,TRUE,thisThID);
语句行"失效",是否要对程序B的窗口"粗暴"一点,把它请到
最上面?!
BringWindowToTop
这2个函数试过没有?
问题已解决,直接用SetWindowPos, <<<对程序B的窗口"粗暴"一点 ::GetWindowRect(hwnd,&rect); ::SetWindowPos(hwnd,HWND_NOTOPMOST,
rect.left ,
rect.top ,
rect.right-rect.left,
rect.bottom -rect.top,
SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);