LinMinquan's Blog

Experience technology to change life

模态对话框生成后指定其在父窗口中的位置

1.首先,不管是模态对话框还是非模态对话框,生成的时候都得指定其父窗口,这个很重要:

CDialog1  dialog1(this);   dialog1.DoModal();

CDialog2  *pDialog2;

pDialog2 = new CDialog2;

pDialog2->Create(IDD_DIALOG2, this);

2.模态对话框的构造函数中可以拿到父类的rect

pParent->GetWindowRect(&rectParent);

然后在OnInitDialog()中设定位置

SetWindowPos( NULL, (rectParent.left+rectParent.right)/2 – 637/2, (rectParent.top+rectParent.bottom)/2 – 416/2, 636, 416, SWP_SHOWWINDOW);


Share