In a modal dialog created with DialogBoxParam i use SetFocus to set the input focus to a editbox. the setfocus is contained in a message-handler for WM_COMMAND in my DialogProc.
when the dialog is displayed, the focus is set correctly, but i can not type something into the dialog box as long as i don't click it with the mouse once...
A.M.
My Latest Articles: CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl - A clone of the Excel tab sheet control.
The WS_TABSTOP has nothing to do with your problem. Sorry for my previous message.
You can call the DialogBoxParam with dwInitParam parameter set to the ID of your editbox and call SetFocus on init dialog message like shown below :
A.M.
My Latest Articles: CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl - A clone of the Excel tab sheet control.
well, i'm not sure if this will help. one problem is, that i need the parameter for something else...
basically, it looks like the control i set the focus on does not receive any keyboard input as long as i don't click it once! the caret is showing up in the control i wanted it to be, so that's ok, but it seems as all keyboard input is still forwarded to the dialog itself or whatever...
the edit box seems not to REALLY HAVE the focus after SetFocus, although it visually has.
one problem is, that i need the parameter for something else...
You don't need to pass the ID of editbox as a parameter. You know the value, so you can set the second parameter to this value in GetDlgItem instead of using lParam.
Could you post the source code for your dialog proc?
Last edited by amarcode; November 10th, 2004 at 12:07 PM.
Reason: misspelled word
A.M.
My Latest Articles: CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl - A clone of the Excel tab sheet control.
int CALLBACK LogonDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_CLOSE:
// do something when the dialog is closed
return TRUE;
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
// do something on ok
return TRUE;
break;
case IDCANCEL:
// do something on cancel
return TRUE;
break;
}
break;
case WM_INITDIALOG:
// Set the focus to the correct control
SetFocus(GetDlgItem(hDlg, IDC_EDIT_PWD));
return FALSE;
}
return FALSE;
}
A.M.
My Latest Articles: CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl - A clone of the Excel tab sheet control.
The attached is a working example. Try to set the editbox as a first control on the dialog (Layout->Tab Order).
A.M.
My Latest Articles: CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl - A clone of the Excel tab sheet control.
"The WM_INITDIALOG message is the first message the dialog box procedure receives. If the dialog box procedure returns TRUE, the Windows sets the input focus to the first child window control in the dialog box that has a WS_TABSTOP style. Alternatively, during the processing of WM_INITDIALOG, the dialog box procedure can use SetFocus to set the focus to the one of the child window controls in the dialog box and then return FALSE."
Programming Windows 3.1 Third Edition by Charles Petzold, Page 415.
A.M.
My Latest Articles: CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl - A clone of the Excel tab sheet control.
"The WM_INITDIALOG message is the first message the dialog box procedure receives. If the dialog box procedure returns TRUE, the Windows sets the input focus to the first child window control in the dialog box that has a WS_TABSTOP style. Alternatively, during the processing of WM_INITDIALOG, the dialog box procedure can use SetFocus to set the focus to the one of the child window controls in the dialog box and then return FALSE."
Programming Windows 3.1 Third Edition by Charles Petzold, Page 415.
i know! but it doesn't work anyway... i also inspected the example you posted and did not find any significant differences to my code.
a short description of the solution:
when the app is loaded, first of all, i display a dialog box using CreateDialog (it's saying "initializing..."). then i explicitly set the focus on that dialog! after initialization, i hide the dialog and then use it (the window handle) as parent for all the other dialogs i create.
this works, but should not be considered to be the way to do it...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.