简体   繁体   English

C ++ Checkbox的作用就像单选按钮WINAPI(No MFC)

[英]C++ Checkbox's acting like radio buttons WINAPI ( No MFC )

I am trying to get 2 checkboxs in my application to act like radio buttons. 我试图在我的应用程序中获得2个复选框,就像单选按钮一样。 IE - When one is ticked the other button will untick itself. IE - 当勾选一个时,另一个按钮将自动解开。 I dont believe that this can be achieved through the properties menu so I am trying to do it in code. 我不相信这可以通过属性菜单实现,所以我试图在代码中做到这一点。

I dont know much about how to do this at all so I am getting a bit lost. 我根本不知道如何做到这一点,所以我有点失落。 This is what I have so far (which Is not working) 这是我到目前为止(这是不工作)

    case BN_CLICKED:
    if(BN_CLICKED == IDC_CHECK_MW){
        SendMessage(GetDlgItem(hDlg,IDC_CHECK_MW), BM_GETCHECK, (WPARAM)0 ,(LPARAM)0) == BST_CHECKED;
    }

I may be way oof but any help would be great! 我可能会这样,但任何帮助都会很棒!

If you have the handles or something handy, just send a BM_SETCHECK : 如果您有方便的手柄或东西,只需发送一个BM_SETCHECK

int checkState = SendMessage (otherHwnd, BM_GETCHECK, 0, 0);
SendMessage (otherHwnd, BM_SETCHECK, checkState == BST_CHECKED ? BST_UNCHECKED : BST_CHECKED, 0);

This of course assumes that it can only be checked or unchecked, not in an intermediate state. 这当然假定它只能被检查或取消检查,而不是处于中间状态。 I would also really reconsider your thinking, as checkboxes are meant to act as such, and radio buttons are the right tools for this behaviour. 我也会真的重新考虑你的想法,因为复选框就是这样做的,而单选按钮是这种行为的正确工具。

Also, in your message switch, you want this probably: 此外,在您的消息切换中,您可能希望这样:

case WM_COMMAND:
{
    if (HIWORD (wParam) == BN_CLICKED)
    {
        switch (LOWORD (wParam))
        {
            case IDC_CHECK_MW:
                //check this, uncheck that
                break;

            case IDC_OTHER_CHECK:
                //check other, uncheck first
                break;

            default:
                //something went wrong
        }
    }    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM