Dual monitor, pop up window goes to primary display
-
Hi, I have one application, which should use pop up window. If I configer the system as dual monitor, drag the application to the secondary display, then click the button to pop up the window, the window will go to the primary display. In the source code, the pop up window is created by: wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, NULL, 0, NULL); I tried to change it to wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, parent, 0, NULL); Changed the last third parameter from NULL to parent, which is the main application window. But the pop up window is still go to the primary display. How can I figure it out? Thanks in advance!
-
Hi, I have one application, which should use pop up window. If I configer the system as dual monitor, drag the application to the secondary display, then click the button to pop up the window, the window will go to the primary display. In the source code, the pop up window is created by: wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, NULL, 0, NULL); I tried to change it to wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, parent, 0, NULL); Changed the last third parameter from NULL to parent, which is the main application window. But the pop up window is still go to the primary display. How can I figure it out? Thanks in advance!
I am not sure what the problem is?? But to solve your problem you can get parent window rect and set the child window position accordingly using 1.SetWindowPos 2.MoveWindow You can also try calling CenterWindow(GetParent()) from child window. I hope it helps..
Regards, Sandip.
-
I am not sure what the problem is?? But to solve your problem you can get parent window rect and set the child window position accordingly using 1.SetWindowPos 2.MoveWindow You can also try calling CenterWindow(GetParent()) from child window. I hope it helps..
Regards, Sandip.
Hi Sandip, Thank you very much for your tip. I will try the ways as you said. Here I would like to clarify my question again: actually I found many applications have this problem same as mein. For example, Outlook, if you configure your system as dual monitor, start Outlook, drag the outlook to the secondary display, then click compose new email. You will see the new email composing window pops to the primary display. But an opposite example is Visual Studio. If you do the same thing for Visual studio, click open file button, the new dialog sticks same with the main visual studio window.
-
I am not sure what the problem is?? But to solve your problem you can get parent window rect and set the child window position accordingly using 1.SetWindowPos 2.MoveWindow You can also try calling CenterWindow(GetParent()) from child window. I hope it helps..
Regards, Sandip.
Hi Sandip, I tried CenterWindow(GetParent()). But it doesn't work. The pop up window is still in the primary display, while the main application window is in the secondary display. I do it in this way: wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, parent, 0, NULL); wnd->CenterWindow(parent->GetParent()); Does it mean the "parent" is not the real main window? or CenterWindow() doesn't work? Actually the position of the pop up window is same as before. Best,
-
Hi Sandip, I tried CenterWindow(GetParent()). But it doesn't work. The pop up window is still in the primary display, while the main application window is in the secondary display. I do it in this way: wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, parent, 0, NULL); wnd->CenterWindow(parent->GetParent()); Does it mean the "parent" is not the real main window? or CenterWindow() doesn't work? Actually the position of the pop up window is same as before. Best,
'Dual view' is complicated stuff, and this is how it works. If anything can be done to avoid this behavior then that can be done in 'Display Driver', as far as I know.
Cheers, Vishal
-
Hi Sandip, I tried CenterWindow(GetParent()). But it doesn't work. The pop up window is still in the primary display, while the main application window is in the secondary display. I do it in this way: wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, parent, 0, NULL); wnd->CenterWindow(parent->GetParent()); Does it mean the "parent" is not the real main window? or CenterWindow() doesn't work? Actually the position of the pop up window is same as before. Best,
-
logiqworks wrote:
wnd->CenterWindow(parent->GetParent());
Here you should pass i think only parent. BTW what is parent?? is it main window or just another child of main window?? I hope it helps..
Regards, Sandip.
Do you mean to pass only parent like this: wnd->CenterWindow(parent); The parent is one child of main window. Because it is complicated to get the main window, so I just use one child window.
-
'Dual view' is complicated stuff, and this is how it works. If anything can be done to avoid this behavior then that can be done in 'Display Driver', as far as I know.
Cheers, Vishal
Hi Vishal, Could you please give me a hint how to do in "Display Driver"? I never use it. But I would like to try.
-
Do you mean to pass only parent like this: wnd->CenterWindow(parent); The parent is one child of main window. Because it is complicated to get the main window, so I just use one child window.
-
logiqworks wrote:
Do you mean to pass only parent like this: wnd->CenterWindow(parent);
Yes, But does window pointed by parent come in primary display or it comes properly. You can get the handle to main window using AfxGetMainWnd();
Regards, Sandip.
Hi Sandip, The situation is that the parent window is initially generated in primary display. I drag it to the secondary display. Then do some operations and pop up some windows. And the pop up window will go back the primary display. I tried wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, AfxGetMainWnd(), 0, NULL); wnd->CenterWindow(AfxGetMainWnd()); as you said. But the pop up window is still in the primary display. And it doesn't locate in the center of the window.
-
Hi Sandip, The situation is that the parent window is initially generated in primary display. I drag it to the secondary display. Then do some operations and pop up some windows. And the pop up window will go back the primary display. I tried wnd->CreateEx(menuAlwaysOnTop ? (WS_EX_TOPMOST | WS_EX_TOOLWINDOW) : WS_EX_TOOLWINDOW, AfxRegisterWndClass(CS_NOCLOSE), "MenuWindow", WS_POPUP, rect, AfxGetMainWnd(), 0, NULL); wnd->CenterWindow(AfxGetMainWnd()); as you said. But the pop up window is still in the primary display. And it doesn't locate in the center of the window.
May be then you should do
CRect rect;
parent->GetWindowRect(rect);
wnd->MoveWindow(rect.left,rect.top,500,400,TRUE);//500 ,400 is width and heightthis should work i think. If it works then you can adjust the wnd position according to rect values to where ever you want.
Regards, Sandip.
-
May be then you should do
CRect rect;
parent->GetWindowRect(rect);
wnd->MoveWindow(rect.left,rect.top,500,400,TRUE);//500 ,400 is width and heightthis should work i think. If it works then you can adjust the wnd position according to rect values to where ever you want.
Regards, Sandip.
Hi Sandip, Thank you very much for your so nice help. I tried the code above, but it still doesn't work. I debugged it. rect.left is -2200, rect.right is -786. Does it mean the parent lies in the secondary display? I set the secondary display as in the left side, and the primary display in the right side. The strange thing is that whatever I do, the pop up window is always in the primary display, the same position. Best regards,