aboutdlg - yamaumima/hello.github.io GitHub Wiki
// AboutDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test.h"
#include "AboutDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog
CAboutDlg::CAboutDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAboutDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAboutDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg message handlers
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}
void CAboutDlg::OnOK()
{
CWnd* pMainWnd = AfxGetMainWnd();
// 创建一个按钮
CButton* pButton = new CButton();
pButton->Create(_T("按钮文本"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(10, 10, 100, 30), this, 1);
// 设置按钮的位置和大小
CRect rect;
pMainWnd->GetClientRect(&rect);
int buttonWidth = 80;
int buttonHeight = 30;
int buttonTop = rect.Height() / 2 - buttonHeight / 2;
int buttonLeft = rect.Width() / 2 - buttonWidth / 2;
pButton->MoveWindow(buttonLeft, buttonTop, buttonWidth, buttonHeight);
// 显示按钮
pButton->ShowWindow(SW_SHOW);
pButton->UpdateWindow();
// EndDialog(IDOK);
// 获取父窗口的句柄
HWND hWndParent = pMainWnd->GetSafeHwnd();
// 创建一个按钮
HWND hWndButton = CreateWindow(
_T("BUTTON"), // 类名
_T("按钮文本"), // 按钮文本
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // 窗口样式
10, 10, 100, 30, // 按钮位置和大小
hWndParent, // 父窗口句柄
(HMENU)1, // 按钮ID
NULL, // 实例句柄
NULL // 附加参数
);
::InvalidateRect(hWndParent, NULL, TRUE);
::UpdateWindow(hWndParent);
// EndDialog(IDOK);
pMainWnd->ShowWindow(SW_HIDE);
}
void CAboutDlg::OnCancel()
{
//CWnd* pMainWnd = AfxGetMainWnd();
// m_nFlags = 0;
DestroyWindow();//EndDialog(-1)
// EndDialog(IDCANCEL);
}