1
votes

If I have an MFC dialog with a button control on it, is there a way to get construct the HWND or CWND for that control using the button's ID (e.g IDC_BUTTON_YES)?

1
If you use GetDlgItem to get the CWnd pointer, do not store it for later use. There's no guarantee it will be valid later on as it may be a temporary pointer.rrirower

1 Answers

4
votes

Yes, you can use the function GetDlgItem of the MFC dialog!

Here is an example for you:

CWnd*  myWnd = this->GetDlgItem(IDC_LIST1);

// as CListBox

CListBox* myListBox = (CListBox*)this->GetDlgItem(IDC_LIST1);