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);
    }
  • 相关阅读:
    tableView的高度问题
    信任机型
    cell 内部 设置width 总不对
    图文混排
    UICollectionview实现自定义cell的移动删除
    ios 各种技术
    打包ane之后在FB上生成ipa的阶段错误
    自动布局出代码植入 的图像化实例
    MapReduce编程实例
    二叉树的遍历(递归遍历、非递归遍历、层序遍历)
  • 原文地址:https://www.cnblogs.com/admin11/p/1050178.html
Copyright © 2011-2022 走看看