Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hello All.
I need to set the focus by pressing "TAB" manually.
I have a problem when manually switching control focus using function SetFocus.
"Focus Rect" does't show.
If I use the default function then the "Focus Rect" is drawn.
 
What should be done to make the "Focus Rect" was painted?
Posted 23-Sep-12 21:08pm
Comments
Jochen Arndt at 25-Sep-12 2:45am
   
You may call RedrawWindow() after SetFocus().
Daniele Rota Nodari at 8-Oct-12 4:08am
   
Hi. Your question is not clear to me.
- You say that You need to set focus by pressing "TAB" manually: do you mean that the final user will simply hit the TAB key?
- You say that SetFocus does not work as expected, but the "default function" is working. What is this default function?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I know how to do this for the user control.
I want to draw "Focus rect" on any standard control(Button, ComboBox etc.) without reimplementing draw function.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

HWND SetFocus(HWND hWnd) function set the focus at window, and DRAWITEMSTRUCT struct has member variable for item state.
typedef struct tagDRAWITEMSTRUCT {
    UINT CtlType;
    UINT CtlID;
    UINT itemID;
    UINT itemAction;
    UINT itemState;
    HWND hwndItem;
    HDC hDC;
    RECT rcItem;
    ULONG_PTR itemData;
} DRAWITEMSTRUCT;
 
void CMyControl::DrawItem(LPDRAWITEMSTRUCT lpDIS) 
{
	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
 
	BOOL bIsFocus = (lpDIS->itemState & ODS_FOCUS);
...
 
DRAWITEMSTRUCT itemstate[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If you need to draw focus rect then you just have to google for drawfocusrect and open the first link
  Permalink  
Comments
Member 2685505 at 26-Sep-12 3:34am
   
Sorry my bad English.
I need, that a button has painted the "Focus Rect" itself.
armagedescu at 26-Sep-12 6:06am
   
Ok, sorry for my bad french, but there is a very useful site: google.com. All you can is to play with button messages, styles and states. You can either call WM_SETFOCUS by SendMessage/SendDlgItemMessage, or call SetFocus. If window handle or dialog item identifier is correct, then the button will draw the focus rect automatically. Any controls which draws focus rect will draw it. You can also call control specific messages, for acheive the same thing, like BN_SETFOCUS, EN_SETFOCUS, HCBT_SETFOCUS, LBN_SETFOCUS and so on. Also see, maybe your button is ownerdraw.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I did it.
All controls necessary to send the WM_UPDATEUISTATE message, before calling SetFocus function.
The focus frame will be displayed correctly.
 
Example:
::SendMessage(hWnd, WM_UPDATEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), NULL);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100