VC如何获取窗口句柄

2011-01-16 22:16:49|?次阅读|上传:wustguangh【已有?条评论】发表评论

关键词:C/C++, MFC, Visual Studio|来源:唯设编程网

自身窗口句柄可用AfxGetMainWnd获取。系统中其他APP的窗口句柄可用FindWindow获取(用SPY帮一下忙)。AfxGetMainWnd获取自身窗口句柄。可用FindWindow获取系统中其他窗口句柄.

HWND hWnd = AfxGetMainWnd()->m_hWnd;
HWND hWnd =::FindWindow(NULL,"XXXXXX");

如:

HWND hBtnClose;
HWND hWnd=::FindWindow(NULL,"腾讯QQ系统广播");
if(hWnd)
{
    hBtnClose=GetDlgItem(hWnd,2);
    if(hBtnClose)
        PostMessage(hBtnClose,BM_CLICK,NULL,NULL);
}

比如查看 Internet选项 窗口是否正打开着:

hwndParent=::FindWindow("#32770","Internet属性");//(for winme)
hwndParent=::FindWindow("#32770","Internet选项");//(for winXP

 


 

发表评论0条 】
网友评论(共?条评论)..
VC如何获取窗口句柄