edvinson
asked on
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. :)
I ran across this:
case WM_GETDLGCODE:
// Call the check box window procedure first
lRet = CallWindowProc(lpCheckProc
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. :)
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.
ASKER
Ok good start! Could you show me an example of 'doing nothing' with it? I am fairly new.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.