zoukankan      html  css  js  c++  java
  • 在mfc中动态创建按钮 荣

    第一步:
    在Resource.h中,添加按钮ID:ID_BTN_TEMP = 1001
    第二步:
    在View类【CView的子类】中添加一个变量,判断按钮是否已经创建:
    bool m_bIsCreatButton;

    第三步:
    创建一个按钮数组:
    CBitmapButton *m_bitList[11]


    第四步:
    在View类【CView的子类】的构造函数中,初始化bIsCreatButton:
    m_bIsCreatButton = false;

    第五步:
    在View类【CView的子类】中添加函数创建按钮:
    CBitmapButton* CHisNavView::CreateButton(int nID, char* text,int left, int top, int right, int bottom)
    {
     CRect rect;
     GetClientRect(rect);
     CBitmapButton *pButton = new CBitmapButton();
     ASSERT_VALID(pButton); pButton->Create(TEXT(text),
      WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
      CRect(left, top, right, bottom),
      this, nID);
     return pButton;
    }

    其中,nID为按钮ID,text为按钮文本。 其他为按钮显示范围。

    第六步:
    在View类【CView的子类】的OnDraw方法中创建按钮:
    m_bitList[0] = CreateButton(ID_BTN_TEMP, "天志的按钮", 50, 50, 150, 80); 

    第六步:
    在View类【CView的子类】中声明函数:
    afx_msg void OnTest()

    第七步:
    在View类【CView的子类】的BEGIN_MESSAGE_MAP(CHisNavView, CView)添加:
    ON_BN_CLICKED(ID_BTN_TEMP, CHisNavView::OnTest)

    第八步:实现OnTest()函数
    void CHisNavView::OnTest()
    {
       MessageBox(TEXT("天志自己写着玩!"), NULL, MB_OK);
    }
  • 相关阅读:
    jquery常用操作@测试分享
    selenium 上传文件
    python 安装mysql驱动
    创建react项目
    入栈操作的合法性 【重复元素】
    git笔记
    python GUI实战项目——tkinter库的简单实例
    Excel更改单元格格式后无效
    Find the Difference
    Two Sum IV
  • 原文地址:https://www.cnblogs.com/admin11/p/1050178.html
Copyright © 2011-2022 走看看