方法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消失):