如何从复选框中检索数据? [英] How do I retrieve the data from a check box?

查看:103
本文介绍了如何从复选框中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经在VC ++中创建了一个复选框,但是我不确定如何从中检索信息.是否给它分配一个BOOL或CButton变量?

我尝试为其分配变量BOOL m_Check_Box,并添加了事件处理程序
DDX_Control(pDX, IDC_displaydepthline, m_Check_Box);
但我不确定如何在:
中检索值

Hi,

I have created a check box in VC++ but I''m not sure how to retrieve the information from it. Do I assign it a variable that is a BOOL OR CButton?

I have tried to assign it the variable BOOL m_Check_Box and I''ve added the event handler
DDX_Control(pDX, IDC_displaydepthline, m_Check_Box);
but I''m not sure how to retrieve the value in :

void CCleanViewDlg::OnBnClickeddisplaydepthline
{
     UpdateData();
     int l_ChkBox = (int)m_Check_Box;
     UpdateData(FALSE);
}


我收到错误消息:``DDX_Control'':无法将参数3从``BOOL''转换为``CWnd&''.

我也尝试过将m_Check_Box设为CButton并使用
检索值 int l_ChkBox = m_Check_Box.GetCheck();
但这只会导致一堆访问冲突读取位置0x00000000"错误.

任何帮助将不胜感激!
谢谢!


I get the error:''DDX_Control'' : cannot convert parameter 3 from ''BOOL'' to ''CWnd &''.

I''ve also tried making m_Check_Box a CButton and retrieving the value using
int l_ChkBox = m_Check_Box.GetCheck();
but that just sit out a bunch of "Access violation reading location 0x00000000" errors.

Any help would be greatly appreciated!
Thanks!

推荐答案

好吧,您将变量名拼错了.在事件处理程序中,您使用m_CheckBox,但是您尝试使用m_Check_Box来检索控件的轮廓.
Well, you misspelled the variable name for one thing. In the event handler, you use m_CheckBox, but you''re trying to retrieve the control''s staete using m_Check_Box.


您可以通过两种方式进行操作:

You can do it in two ways:


  1. 添加类型为CButton的成员变量,假设它名为m_btnCheck,然后在DoDataExchange中添加以下内容:

  1. Add a member variable of type CButton, let''s say it''s named m_btnCheck, then add in your DoDataExchange the following:
DDX_Control(pDC, IDC_displaydepthline, m_btnCheck);


最后在您的处理程序中:


And finally in your handler:

void CCleanViewDlg::OnBnClickeddisplaydepthline()
{
   BOOL bChecked = (m_btnCheck.GetCheck() == BST_CHECKED);
}


  • 添加类型为int的成员变量,假设它名为m_iCheck,然后在您的DoDataExchange中添加以下内容:


  • Add a member variable of type int, let''s say it''s named m_iCheck, then add in your DoDataExchange the following:

    DDX_Check(pDC, IDC_displaydepthline, m_iCheck);


    最后在您的处理程序中:


    And finally in your handler:

    void CCleanViewDlg::OnBnClickeddisplaydepthline()
    {
       UpdateData();
       BOOL bChecked = (m_iCheck == BST_CHECKED);
    }




  • 这篇关于如何从复选框中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆