Subclass a Checkbox

I want to disable using the mouse to check a checkbox.

I ran across this:

case WM_GETDLGCODE:
      // Call the check box window procedure first
      lRet = CallWindowProc(lpCheckProc, hWnd, wMessage, wParam,
                            lParam);

      // If lParam points to an MSG structure
      if (lParam)
      {
         lpmsg = (LPMSG)lParam;
         if (lpmsg->message == WM_CHAR)
         {
            if (lpmsg->wParam == 'x' || lpmsg->wParam == 'X')
            {
               // Select the check box when user presses "X"
               SendMessage(hWnd, BM_SETCHECK, TRUE, 0);
               lRet |= DLGC_WANTMESSAGE;
            }
            else if (lpmsg->wParam == 'o' || lpmsg->wParam == 'O')
            {
               // Clear the check box when user presses "O"
               SendMessage(hWnd, BM_SETCHECK, FALSE, 0);
               lRet |= DLGC_WANTMESSAGE;
            }
         }
      }
      return lRet;

which appears to be on the right track. But the mouse will still work I assume.

This is in a dialog, using win32. Can anyone help me get this to work?

Thanks!

Ps. Before anyone gets into usability issues, I am only tackling this to see if I *could*. Just studying, this won't be in production. :)
LVL 1
edvinsonAsked:
Who is Participating?
 
Dariusz DziaraProgrammerCommented:
case WM_LBUTTONDOWN:
  return 0;        // means that application processed message

I hope this is enough.

0
 
Dariusz DziaraProgrammerCommented:
I guess that checking, unchecking checkbox (by using mouse) is implemented by handling mouse messages like WM_LBUTTONDOWN so if you want to change it you should replace such handler by your own. For example do nothing in WM_LBUTTONDOWN for checkox.
0
 
edvinsonAuthor Commented:
Ok good start! Could you show me an example of 'doing nothing' with it? I am fairly new.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.