在onCreate()跟在onDraw()得到的GetClientRect结果不同,宽跟高都相差16
这是为什么?
在运行中没有改变任何的形状大小的代码。

解决方案 »

  1.   

    在onCreate()中,对象有可能还没有建立。
    通过检测this->GetSafeHwnd()==NULL 是否成立,可以进行判断是否建立了对象。在建立对象后,再通过GetClientRect()就可以得到正确的结果了
      

  2.   

    OnCreate后对象已经建立了,窗口已经拥有句柄,但此时的客户区大小确实会与OnDraw中不同
      

  3.   

    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
      

  4.   

    ???
    我在基于对话框的程序这样
    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一样呀