本文主要是介绍MFC小白学习记录之对话框单击控件弹出button,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法1:
头文件中声明:
private:
CButton m_btn;
bool m_iscreate;
构造函数中初始化:
m_iscreate=false;
单击消息响应中:
if (m_iscreate==false)
{
m_btn.Create("Lyunjun",WS_CHILD | WS_VISIBLE |BS_DEFPUSHBUTTON,CRect
(0,0,60,40),this,123);
m_iscreate=true;
}
else
{
m_btn.DestroyWindow();
m_iscreate=false;
}
方法2(原理与上面相同,不过使用static变量方法):
static bool iscreate=false;
if (iscreate==false)
{
m_btn.Create("Lyunjun",WS_CHILD | WS_VISIBLE |BS_DEFPUSHBUTTON,CRect
(0,0,60,40),this,123);
iscreate=true;
}
else
{
m_btn.DestroyWindow();
iscreate=false;
}
方法3:
if (!m_btn.m_hWnd)
{
m_btn.Create("Lyunjun",WS_CHILD | WS_VISIBLE |BS_DEFPUSHBUTTON,CRect
(0,0,60,40),this,123);
}
else
{
m_btn.DestroyWindow();
}
实现下图(单击ADDER弹出Lyunjun button,再单击Lyunjun button消失):
这篇关于MFC小白学习记录之对话框单击控件弹出button的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!