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. Active window

Active window

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 2 Posters 0 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.
  • J Offline
    J Offline
    jpyp
    wrote on last edited by
    #1

    I have a fairly large dialog-based app which consists of a main dialog window and a large number of child dialogs. When I close a child window, the focus always goes back to the main dialog window instead of the window that had the focus previously. This used to work before, but since then we made a lot of changes and nobody noticed when it started doing this. Thanks for your help!

    jpyp

    J 1 Reply Last reply
    0
    • J jpyp

      I have a fairly large dialog-based app which consists of a main dialog window and a large number of child dialogs. When I close a child window, the focus always goes back to the main dialog window instead of the window that had the focus previously. This used to work before, but since then we made a lot of changes and nobody noticed when it started doing this. Thanks for your help!

      jpyp

      J Offline
      J Offline
      jk chan
      wrote on last edited by
      #2

      Check your Z- order of your windows.

      If u can Dream... U can do it

      J 1 Reply Last reply
      0
      • J jk chan

        Check your Z- order of your windows.

        If u can Dream... U can do it

        J Offline
        J Offline
        jpyp
        wrote on last edited by
        #3

        krishnadevank wrote:

        Check your Z- order of your windows.

        I did and I can't see what is wrong. Here is more info. In the OnCreate function of the main window, I position the window as follows: SetWindowPos(&wndBottom, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE)); Then in the main window code, I create each child window as follows: page is a global array that contains info of all openned child windows. page[0].pDlg = new CMyDlg0(this); page[0].pDlg->Create(_ID of this dialog_, NULL); page[0].pWnd->SetWindowPos(&wndTop, 20, 100, 0, 0, SWP_NOSIZE); page[1].pDlg = new CMyDlg1(this); page[1].pDlg->Create(_ID of this dialog_, NULL); page[1].pWnd->SetWindowPos(&wndTop, 20, 100, 0, 0, SWP_NOSIZE); In the CMyDlg0 OnInitDialog() function: page[0].pWnd = this; In the CMyDlg1 OnInitDialog() function: page[1].pWnd = this; We didn't design this code. We inherited it from the company that design the app for us. We only maintain the code. We would have done things differently but we are now stuck with this. Thanks in advance for your help!

        jpyp

        J 1 Reply Last reply
        0
        • J jpyp

          krishnadevank wrote:

          Check your Z- order of your windows.

          I did and I can't see what is wrong. Here is more info. In the OnCreate function of the main window, I position the window as follows: SetWindowPos(&wndBottom, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE)); Then in the main window code, I create each child window as follows: page is a global array that contains info of all openned child windows. page[0].pDlg = new CMyDlg0(this); page[0].pDlg->Create(_ID of this dialog_, NULL); page[0].pWnd->SetWindowPos(&wndTop, 20, 100, 0, 0, SWP_NOSIZE); page[1].pDlg = new CMyDlg1(this); page[1].pDlg->Create(_ID of this dialog_, NULL); page[1].pWnd->SetWindowPos(&wndTop, 20, 100, 0, 0, SWP_NOSIZE); In the CMyDlg0 OnInitDialog() function: page[0].pWnd = this; In the CMyDlg1 OnInitDialog() function: page[1].pWnd = this; We didn't design this code. We inherited it from the company that design the app for us. We only maintain the code. We would have done things differently but we are now stuck with this. Thanks in advance for your help!

          jpyp

          J Offline
          J Offline
          jk chan
          wrote on last edited by
          #4

          Call setwindowpos with ur opend child window handles as hWndInsertAfter in a loop , So that it will be arrange it Z order. In the above code u put it as 0 (HWND_TOP). for(all opned child windows) BOOL SetWindowPos( HWND hWnd, HWND hWndInsertAfter, // placement-order handle int X, int Y, int cx, int cy, UINT uFlags ); } Hopes this helps.

          If u can Dream... U can do it

          J 1 Reply Last reply
          0
          • J jk chan

            Call setwindowpos with ur opend child window handles as hWndInsertAfter in a loop , So that it will be arrange it Z order. In the above code u put it as 0 (HWND_TOP). for(all opned child windows) BOOL SetWindowPos( HWND hWnd, HWND hWndInsertAfter, // placement-order handle int X, int Y, int cx, int cy, UINT uFlags ); } Hopes this helps.

            If u can Dream... U can do it

            J Offline
            J Offline
            jpyp
            wrote on last edited by
            #5

            Thanks for your response! I thought I understood this Z-order thing but maybe I'm missing something. I have tried what you recommended with no success. The result was actually worst. I tried the following: (the lines in italic are what has changed from my original code) I set the position of the main window. SetWindowPos(&wndBottom, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE)); Then I open the first 2 child windows as follows: (this not done in a loop) page[0].pDlg = new CMyDlg0(this); page[0].pDlg->Create(ID of this dialog, NULL); _HWND pHwnd = page[0].pWnd->GetSafeHwnd(); ::SetWindowPos(pWnd, HWND_TOP, 20, 100, 0, 0, SWP_NOSIZE);_ page[1].pDlg = new CMyDlg0(this); page[1].pDlg->Create(ID of this dialog, NULL); _HWND pHwnd = page[1].pWnd->GetSafeHwnd(); ::SetWindowPos(pWnd, HWND_TOP, 20, 100, 0, 0, SWP_NOSIZE);_ If I understand how this work, at this point my Z-order should look like this: page[1] page[0] main window I started with the main window at the bottom, then I open the first child window with HWND_TOP which puts it at the top and keeping the main window at the bottom. Then I open the second window again with HWND_TOP which in turns puts it at the top and pushes down the other 2 windows to position 2 and 3 respectively. When I close page[1], page[0] should become the active window because it is the next higher up in the Z-order in order word now position 1. However in my case, the main window becomes the active window. Like I said, I must be missing something. Is there a way I can look at the Z-order list?

            jpyp

            J 1 Reply Last reply
            0
            • J jpyp

              Thanks for your response! I thought I understood this Z-order thing but maybe I'm missing something. I have tried what you recommended with no success. The result was actually worst. I tried the following: (the lines in italic are what has changed from my original code) I set the position of the main window. SetWindowPos(&wndBottom, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE)); Then I open the first 2 child windows as follows: (this not done in a loop) page[0].pDlg = new CMyDlg0(this); page[0].pDlg->Create(ID of this dialog, NULL); _HWND pHwnd = page[0].pWnd->GetSafeHwnd(); ::SetWindowPos(pWnd, HWND_TOP, 20, 100, 0, 0, SWP_NOSIZE);_ page[1].pDlg = new CMyDlg0(this); page[1].pDlg->Create(ID of this dialog, NULL); _HWND pHwnd = page[1].pWnd->GetSafeHwnd(); ::SetWindowPos(pWnd, HWND_TOP, 20, 100, 0, 0, SWP_NOSIZE);_ If I understand how this work, at this point my Z-order should look like this: page[1] page[0] main window I started with the main window at the bottom, then I open the first child window with HWND_TOP which puts it at the top and keeping the main window at the bottom. Then I open the second window again with HWND_TOP which in turns puts it at the top and pushes down the other 2 windows to position 2 and 3 respectively. When I close page[1], page[0] should become the active window because it is the next higher up in the Z-order in order word now position 1. However in my case, the main window becomes the active window. Like I said, I must be missing something. Is there a way I can look at the Z-order list?

              jpyp

              J Offline
              J Offline
              jk chan
              wrote on last edited by
              #6

              You are wrong. Don't put HWND_TOP there. put ur window handle. so that the system will place ur window next. hWndInsertAfter [in] Handle to the window to precede the positioned window in the Z order. """This parameter must be a window handle""" OR one of the following values. it may be like this setwindowPos(firstwind,secondwnd)

              If u can Dream... U can do it

              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