Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Dual monitor, pop up window goes to primary display

Dual monitor, pop up window goes to primary display

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    logiqworks
    wrote on last edited by
    #1

    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!

    S 1 Reply Last reply
    0
    • L logiqworks

      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!

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      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.

      L 2 Replies Last reply
      0
      • S SandipG

        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.

        L Offline
        L Offline
        logiqworks
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S SandipG

          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.

          L Offline
          L Offline
          logiqworks
          wrote on last edited by
          #4

          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,

          V S 2 Replies Last reply
          0
          • L logiqworks

            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,

            V Offline
            V Offline
            vishalmore
            wrote on last edited by
            #5

            '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

            L 1 Reply Last reply
            0
            • L logiqworks

              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,

              S Offline
              S Offline
              SandipG
              wrote on last edited by
              #6

              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.

              L 1 Reply Last reply
              0
              • S SandipG

                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.

                L Offline
                L Offline
                logiqworks
                wrote on last edited by
                #7

                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.

                S 1 Reply Last reply
                0
                • V vishalmore

                  '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

                  L Offline
                  L Offline
                  logiqworks
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • L logiqworks

                    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.

                    S Offline
                    S Offline
                    SandipG
                    wrote on last edited by
                    #9

                    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.

                    L 1 Reply Last reply
                    0
                    • S SandipG

                      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.

                      L Offline
                      L Offline
                      logiqworks
                      wrote on last edited by
                      #10

                      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.

                      S 1 Reply Last reply
                      0
                      • L logiqworks

                        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.

                        S Offline
                        S Offline
                        SandipG
                        wrote on last edited by
                        #11

                        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 height

                        this 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.

                        L 1 Reply Last reply
                        0
                        • S SandipG

                          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 height

                          this 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.

                          L Offline
                          L Offline
                          logiqworks
                          wrote on last edited by
                          #12

                          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,

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups