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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Window Size and position in registry

Window Size and position in registry

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswindows-admindebuggingtutorial
6 Posts 3 Posters 9 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.
  • E Offline
    E Offline
    electronicman_x
    wrote on last edited by
    #1

    2 questions: Q1: I'm currently working on an MDI program with controlbars and the Stingray Toolkit. I want to save the program's last size and position in the registry when the program is closed. Currently i'm able to store the controlbars locations into the registry using the SaveBarState function. I basically need to create my own registry key or find some similar function that will store the program's size and position like the SaveBarState function. I'm not really sure how to go about doing this. I can get the information about the program, but i dont know how to store it to the registry properly. Q2: The reason I'm doing this is because i want to save the appearance of the program so when it runs again it looks just as it was when it was closed. I also want to be able to size the program according to the screen real-estate on the desktop (the first time it runs or if the resolution changes). The reason for this is i have a few systems im running this program on that use multiple monitors and i dont want the window stretched across them. I also want to have control over the window size and position when it runs. I have some rough code, but i dont know if i should do things this way. some crappy code im playing with: (This lets me control the size but im not sure how safe this method is) //(inside MyApp()) CRect rClientSpace; CRect rc2; CWnd * pWndMain; pWndMain=(CWnd *)pMainFrame; pWndMain->GetWindowRect(rc2); SystemParametersInfo(SPI_GETWORKAREA,0,&rClientSpace,0); //checks horiz. and vert. to make sure it can make this window. if ( ((rc2.left+1000) < rClientSpace.right)&&((rc2.top+750) < rClientSpace.bottom) ) { pWndMain->SetWindowPos(NULL, rc2.left, rc2.top, 1000, 750,SWP_NOZORDER);//I want 1000x750 when feasible } pWndMain->GetWindowRect(rc2);//to see the results in debugger Any ideas or code would be great. Thanks ! Jeff Rothenberg Project Engineer Vector CANtech, Inc.

    M N 2 Replies Last reply
    0
    • E electronicman_x

      2 questions: Q1: I'm currently working on an MDI program with controlbars and the Stingray Toolkit. I want to save the program's last size and position in the registry when the program is closed. Currently i'm able to store the controlbars locations into the registry using the SaveBarState function. I basically need to create my own registry key or find some similar function that will store the program's size and position like the SaveBarState function. I'm not really sure how to go about doing this. I can get the information about the program, but i dont know how to store it to the registry properly. Q2: The reason I'm doing this is because i want to save the appearance of the program so when it runs again it looks just as it was when it was closed. I also want to be able to size the program according to the screen real-estate on the desktop (the first time it runs or if the resolution changes). The reason for this is i have a few systems im running this program on that use multiple monitors and i dont want the window stretched across them. I also want to have control over the window size and position when it runs. I have some rough code, but i dont know if i should do things this way. some crappy code im playing with: (This lets me control the size but im not sure how safe this method is) //(inside MyApp()) CRect rClientSpace; CRect rc2; CWnd * pWndMain; pWndMain=(CWnd *)pMainFrame; pWndMain->GetWindowRect(rc2); SystemParametersInfo(SPI_GETWORKAREA,0,&rClientSpace,0); //checks horiz. and vert. to make sure it can make this window. if ( ((rc2.left+1000) < rClientSpace.right)&&((rc2.top+750) < rClientSpace.bottom) ) { pWndMain->SetWindowPos(NULL, rc2.left, rc2.top, 1000, 750,SWP_NOZORDER);//I want 1000x750 when feasible } pWndMain->GetWindowRect(rc2);//to see the results in debugger Any ideas or code would be great. Thanks ! Jeff Rothenberg Project Engineer Vector CANtech, Inc.

      M Offline
      M Offline
      Miszou
      wrote on last edited by
      #2

      This is how I do it:

      void CMainFrame::OnDestroy()
      {
      WINDOWPLACEMENT wndPlace;
      if ( GetWindowPlacement( &wndPlace ) )
      {
      AfxGetApp()->WriteProfileInt( "WndPos", "Left", wndPlace.rcNormalPosition.left );
      AfxGetApp()->WriteProfileInt( "WndPos", "Top", wndPlace.rcNormalPosition.top );
      AfxGetApp()->WriteProfileInt( "WndPos", "Right", wndPlace.rcNormalPosition.right );
      AfxGetApp()->WriteProfileInt( "WndPos", "Bottom", wndPlace.rcNormalPosition.bottom );
      AfxGetApp()->WriteProfileInt( "WndPos", "Max", wndPlace.showCmd == SW_SHOWMAXIMIZED );
      }

      CFrameWnd::OnDestroy();
      

      }

      void CMainFrame::ActivateFrame(int nCmdShow)
      {
      CRect r;

      r.top = AfxGetApp()->GetProfileInt( "WndPos", "Top", 0 );
      r.left = AfxGetApp()->GetProfileInt( "WndPos", "Left", 0 );
      r.bottom = AfxGetApp()->GetProfileInt( "WndPos", "Bottom", 400 );
      r.right = AfxGetApp()->GetProfileInt( "WndPos", "Right", 600 );
      MoveWindow( r );
      
      if ( AfxGetApp()->GetProfileInt( "WndPos", "Max", -1 ) == -1 )
      {
      	CenterWindow();
      	nCmdShow = SW\_MAXIMIZE;
      }
      
      if ( AfxGetApp()->GetProfileInt( "WndPos", "Max", 0 ) == 1 )
      	nCmdShow = SW\_MAXIMIZE;
      
      CFrameWnd::ActivateFrame(nCmdShow);
      

      }


      There are 10 kinds of people - those that get binary and those that don't.

      E 1 Reply Last reply
      0
      • E electronicman_x

        2 questions: Q1: I'm currently working on an MDI program with controlbars and the Stingray Toolkit. I want to save the program's last size and position in the registry when the program is closed. Currently i'm able to store the controlbars locations into the registry using the SaveBarState function. I basically need to create my own registry key or find some similar function that will store the program's size and position like the SaveBarState function. I'm not really sure how to go about doing this. I can get the information about the program, but i dont know how to store it to the registry properly. Q2: The reason I'm doing this is because i want to save the appearance of the program so when it runs again it looks just as it was when it was closed. I also want to be able to size the program according to the screen real-estate on the desktop (the first time it runs or if the resolution changes). The reason for this is i have a few systems im running this program on that use multiple monitors and i dont want the window stretched across them. I also want to have control over the window size and position when it runs. I have some rough code, but i dont know if i should do things this way. some crappy code im playing with: (This lets me control the size but im not sure how safe this method is) //(inside MyApp()) CRect rClientSpace; CRect rc2; CWnd * pWndMain; pWndMain=(CWnd *)pMainFrame; pWndMain->GetWindowRect(rc2); SystemParametersInfo(SPI_GETWORKAREA,0,&rClientSpace,0); //checks horiz. and vert. to make sure it can make this window. if ( ((rc2.left+1000) < rClientSpace.right)&&((rc2.top+750) < rClientSpace.bottom) ) { pWndMain->SetWindowPos(NULL, rc2.left, rc2.top, 1000, 750,SWP_NOZORDER);//I want 1000x750 when feasible } pWndMain->GetWindowRect(rc2);//to see the results in debugger Any ideas or code would be great. Thanks ! Jeff Rothenberg Project Engineer Vector CANtech, Inc.

        N Offline
        N Offline
        Neville Franks
        wrote on last edited by
        #3

        Jeff, What version of StingRay are you using. OT-Pro includes SECWorkspaceManagerEx() which saves the size/pos/state of all windows/toolbars etc. I use this in ED (see sig). Also nore that SPI_GETWORKAREA is only for the primary monitor. If you want to force users only to use that, you are ok, but most users won't like that. Instead use code like: #include <multimon.h> if ( WinPlatform() & ( WIN_98 | WIN_NT5 ) && GetSystemMetrics( SM_CMONITORS ) > 1 // if > one monitor. ) { // SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN are the width and height, // in pixels, of the virtual screen. // SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN metrics are the coordinates // of the top left corner of the virtual screen. // The virtual screen is the bounding rectangle of all display monitors. // See also: SM_CMONITORS, SM_SAMEDISPLAYFORMAT. pRect->top = GetSystemMetrics( SM_YVIRTUALSCREEN ); pRect->left = GetSystemMetrics( SM_XVIRTUALSCREEN ); pRect->right = GetSystemMetrics( SM_CXVIRTUALSCREEN ) + pRect->left; pRect->bottom = GetSystemMetrics( SM_CYVIRTUALSCREEN ) + pRect->top; } There are articles here on Multimon which provides a good API for dealing with multiple monitors. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

        E 1 Reply Last reply
        0
        • M Miszou

          This is how I do it:

          void CMainFrame::OnDestroy()
          {
          WINDOWPLACEMENT wndPlace;
          if ( GetWindowPlacement( &wndPlace ) )
          {
          AfxGetApp()->WriteProfileInt( "WndPos", "Left", wndPlace.rcNormalPosition.left );
          AfxGetApp()->WriteProfileInt( "WndPos", "Top", wndPlace.rcNormalPosition.top );
          AfxGetApp()->WriteProfileInt( "WndPos", "Right", wndPlace.rcNormalPosition.right );
          AfxGetApp()->WriteProfileInt( "WndPos", "Bottom", wndPlace.rcNormalPosition.bottom );
          AfxGetApp()->WriteProfileInt( "WndPos", "Max", wndPlace.showCmd == SW_SHOWMAXIMIZED );
          }

          CFrameWnd::OnDestroy();
          

          }

          void CMainFrame::ActivateFrame(int nCmdShow)
          {
          CRect r;

          r.top = AfxGetApp()->GetProfileInt( "WndPos", "Top", 0 );
          r.left = AfxGetApp()->GetProfileInt( "WndPos", "Left", 0 );
          r.bottom = AfxGetApp()->GetProfileInt( "WndPos", "Bottom", 400 );
          r.right = AfxGetApp()->GetProfileInt( "WndPos", "Right", 600 );
          MoveWindow( r );
          
          if ( AfxGetApp()->GetProfileInt( "WndPos", "Max", -1 ) == -1 )
          {
          	CenterWindow();
          	nCmdShow = SW\_MAXIMIZE;
          }
          
          if ( AfxGetApp()->GetProfileInt( "WndPos", "Max", 0 ) == 1 )
          	nCmdShow = SW\_MAXIMIZE;
          
          CFrameWnd::ActivateFrame(nCmdShow);
          

          }


          There are 10 kinds of people - those that get binary and those that don't.

          E Offline
          E Offline
          electronicman_x
          wrote on last edited by
          #4

          Thanks, that worked well. Jeff Rothenberg Project Engineer Vector CANtech, Inc.

          1 Reply Last reply
          0
          • N Neville Franks

            Jeff, What version of StingRay are you using. OT-Pro includes SECWorkspaceManagerEx() which saves the size/pos/state of all windows/toolbars etc. I use this in ED (see sig). Also nore that SPI_GETWORKAREA is only for the primary monitor. If you want to force users only to use that, you are ok, but most users won't like that. Instead use code like: #include <multimon.h> if ( WinPlatform() & ( WIN_98 | WIN_NT5 ) && GetSystemMetrics( SM_CMONITORS ) > 1 // if > one monitor. ) { // SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN are the width and height, // in pixels, of the virtual screen. // SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN metrics are the coordinates // of the top left corner of the virtual screen. // The virtual screen is the bounding rectangle of all display monitors. // See also: SM_CMONITORS, SM_SAMEDISPLAYFORMAT. pRect->top = GetSystemMetrics( SM_YVIRTUALSCREEN ); pRect->left = GetSystemMetrics( SM_XVIRTUALSCREEN ); pRect->right = GetSystemMetrics( SM_CXVIRTUALSCREEN ) + pRect->left; pRect->bottom = GetSystemMetrics( SM_CYVIRTUALSCREEN ) + pRect->top; } There are articles here on Multimon which provides a good API for dealing with multiple monitors. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

            E Offline
            E Offline
            electronicman_x
            wrote on last edited by
            #5

            I'll have to try that out. The SPI_GETWORKAREA seems to work but probably because i have nView on my Geforce laptop video card. It acts like one wide monitor. Jeff Rothenberg Project Engineer Vector CANtech, Inc.

            N 1 Reply Last reply
            0
            • E electronicman_x

              I'll have to try that out. The SPI_GETWORKAREA seems to work but probably because i have nView on my Geforce laptop video card. It acts like one wide monitor. Jeff Rothenberg Project Engineer Vector CANtech, Inc.

              N Offline
              N Offline
              Neville Franks
              wrote on last edited by
              #6

              electronicman_x wrote: I'll have to try that out. Yes you must. electronicman_x wrote: The SPI_GETWORKAREA seems to work but probably because i have nView on my Geforce laptop video card. It acts like one wide monitor. This must be fooling SPI_GETWORKAREA. You need to disable this sort of stuff when developing and testing multi-monitor code. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

              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