?
Solved

Subclass a Checkbox

Posted on 2006-04-23
3
Medium Priority
?
640 Views
Last Modified: 2008-03-03
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. :)
0
Comment
Question by:edvinson
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mrblue
ID: 16519471
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
 
LVL 1

Author Comment

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

Accepted Solution

by:
mrblue earned 1500 total points
ID: 16519890
case WM_LBUTTONDOWN:
  return 0;        // means that application processed message

I hope this is enough.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

864 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