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)?
Asked
Active
Viewed 7,123 times
1
-
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645481%28v=vs.85%29.aspx – Hans Passant Jan 18 '15 at 17:58
-
1http://msdn.microsoft.com/en-us/library/77d16yhw.aspx – Hans Passant Jan 18 '15 at 17:59
-
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 Jan 18 '15 at 23:54
1 Answers
4
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);

Glorfindel
- 21,988
- 13
- 81
- 109

Tihomir Tashev
- 185
- 2
- 9