SetFocus and WM_SETFOCUS

This is a discussion on SetFocus and WM_SETFOCUS within the Windows Programming forums, part of the Platform Specific Boards category; i am subclassing my button controls so on tab they SetFocus to the next button control. but there is a ...

  1. #1
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214

    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
    Good Help Source all round
    Good help for win programmers
    you will probably find something in here
    this thing also helps

    if you have never tried any of the above then maybe you should, they help alot

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    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
    Last edited by novacain; 10-21-2004 at 01:57 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    im using pure api not mfc
    Good Help Source all round
    Good help for win programmers
    you will probably find something in here
    this thing also helps

    if you have never tried any of the above then maybe you should, they help alot

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Who said anything about using MFC? Can you explain why my last comment isnt what you are looking for?

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21