CWnd* pWnd = AfxGetMainWnd(); HWND hWnd = pWnd->GetSafeHwnd();
CButton* pButton = (CButton*)GetDlgItem(IDC_MYBUTTON); HWND hWnd = pButton->GetSafeHwnd();This example gets the handle to a button control with the ID IDC_MYBUTTON and stores it in the variable hWnd. In both examples, CWnd::GetSafeHwnd is called on a pointer to a CWnd object to get the window handle. Overall, CWnd::GetSafeHwnd is a useful function in the MFC library for getting the handle to a window, which is necessary for performing various operations on the window.