Win32: setting focus impossible!?

Started by
1 comment, last by VanKurt 16 years, 11 months ago
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
Advertisement
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.
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!

This topic is closed to new replies.

Advertisement