Subclass a Checkbox

Posted on 2006-04-23
Last Modified: 2008-03-03
I want to disable using the mouse to check a checkbox.

I ran across this:

      // Call the check box window procedure first
      lRet = CallWindowProc(lpCheckProc, hWnd, wMessage, wParam,

      // 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?


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. :)
Question by:edvinson
    LVL 8

    Expert Comment

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

    Author Comment

    Ok good start! Could you show me an example of 'doing nothing' with it? I am fairly new.
    LVL 8

    Accepted Solution

      return 0;        // means that application processed message

    I hope this is enough.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now