CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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!
    reboot, and everything is good

    visit my website at hochleistung.at

  2. #2
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: cannot edit edit-box after setfocus (non-MFC)

    Use WS_TABSTOP flag with your editbox control.
    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.

  3. #3
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    Re: cannot edit edit-box after setfocus (non-MFC)

    Quote Originally Posted by amarcode
    Use WS_TABSTOP flag with your editbox control.
    i did...
    reboot, and everything is good

    visit my website at hochleistung.at

  4. #4
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    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;
    }
    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.

  5. #5
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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.
    reboot, and everything is good

    visit my website at hochleistung.at

  6. #6
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    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.

    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.

  7. #7
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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;
    }
    reboot, and everything is good

    visit my website at hochleistung.at

  8. #8
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    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?
    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.

  9. #9
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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?
    reboot, and everything is good

    visit my website at hochleistung.at

  10. #10
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    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).
    Attached Files Attached Files
    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.

  11. #11
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    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.
    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.

  12. #12
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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.
    reboot, and everything is good

    visit my website at hochleistung.at

  13. #13
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: cannot edit edit-box after setfocus (non-MFC)

    [ Moved thread ]

  14. #14
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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!
    reboot, and everything is good

    visit my website at hochleistung.at

  15. #15
    Join Date
    Jan 2004
    Location
    Upper Austria
    Posts
    215

    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...
    reboot, and everything is good

    visit my website at hochleistung.at

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured