-
June 24th, 2019, 07:25 AM
#1
[RESOLVED] SetFocusRect with CheckBox (no .rc file). How to?
Can't seem to infer how to get a focusrect (dotted-line rectangle) around a WinAPI checkbox.
Have tried DrawFocusRect() and also SendMessage() using SET_FOCUS. Maybe I got some parameters wrong? Am still unsure as to what is the accurate HDC to provide to DrawFocusRect.
What code accomplishes this and where in the Window Proc list should it be placed?
How do I determine the correct HDC to provide as the first parameter in DrawFocusRect().
Do I need to use BeginPaint() and EndPaint() around DrawFocusRect()?
Where do I place DrawFocusRect() in Window Procedure to make it affect the checkbox?
If it isn't DrawFocusRect() or SendMessage (supplying WM_SETFOCUS and BST_FOCUS) then how do I get the checkbox to be framed by a dotted-line rectangle?
Appreciate your help, have tried loads of searching on the topic with no answer so far...
-
June 24th, 2019, 07:52 AM
#2
Re: SetFocusRect with CheckBox (no .rc file). How to?
Answering my own question here, heheh:
How do I determine the correct HDC to provide as the first parameter in DrawFocusRect().
Use GetDC(the Checkbox's HWND);
-
June 24th, 2019, 07:58 AM
#3
Re: SetFocusRect with CheckBox (no .rc file). How to?
Aaaaaand, it turns out the Checkbox automatically draws a focus rect when clicked on or when highlighted with tab.
I just had a background that made it impossible to see the focus rect...
For DrawFocusRect() the following parameters give an accurate HDC...
DrawFocusRect(GetDC(HWND), &rectStruct);
Guess I solved my own question...
-
June 24th, 2019, 10:47 AM
#4
Re: [RESOLVED] SetFocusRect with CheckBox (no .rc file). How to?
Guess I solved my own question...
Great!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.2)
-
July 31st, 2019, 07:27 AM
#5
Re: [RESOLVED] SetFocusRect with CheckBox (no .rc file). How to?
-
July 31st, 2019, 11:48 AM
#6
Re: SetFocusRect with CheckBox (no .rc file). How to?
 Originally Posted by Arianax
...
DrawFocusRect(GetDC(HWND), &rectStruct);
Guess I solved my own question...
You did, however, only partially.
According MSDN documentation after you called and used GetDC() you then must call ReleaseDC function
Victor Nijegorodov
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|