PDA

Click to See Complete Forum and Search --> : SetFocus problems..


softwareguy74
Jan 6th, 2001, 10:56 AM
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

softwareguy74
Jan 6th, 2001, 11:02 AM
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

parksie
Jan 6th, 2001, 11:14 AM
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:

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:

TRUE The window is being shown
FALSE The window is being hidden