MFC单文档按钮两两组合按下后不同功能的实现。有若干按钮,按下按钮1和按钮2实现功能一,按下按钮1和按钮3实现功能二,按下按钮1和按钮3实现功能三,按下按钮2和3实现功能四。同时先按下按钮1后按下按钮2和先按下按钮2后按下按钮1实现的功能也不同。*麻烦代码详细一些,初学者理解力较差。
1条回答 默认 最新
- threenewbee 2019-06-01 10:16关注
给你完整写了一个,采纳本回答留下email发给你
其他人如果也需要,可以从 https://download.csdn.net/download/caozhy/11220774 下载。
这个不要用按钮,而是应该用CheckBox控件实现。
// Q764102View.cpp : implementation of the CQ764102View class // #include "pch.h" #include "framework.h" // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail // and search filter handlers and allows sharing of document code with that project. #ifndef SHARED_HANDLERS #include "Q764102.h" #endif #include "Q764102Doc.h" #include "Q764102View.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CQ764102View IMPLEMENT_DYNCREATE(CQ764102View, CFormView) BEGIN_MESSAGE_MAP(CQ764102View, CFormView) // Standard printing commands ON_COMMAND(ID_FILE_PRINT, &CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, &CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CQ764102View::OnFilePrintPreview) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_BN_CLICKED(IDC_CHECK1, &CQ764102View::OnClickedCheck1) ON_BN_CLICKED(IDC_CHECK2, &CQ764102View::OnClickedCheck2) ON_BN_CLICKED(IDC_CHECK3, &CQ764102View::OnClickedCheck3) ON_BN_CLICKED(IDC_CHECK4, &CQ764102View::OnClickedCheck4) END_MESSAGE_MAP() // CQ764102View construction/destruction CQ764102View::CQ764102View() noexcept : CFormView(IDD_Q764102_FORM) { // TODO: add construction code here } CQ764102View::~CQ764102View() { } void CQ764102View::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); } BOOL CQ764102View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } void CQ764102View::OnInitialUpdate() { CFormView::OnInitialUpdate(); GetParentFrame()->RecalcLayout(); ResizeParentToFit(); } // CQ764102View printing void CQ764102View::OnFilePrintPreview() { #ifndef SHARED_HANDLERS AFXPrintPreview(this); #endif } BOOL CQ764102View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CQ764102View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CQ764102View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CQ764102View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) { // TODO: add customized printing code here } void CQ764102View::OnRButtonUp(UINT /* nFlags */, CPoint point) { ClientToScreen(&point); OnContextMenu(this, point); } void CQ764102View::OnContextMenu(CWnd* /* pWnd */, CPoint point) { #ifndef SHARED_HANDLERS theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE); #endif } // CQ764102View diagnostics #ifdef _DEBUG void CQ764102View::AssertValid() const { CFormView::AssertValid(); } void CQ764102View::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CQ764102Doc* CQ764102View::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQ764102Doc))); return (CQ764102Doc*)m_pDocument; } #endif //_DEBUG // CQ764102View message handlers void CQ764102View::DoFunc() { CButton* btn1 = (CButton*)GetDlgItem(IDC_CHECK1); int i1 = btn1->GetCheck(); CButton* btn2 = (CButton*)GetDlgItem(IDC_CHECK2); int i2 = btn2->GetCheck(); CButton* btn3 = (CButton*)GetDlgItem(IDC_CHECK3); int i3 = btn3->GetCheck(); CButton* btn4 = (CButton*)GetDlgItem(IDC_CHECK4); int i4 = btn4->GetCheck(); if (i1 + i2 + i3 + i4 == 2) { btn1->SetCheck(0); btn2->SetCheck(0); btn3->SetCheck(0); btn4->SetCheck(0); if (i1 + i2 == 2) { MessageBox(_T("功能1")); } else if (i1 + i3 == 2) { MessageBox(_T("功能2")); } else if (i1 + i4 == 2) { MessageBox(_T("功能3")); } else if (i2 + i3 == 2) { MessageBox(_T("功能4")); } else { MessageBox(_T("无此功能")); } } } void CQ764102View::OnClickedCheck1() { // TODO: Add your control notification handler code here DoFunc(); } void CQ764102View::OnClickedCheck2() { // TODO: Add your control notification handler code here DoFunc(); } void CQ764102View::OnClickedCheck3() { // TODO: Add your control notification handler code here DoFunc(); } void CQ764102View::OnClickedCheck4() { // TODO: Add your control notification handler code here DoFunc(); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
- ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
- ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
- ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?