Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Jochen Arndt 25-Sep-12 2:45am    
You may call RedrawWindow() after SetFocus().
Daniele Rota Nodari 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?

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.
 
Share this answer
 
HWND SetFocus(HWND hWnd) function set the focus at window, and DRAWITEMSTRUCT struct has member variable for item state.
CSS
typedef struct tagDRAWITEMSTRUCT {
    UINT CtlType;
    UINT CtlID;
    UINT itemID;
    UINT itemAction;
    UINT itemState;
    HWND hwndItem;
    HDC hDC;
    RECT rcItem;
    ULONG_PTR itemData;
} DRAWITEMSTRUCT;


C++
void CMyControl::DrawItem(LPDRAWITEMSTRUCT lpDIS) 
{
	CDC* pDC = CDC::FromHandle(lpDIS->hDC);

	BOOL bIsFocus = (lpDIS->itemState & ODS_FOCUS);
...


DRAWITEMSTRUCT itemstate[^]
 
Share this answer
 
If you need to draw focus rect then you just have to google for drawfocusrect and open the first link
 
Share this answer
 
Comments
Member 2685505 26-Sep-12 3:34am    
Sorry my bad English.
I need, that a button has painted the "Focus Rect" itself.
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);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900