Sign in to follow this  
VanKurt

Win32: setting focus impossible!?

Recommended Posts

Hey guys! Ich getting crazy trying to set the focus to a button in a dialog. In the WindowProc of the dialog I have the following:
	case WM_INITDIALOG:
		{
			// Set Focus to start button
			SendMessage( hwndDlg, WM_SETFOCUS, (WPARAM)GetDlgItem(hwndDlg, BTN_START), NULL );
			//SetFocus(GetDlgItem(hwndDlg, BTN_START));
	}break;

But neither sending the WM_SETFOCUS message nor using SetFocus() changes a thing. The focus is always on another button, no matter what I do... Any help is apreciated! Thaaaaanks :-D

Share this post


Link to post
Share on other sites
Did you read the MSDN for WM_INITDIALOG?
Quote:
Return Value
The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control given by hwndFocus. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus.

Share this post


Link to post
Share on other sites
Sorry, I left that out in the code I posted. But now I found a way: in the settings of the button there is a flag called "default button". If that is set to true, the button is initially focused.

Thank's for your reply!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this