Checkbox: SetFocus() doesn't draw broken rectangle around it
-
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!
-
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!
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.