请 关于首次显示嵌套对话框时位置怎么确定~
请高手指点 关于首次显示嵌套对话框时位置如何确定~~~
在Dialog1中嵌套Dialog2时,在首次运行时要使Dialog2显示在Dialog1的指定位置,应该如何实现呢?
我在Dialog 1 的InitDialog中这样实现:
CRect RectDialog1,RectDialog2;
GetWindowRect(&RectDialog1);
Dialog2.GetWindowRect(&RectDialog2);
Dialog2.MoveWindow(RectDialog1.left,RectDialog1.top,RectDialog2.right-RectDialog1.left,RectDialog1.bottom-RectDialog1.top,SWP_NOMOVE );
Dialog2.ShowWindow(SW_SHOW);
为什么当我运行时Dialog2始终显示在Dialog1的中间,看起来有点像是将Dialog1的中心作为left和right
我应该如何实现呢?如果把这段代码放在OnSize中也会出错,因为当Dialog1创建时先运行OnSize再运行InitDialog,这样Dialog2.GetWindowRect(&RectDialog2);就会出错,请高手指点
------解决方案--------------------
MoveWindow使用父窗口的客户坐标,GetWindowRect得到的是屏幕坐标。
应该放在OnSize中,调用前判断一下窗口句柄的有效性:
if (IsWindow(Dialog2.GetSafeHwnd())
Dialog2.MoveWindow(0, 0, cx, cy);
------解决方案--------------------
你对MoveWindow最后一个参数的使用有错误。
------解决方案--------------------
Dialog2使用非模式对话框 不要用模式对话框, 然后设置成下层
在Dialog1中嵌套Dialog2时,在首次运行时要使Dialog2显示在Dialog1的指定位置,应该如何实现呢?
我在Dialog 1 的InitDialog中这样实现:
CRect RectDialog1,RectDialog2;
GetWindowRect(&RectDialog1);
Dialog2.GetWindowRect(&RectDialog2);
Dialog2.MoveWindow(RectDialog1.left,RectDialog1.top,RectDialog2.right-RectDialog1.left,RectDialog1.bottom-RectDialog1.top,SWP_NOMOVE );
Dialog2.ShowWindow(SW_SHOW);
为什么当我运行时Dialog2始终显示在Dialog1的中间,看起来有点像是将Dialog1的中心作为left和right
我应该如何实现呢?如果把这段代码放在OnSize中也会出错,因为当Dialog1创建时先运行OnSize再运行InitDialog,这样Dialog2.GetWindowRect(&RectDialog2);就会出错,请高手指点
------解决方案--------------------
MoveWindow使用父窗口的客户坐标,GetWindowRect得到的是屏幕坐标。
应该放在OnSize中,调用前判断一下窗口句柄的有效性:
if (IsWindow(Dialog2.GetSafeHwnd())
Dialog2.MoveWindow(0, 0, cx, cy);
------解决方案--------------------
你对MoveWindow最后一个参数的使用有错误。
------解决方案--------------------
Dialog2使用非模式对话框 不要用模式对话框, 然后设置成下层