代码如下:在OnInitDialog()中我这样写的:
CRect rectParentDlg;
this->GetWindowRect(&rectParentDlg);
CRect rectFuck;
m_bfuck.GetWindowRect(&rectFuck);//m_bfuck为CButton 的一个变量
m_bfuck.MoveWindow(rectParentDlg.left,rectParentDlg.top,rectFuck.Width(),rectFuck.Height(),TRUE);我要将这个控件放到对话框的左上角去,可是运行之后m_bfuck控件却在对话框上不见了,真奇怪,我以前也是这样写的都不会,代码一样,却结果不对了,为什么呀,真他妈的难过!

解决方案 »

  1.   

    CRect clirect;
    CRect rec;
    CPoint btnpt;
    CPoint refpt;
    CPoint ctrlpt;
    CSize offset;
    GetClientRect(clirect);
    refpt = clirect.BottomRight();
    CButton*  button; button = (CButton*)GetDlgItem(IDC_CLOSE);
        if( button != NULL) {
    button->GetWindowRect( rec );
    ScreenToClient(rec);
    int len = rec.right - rec.left;
    rec.right = clirect.right - m_btn.x;
    rec.left = clirect.right - m_btn.x - len;
    button->MoveWindow(rec, TRUE);

      

  2.   

    你把你的控件移到非Client去,当然不存在了,
    GetWindowRect(&rectParentDlg);
    得到的是对话框的整个区域,应该用
    GetClientRect(clirect);
      

  3.   

    this->GetWindowRect(&rectParentDlg);
    换成:
    this->GetClientRect(&rectParentDlg);
      

  4.   

    我找到了。其实是因为我用了CenterWindow()
    就会这样,去掉就不会了,不过我觉得zhb1284(zhb1284) ( ) 信誉:100 
    说得对,应该用GetClientRect();
    谢谢!