VC++控件之权限设置

来源:互联网 发布:mac qq截屏 编辑:程序博客网 时间:2024/05/29 15:30

一、新建工程


二、编辑资源

               编辑对话框


                设置列表框属性


三、添加变量、函数

        1、添加变量




          2、添加函数


四、添加代码(红色部分)

         1、添加初始化代码:

BOOL CCListBoxDlg::OnInitDialog()
{
CDialog::OnInitDialog();

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
   CString strAboutMenu;
   strAboutMenu.LoadString(IDS_ABOUTBOX);
   if (!strAboutMenu.IsEmpty())
   {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
   }
}

SetIcon(m_hIcon, TRUE);    // Set big icon
SetIcon(m_hIcon, FALSE);   // Set small icon

// TODO: Add extra initialization here
m_checklist.SetCheckStyle(BS_CHECKBOX);
m_checklist.AddString("添加");
m_checklist.AddString("修改");
m_checklist.AddString("搜索");
m_checklist.AddString("删除");
GetDlgItem(IDC_ADD_BUTTON1)->EnableWindow(FALSE);
GetDlgItem(IDC_DEL_BUTTON2)->EnableWindow(FALSE);
GetDlgItem(IDC_SCAN_BUTTON3)->EnableWindow(FALSE);
GetDlgItem(IDC_REPAIRE_BUTTON4)->EnableWindow(FALSE);

return TRUE; // return TRUE unless you set the focus to a control
}

           2、为新增函数添加代码

void CCListBoxDlg::OnDblclkList2()
{
// TODO: Add your control notification handler code here
int i=m_checklist.GetCurSel();
if(i<0)return;
if(m_checklist.GetCheck(i)<1)
m_checklist.SetCheck(i,1);
else
m_checklist.SetCheck(i,0);
}

void CCListBoxDlg::OnPowerButton5()
{
// TODO: Add your control notification handler code here
if(m_checklist.GetCheck(0))
   GetDlgItem(IDC_ADD_BUTTON1)->EnableWindow(TRUE);
else
   GetDlgItem(IDC_ADD_BUTTON1)->EnableWindow(FALSE);
if(m_checklist.GetCheck(1))
   GetDlgItem(IDC_DEL_BUTTON2)->EnableWindow(TRUE);
else
   GetDlgItem(IDC_DEL_BUTTON2)->EnableWindow(FALSE);
if(m_checklist.GetCheck(2))
   GetDlgItem(IDC_SCAN_BUTTON3)->EnableWindow(TRUE);
else
   GetDlgItem(IDC_SCAN_BUTTON3)->EnableWindow(FALSE);
if(m_checklist.GetCheck(3))
   GetDlgItem(IDC_REPAIRE_BUTTON4)->EnableWindow(TRUE);
else
   GetDlgItem(IDC_REPAIRE_BUTTON4)->EnableWindow(FALSE);

}

五、编译

六、运行


七、函数说明

       1、CCheckListBos::SetCheckStyle函数声明

          void SetCheckStyle(UINT nStyle)

             nStyle:确定列表框风格之参数

             功能:   设置列表框风格

       2、CCheckListBos::GetCheck函数声明

 

 

 

          void GetCheck(int nIndex)

             nIndex:列表项的索引

            功能:    判断单前列表框选项是否被选中。返回“0”表示没选中;返回“1”为选中;返回“2”则不确定。