Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Checkbox: SetFocus() doesn't draw broken rectangle around it

Checkbox: SetFocus() doesn't draw broken rectangle around it

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Donguy1976
    wrote on last edited by
    #1

    I am working on a legacy Windows app written in Win32. There's a checkbox in the screen and i call the SetFocus() function to have the focus on it. I know that it works as far as setting the focus, because now i can use space button in keyboard to check and uncheck the checkbox. But the problem is, when a control get's the focus, it's supposed show a broken rectangle around it. In my case this broken rectangle is not drawn/shown all the time. Sometimes it shows the broken rectangle and some times it doesn't. I need to show some visual indication to user that this checkbox has the focus. I tried using WM_CTLCOLORSTATIC, but that creates some painting issues in the window. So am looking for a simpler solution, by which i could show some visual indicator to user that this checkbox is having focus. Like changing the text color or background color or even force draw a broken rectangle. But i have no idea how to do this without using the WM_CTLCOLORSTATIC. Is there a easier way to show some sort of visual indication on a checkbox in Win32? Thanks in advance!

    A 1 Reply Last reply
    0
    • D Donguy1976

      I am working on a legacy Windows app written in Win32. There's a checkbox in the screen and i call the SetFocus() function to have the focus on it. I know that it works as far as setting the focus, because now i can use space button in keyboard to check and uncheck the checkbox. But the problem is, when a control get's the focus, it's supposed show a broken rectangle around it. In my case this broken rectangle is not drawn/shown all the time. Sometimes it shows the broken rectangle and some times it doesn't. I need to show some visual indication to user that this checkbox has the focus. I tried using WM_CTLCOLORSTATIC, but that creates some painting issues in the window. So am looking for a simpler solution, by which i could show some visual indicator to user that this checkbox is having focus. Like changing the text color or background color or even force draw a broken rectangle. But i have no idea how to do this without using the WM_CTLCOLORSTATIC. Is there a easier way to show some sort of visual indication on a checkbox in Win32? Thanks in advance!

      A Offline
      A Offline
      Arthur V Ratz
      wrote on last edited by
      #2

      I don't know exactly, but it seems to me that you should never call SetFocus() method. Instead, we have to post WM_SETFOCUS message to the checkbox control as follows:

      HWND hCheckBoxWnd = NULL;
      if ((hCheckBoxWnd = ::GetDlgItem(hDlg,IDC_YOUR_CHECK_BOX_ID)))
      ::PostMessage(hCheckBoxWnd, WM_SETFOCUS, 0, 0);

      Actually, you should not send the message using SendMessage(...) Win32API function, all you have to do is to post the message using PostMessage(...) instead.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups