The CWnd object receives this call after the window is created but before it becomes visible The CREATESTRUCT structure contains copies of the parameters used to create the window
??? 我在基于对话框的程序这样 int CAaDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialog::OnCreate(lpCreateStruct) == -1) return -1;
GetClientRect(rect2); return 0; }void CAaDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } GetClientRect(rect1); }rect1 与rect2的width与Height一样呀
通过检测this->GetSafeHwnd()==NULL 是否成立,可以进行判断是否建立了对象。在建立对象后,再通过GetClientRect()就可以得到正确的结果了
The CREATESTRUCT structure contains copies of the parameters used to create the window
我在基于对话框的程序这样
int CAaDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
GetClientRect(rect2);
return 0;
}void CAaDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
} GetClientRect(rect1);
}rect1 与rect2的width与Height一样呀