CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2019
    Posts
    53

    [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...

  2. #2
    Join Date
    May 2019
    Posts
    53

    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);

  3. #3
    Join Date
    May 2019
    Posts
    53

    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...

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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.5)

  5. #5
    Join Date
    Jul 2019
    Posts
    1

    Re: [RESOLVED] SetFocusRect with CheckBox (no .rc file). How to?

    thanks

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: SetFocusRect with CheckBox (no .rc file). How to?

    Quote Originally Posted by Arianax View Post
    ...
    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
  •  





Click Here to Expand Forum to Full Width

Featured