Summary of VC++ programming methods to get a window handle

  • 2020-05-26 09:50:53
  • OfStack

This article demonstrates how VC++ programmatically gets a window handle. I will share it with you for your reference as follows:

In VC++ programming often need to get control or window handle, the following summarizes several methods, also hope you can add more.

1. The handle to its own window can be obtained by AfxGetMainWnd.

2. Other window handles of APP in the system can be obtained by FindWindow (do 1 a favor with SPY).


HWND hBtnClose;
HWND hWnd=::FindWindow(NULL," tencent QQ System of radio ");
if(hWnd)
{
  hBtnClose=GetDlgItem(hWnd,2);
  if(hBtnClose)
  PostMessage(hBtnClose,BM_CLICK,NULL,NULL);
}

3. Get the window handle by pointer


HWND hwnd = pwnd->m_hwnd; // Get it HWND , object or pointer 

4. When we want to get a handle to a pointer to a window object (a derived object of CWnd) (HWND), the safest way is to use GetSafeHwnd() Functions;

5,


HWND GetDlgltem(HWND hDlg,int nlDDlgltem);

6. Get through the control ID number.


CListCtrl* pleftList = (CListCtrl* )GetDlgItem(IDC_LIST1);
pleftList->GetSafeHandl();

I hope this article is helpful to you VC++ programming.


Related articles: