Amre
Amre

Reputation: 1680

Is there a way to get the Handle or CWnd* of a control using the ID of the control

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)?

Upvotes: 1

Views: 7593

Answers (1)

Tihomir Tashev
Tihomir Tashev

Reputation: 195

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);

Upvotes: 4

Related Questions