Hi,

For 2 day's now i'm trying to get SetFocus to work, without any success. I'm trying to set the keyboard focus to the second editbox.

Can someone look at the code and point me in the right direction?

Tia,
Slash0r
Posted on 2003-12-11 03:09:20 by Slash0r
You must return false or Windows will SetFocus to the handle in wParam.

:alright:

.IF(uMsg == WM_INITDIALOG)
invoke GetWindowRect, hDlg, ADDR rect
invoke SetWindowPos, hDlg, HWND_TOPMOST, rect.left, rect.top,

rect.right, rect.bottom, SWP_SHOWWINDOW

invoke GetDlgItem, hDlg, IDC_EDIT_2
invoke SetFocus, eax
mov eax, FALSE
ret

Regards,
Mariano.
Posted on 2003-12-11 03:42:40 by Eternal Idol Birmingham
When you receive WM_INTDIALOG message the wParam contains a control handle to which windows will set focus if you return from your dialogbox procedure TRUE. So you should return FALSE if you want to alter keyboard focus, of just set the second edit control to be first in resource file, then windows will assign the default keyboard focus to it.
Posted on 2003-12-11 03:51:37 by Vaxon
I already said that and pointed in his code what to change.

Here's the MSDN info.
Posted on 2003-12-11 03:53:44 by Eternal Idol Birmingham
Thx Mariano,

It's working now!

BUT what i don't understand is that WM_INITDIALOG has to return TRUE so Windows knows that that message is handled. I return FALSE after SetFocus so windows thinks the WM_INITDIALOG message is not processed?????

Oh well it's working...

EDIT: Hmm..i was a bit slow...Mariano already gave the MSDN info.
Posted on 2003-12-11 03:58:25 by Slash0r
From MSDN :
"The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control specified by wParam. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus. "

If you return TRUE (in the eax register), the system will do a SetFocus itself on wParam, if you return FALSE it will not.

:alright:

Regards,
Mariano.
Posted on 2003-12-11 04:01:12 by Eternal Idol Birmingham
Just as a side note:
 mov eax, FALSE

ret

Is not how you return FALSE in a dialog callback. That will only gaurantee that you return FALSE to the dialog procedure. To return FALSE to Windows you use SetWindowLong :
invoke SetWindowLong,hWin,DWL_MSGRESULT,FALSE

This is an especially important distinction when dealing with WM_NOTIFY or return critical messages.
Posted on 2003-12-11 07:01:22 by donkey
"The dialog box procedure should return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored. "

From the MSDN.
Posted on 2003-12-11 08:53:42 by Eternal Idol Birmingham

"The dialog box procedure should return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored. "

From the MSDN.


I realize that, I was going to make the distinction between WM_INITDIALOG and other messages but I figured it was pretty clear on that message. For WM_NOTIFY it is very important to use DWL_MSGRESULT. That's why I said it was a side note. For WM_INITDIALOG you return to the dialog procedure, not Windows, I did make it clear that there is a distinction between how to return values to the two.
Posted on 2003-12-11 08:55:42 by donkey
A dialog box ignores DWL_MSGRESULT from about a dozen messages. Most of them are the color control messages.
Posted on 2003-12-11 15:55:46 by tenkey