参考:
工作中遇到对话框中动态添加和删除(隐藏、显示)按钮问题
#define IDC_GROUPBOX1 1001
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnInitDialog();
afx_msg void DelButton();
CButton *m_pGroupBox1;
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
BOOL CAboutDlg::OnInitDialog()
{
/* if( m_pGroupBox1 != NULL )
{
delete m_pGroupBox1;
m_pGroupBox1 = NULL;
}
*/ m_pGroupBox1 = new CButton;
m_pGroupBox1->Create( _T( "Test" ), BS_PUSHBUTTON | BS_CENTER | WS_VISIBLE, CRect( CPoint( 50, 50 ), CSize( 100, 30 ) ), this, IDC_GROUPBOX1 );
m_pGroupBox1->ShowWindow(SW_SHOW);
/* m_pGroupBox1->DestroyWindow();
delete m_pGroupBox1;
m_pGroupBox1 = NULL;
*/
return TRUE;
}
void CAboutDlg::DelButton()
{
HWND hWnd = GetSafeHwnd();
if( m_pGroupBox1 != NULL )
{
m_pGroupBox1->DestroyWindow();
delete m_pGroupBox1;
m_pGroupBox1 = NULL;
}
//CButton *pBtn = GetDlgItem(IDOK, &hWnd);
GetDlgItem(IDOK)->ShowWindow(HIDE_WINDOW); //Hide "OK" Button
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
ON_WM_SYSCOMMAND()
//}}AFX_MSG_MAP
ON_COMMAND(IDC_GROUPBOX1, DelButton)
END_MESSAGE_MAP()
*****更改默认菜单名称
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
//pSysMenu->DeleteMenu(SC_MAXIMIZE,MF_BYCOMMAND);
//pSysMenu->DeleteMenu(SC_SIZE,MF_BYCOMMAND);
// end added
CString strAboutMenu("Hello World");
if (!strAboutMenu.IsEmpty())
{
pSysMenu->InsertMenu(SC_CLOSE, MF_BYCOMMAND, IDM_ABOUTBOX, strAboutMenu);
pSysMenu->InsertMenu(SC_CLOSE, MF_BYCOMMAND | MF_SEPARATOR);
}
******新增菜单
CMenu menu;
if (menu.LoadMenu(uMainMenuID))
{
CMenu* p_menu = menu.GetSubMenu(1);
if (p_menu)
{
CString str = _T("Change Skin...");
//p_menu->GetMenuString(ID_CHANGE_SKIN, str, MF_BYCOMMAND);
pSysMenu->AppendMenu(MF_STRING, ID_CHANGE_SKIN, str);
}
}
}
*****删除菜单
CMenu* pMainMenu= GetMenuBar()->GetMenu();
if(pMainMenu)
{
CMenu* pChildMenu = pMainMenu->GetSubMenu(3);
if(pChildMenu)
pChildMenu->DeleteMenu(ID_HELP_ABOUT,MF_BYCOMMAND);
}
阅读(3481) | 评论(1) | 转发(0) |