cannot edit edit-box after setfocus (non-MFC)
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...
all help will be appreciated!
Re: cannot edit edit-box after setfocus (non-MFC)
Use WS_TABSTOP flag with your editbox control.
Re: cannot edit edit-box after setfocus (non-MFC)
Quote:
Originally Posted by amarcode
Use WS_TABSTOP flag with your editbox control.
i did...
Re: cannot edit edit-box after setfocus (non-MFC)
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 :
Code:
::DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), m_hWnd, DialogProc, IDC_EDIT);
BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
::SetFocus(::GetDlgItem(hwndDlg,lParam));
break;
default:
break;
}
return 0;
}
Re: cannot edit edit-box after setfocus (non-MFC)
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.
Re: cannot edit edit-box after setfocus (non-MFC)
Quote:
Originally Posted by reset-leo
well, i'm not sure if this will help.
It works well for me.
Quote:
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?
Re: cannot edit edit-box after setfocus (non-MFC)
here is the code:
Code:
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;
}
Re: cannot edit edit-box after setfocus (non-MFC)
Quote:
Originally Posted by reset-leo
here is the code:
Is this code working well now?
Re: cannot edit edit-box after setfocus (non-MFC)
Quote:
Originally Posted by amarcode
Is this code working well now?
no it is not. i suppose you did not find any errors in my code, right? i didn't either! ;)
is there anything else you could imagine to be wrong?
1 Attachment(s)
Re: cannot edit edit-box after setfocus (non-MFC)
The attached is a working example. Try to set the editbox as a first control on the dialog (Layout->Tab Order).
Re: cannot edit edit-box after setfocus (non-MFC)
"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.
Re: cannot edit edit-box after setfocus (non-MFC)
Quote:
Originally Posted by amarcode
"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.
Re: cannot edit edit-box after setfocus (non-MFC)
Re: cannot edit edit-box after setfocus (non-MFC)
now i know what's happening!
the focus is set to the edit box correctly, but the dialog itself doesn't have the focus! i'm annoyed i didn't find that out sooner...
BTW: it doesn't work yet, i still have to solve this. thanx for the help so far!
Re: cannot edit edit-box after setfocus (non-MFC)
i soved it!!!!
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...