-
SetFocus and WM_SETFOCUS
i am subclassing my button controls so on tab they SetFocus to the next button control.
but there is a slight problem with how i am doing it.which is like this
Code:
LRESULT APIENTRY ButtonHost(HWND hwnd , UINT message , WPARAM wParam , LPARAM lParam)
{
switch(message)
{
case WM_CHAR:
if(wParam == VK_TAB)
{
SetFocus(hwndButtonOptionsH);
}
if(wParam != VK_TAB)
{
return CallWindowProc(wpButtonHost , hwnd , message , wParam , lParam);
}break;
case WM_SETFOCUS:
SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON);
return 0;
case WM_KILLFOCUS:
SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON);
ShowWindow(hwnd, SW_HIDE);
ShowWindow(hwnd, SW_SHOW);
return 0;
default:
return CallWindowProc(wpButtonHost , hwnd , message , wParam , lParam);
}
return 0;
}
now the problem is it is setting the focus to the other button control but it seems like it is not receiving the WM_SETFOCUS message because all the button controls have the effect of taking out the seletection rect and making it defpushbutton instead.
i have tried using sendmessage and WM_SETFOCUS but that seems to not be working right.
does any one know away around this as to where my buttons that is getting selected with SetFocus uses the effect they get when they get WM_SETFOCUS,
thanks
-
Why are you subclassing controls to do something that is built into dialogs by default.
In your WM_INITDIALOG handler, set the focus to a control and then return FALSE. The tab order will be defined by the control's order in the .rc file.
-
try
SetWindowPos( GetParent( hwnd ), HWND_TOPMOST, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE );
after you have set the new button style with SetWindowLong()
AFAIK some of the styles can only be used when the window/control is created.
Try testing the return from GetWindowLong() with GetLastError() if it fails.
Have you looked at WS_TABSTOP style?
Try
SetFocus( GetDlgItem( GetParent( hwnd ), ID_NEXTBUTTON ) ); //ensure the right HWND is used
-
im using pure api not mfc
-
Who said anything about using MFC? Can you explain why my last comment isnt what you are looking for?
-
If you are not using a dialog resource and are using CreateWindow/CreateWindowEx to create your controls then, as Novacain has suggested, give your controls the WS_TABSTOP window style and use IsDialogMessage in your message loop (use this, too, if using a modeless dialog) to get default dialog keyboard processing (such as control tabbing) as described by bithub. If your objective is simply 'control tabbing' then you should prefer the default, dialog behaviour over your own home-cooked stuff, as bithub has stated.
If you need to override this default behaviour for some reason or other then perhaps WM_GETDLGCODE may be of some interest. You may also want to take a look at WM_NEXTDLGCTL (but note that you should use PostMessage and not SendMessage if you need to send this message).