Results 1 to 3 of 3

Thread: SetFocus problems..

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I'm trying to set the focus to an edit control when a dialog box is initizlied:

    hWnd = SetFocus(GetDlgItem(hDlg,IDC_EDIT1));

    But it's not happening.. No errors, but the focus is not getting set on IDC_EDIT1.

    Any ideas what I'm doing wrong?

    thanks,

    dan

    Visual Studio 2010

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    I just tried another approach to the set focus and it worked.. I put a button on the dialog box to set the focus. So why does that work and my first example doesn't?

    I wonder if it has something to do with the fact that I'm trying to set the focus as the dialog is being initilized and maybe there is not yet a handle assigned to IDC_EDIT1?

    My first example I put it under:

    case WM_INITDIALOG:

    Is that the wrong place? I want to set the focus when the dialog is shown...

    Any help would be appreciated..

    Dan

    Visual Studio 2010

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    When WM_INITDIALOG is sent, the dialogue has not yet been shown - it's only been initialised. So, to change it when the dialogue is shown, use WM_SHOWWINDOW.

    Incidentally, that message is sent when the window is shown or hidden, so keep an eye on the parameters:

    lParam:
    Code:
    SW_OTHERUNZOOM   The window is being uncovered because a maximize window was restored or minimized. 
    SW_OTHERZOOM     The window is being covered by another window that has been maximized. 
    SW_PARENTCLOSING The window's owner window is being minimized. 
    SW_PARENTOPENING The window's owner window is being restored.
    wParam:
    Code:
    TRUE The window is being shown
    FALSE The window is being hidden
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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