views:

11

answers:

1

I have a MS Visual C++ project where I have a CDialog based dialog box with several edit controls. I want to highlight the control with the current focus for the user. I implemented this by getting a pointer to the window that has the current focus with GetFocus() and then obtaining the ID for the focused control with GetDlgCtrlID():

CWnd *pWnd=GetFocus();

idfocus=(pWnd->GetDlgCtrlID());

I then compare this to the current control for which the HBRUSH is being set for in member function OnCtlColor.

This works fine until I click on the window for another application running on my PC. Such as Firefox. At which point my application crashes.

What is the best way to find which control, if any, in a specific dialog box, and only that particular dialog box, has focus? Or maybe restrict to only the same application.