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
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
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.
: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.
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.
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.
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.
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.
"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.
Just as a side note:
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 :
This is an especially important distinction when dealing with WM_NOTIFY or return critical messages.
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.
"The dialog box procedure should return the value directly. The DWL_MSGRESULT value set by the SetWindowLong function is ignored. "
From the MSDN.
From the MSDN.
"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.
A dialog box ignores DWL_MSGRESULT from about a dozen messages. Most of them are the color control messages.