Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting focus on OK Button

Status
Not open for further replies.

RileyCat

Programmer
Apr 5, 2004
124
US
Hi,

I have a dialog box on which I have coded to trap the enter key to move to the next tab control item rather than activate the okay button.

How can I detect when focus is reset onto the okay button so I can automatically force the OnOk to fire? The okay button always follows the last user entry box (i.e. edit, list, etc) but I don't always know how many tab control items there are before the Ok.

Does anybody have an idea of how I might detect that the Okay button is either the next tab item to get focus or else how to detect when the button does get focus?

I'd be grateful for any suggestions.
 
try this following code snippet:

CButton * pButton = (CButton *)pDialog->GetDlgItem(IDOK);
if(pButton->GetState() & 0x0008)
//do something

0x0008 is a bit mask to compare with GetState() to see if the button has the focus. If so, it will return a non-zero value. Hope this helps!

bdiamond
 
if(hYourOkButtonWhd == GetFocus)
{
//the Ok button has focus
}

The handle to your button you can retrieve with GetDlgItem

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top