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. storing a windows postion in the registry...

storing a windows postion in the registry...

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminquestion
8 Posts 5 Posters 1 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.
  • P Offline
    P Offline
    paranoid android
    wrote on last edited by
    #1

    I've tried to store the windows location/size in the registry, and it appears to save the right numbers, but when I read them back in and call MoveWindow it seems to change the numbers. Is move window the right function to call for this, or am I saving the wrong postion using by calling GetWindowRect? I'm pretty sure that its not any of the code that is wrong, but rather that I'm not saving the right numbers. thanks tyler.

    C P A P 4 Replies Last reply
    0
    • P paranoid android

      I've tried to store the windows location/size in the registry, and it appears to save the right numbers, but when I read them back in and call MoveWindow it seems to change the numbers. Is move window the right function to call for this, or am I saving the wrong postion using by calling GetWindowRect? I'm pretty sure that its not any of the code that is wrong, but rather that I'm not saving the right numbers. thanks tyler.

      C Offline
      C Offline
      Christian
      wrote on last edited by
      #2

      There are a few possible issues. 1/ Where are you setting the position 2/ what sort of co-ordinates are you saving ( relative to window or relative to dialog ) ? ClientToScreen will convert your co-ordinates to ones relative to the whole window 3/ Have you checked the values going in and coming out to make sure you're reading them correctly ? 4/ Are you passing them in correctly ( MoveWindow takes a width and height, rather than x2, y2. )

      P 1 Reply Last reply
      0
      • P paranoid android

        I've tried to store the windows location/size in the registry, and it appears to save the right numbers, but when I read them back in and call MoveWindow it seems to change the numbers. Is move window the right function to call for this, or am I saving the wrong postion using by calling GetWindowRect? I'm pretty sure that its not any of the code that is wrong, but rather that I'm not saving the right numbers. thanks tyler.

        P Offline
        P Offline
        Paolo Messina
        wrote on last edited by
        #3

        You may also try with Get/SetWindowPlacement(). If you save and restore all its fields you can also restore minimized/maximized state. Cheers Paolo.

        1 Reply Last reply
        0
        • P paranoid android

          I've tried to store the windows location/size in the registry, and it appears to save the right numbers, but when I read them back in and call MoveWindow it seems to change the numbers. Is move window the right function to call for this, or am I saving the wrong postion using by calling GetWindowRect? I'm pretty sure that its not any of the code that is wrong, but rather that I'm not saving the right numbers. thanks tyler.

          A Offline
          A Offline
          Andre Dewispelaere 0
          wrote on last edited by
          #4

          I suggest that you should read the topic about Persistent Frames in the book Inside Visual C++ from Kruglinsky from Microsoft Press.

          1 Reply Last reply
          0
          • P paranoid android

            I've tried to store the windows location/size in the registry, and it appears to save the right numbers, but when I read them back in and call MoveWindow it seems to change the numbers. Is move window the right function to call for this, or am I saving the wrong postion using by calling GetWindowRect? I'm pretty sure that its not any of the code that is wrong, but rather that I'm not saving the right numbers. thanks tyler.

            P Offline
            P Offline
            Philip Nicoletti
            wrote on last edited by
            #5

            to save the Window position :

            WINDOWPLACEMENT pwp;
            BOOL            ret;
            
            ret = GetWindowPlacement(&pwp);
            
            
            CString strBuffer;
            
            strBuffer.Format("%i %i %i %i %i %i %i %i %i %i",
            	pwp.flags, pwp.showCmd,
            	pwp.ptMinPosition.x , pwp.ptMinPosition.y , 
            	pwp.ptMaxPosition.x , pwp.ptMaxPosition.y , 
            	pwp.rcNormalPosition.left , pwp.rcNormalPosition.top , 
            	pwp.rcNormalPosition.right , pwp.rcNormalPosition.bottom);
            
            
            AfxGetApp()->WriteProfileString("Settings","windowPos",strBuffer);
            

            to restore the window position :

            WINDOWPLACEMENT pwp;
            CString strBuffer = AfxGetApp ()->GetProfileString("Settings","windowPos");
            
            int cRead = \_stscanf(strBuffer,"%i %i %i %i %i %i %i %i %i %i",
            	&pwp.flags,&pwp.showCmd,
            	&pwp.ptMinPosition.x , &pwp.ptMinPosition.y , 
            	&pwp.ptMaxPosition.x , &pwp.ptMaxPosition.y ,
            	&pwp.rcNormalPosition.left , &pwp.rcNormalPosition.top ,
            	&pwp.rcNormalPosition.right , &pwp.rcNormalPosition.bottom);
            
            if (cRead == 10) SetWindowPlacement(&pwp);
            
            P 2 Replies Last reply
            0
            • C Christian

              There are a few possible issues. 1/ Where are you setting the position 2/ what sort of co-ordinates are you saving ( relative to window or relative to dialog ) ? ClientToScreen will convert your co-ordinates to ones relative to the whole window 3/ Have you checked the values going in and coming out to make sure you're reading them correctly ? 4/ Are you passing them in correctly ( MoveWindow takes a width and height, rather than x2, y2. )

              P Offline
              P Offline
              paranoid android
              wrote on last edited by
              #6

              ah yeah, MoveWindow takes width and height and not x2, y2. I wish I remembered that. I did this once in MFC though the same way with MoveWindow using GetWindowRect but when looking back through the code I missed the rect.Width(), and rect.Height() instead of just a RECT structure passing the bottom and right. thanks for the help.

              1 Reply Last reply
              0
              • P Philip Nicoletti

                to save the Window position :

                WINDOWPLACEMENT pwp;
                BOOL            ret;
                
                ret = GetWindowPlacement(&pwp);
                
                
                CString strBuffer;
                
                strBuffer.Format("%i %i %i %i %i %i %i %i %i %i",
                	pwp.flags, pwp.showCmd,
                	pwp.ptMinPosition.x , pwp.ptMinPosition.y , 
                	pwp.ptMaxPosition.x , pwp.ptMaxPosition.y , 
                	pwp.rcNormalPosition.left , pwp.rcNormalPosition.top , 
                	pwp.rcNormalPosition.right , pwp.rcNormalPosition.bottom);
                
                
                AfxGetApp()->WriteProfileString("Settings","windowPos",strBuffer);
                

                to restore the window position :

                WINDOWPLACEMENT pwp;
                CString strBuffer = AfxGetApp ()->GetProfileString("Settings","windowPos");
                
                int cRead = \_stscanf(strBuffer,"%i %i %i %i %i %i %i %i %i %i",
                	&pwp.flags,&pwp.showCmd,
                	&pwp.ptMinPosition.x , &pwp.ptMinPosition.y , 
                	&pwp.ptMaxPosition.x , &pwp.ptMaxPosition.y ,
                	&pwp.rcNormalPosition.left , &pwp.rcNormalPosition.top ,
                	&pwp.rcNormalPosition.right , &pwp.rcNormalPosition.bottom);
                
                if (cRead == 10) SetWindowPlacement(&pwp);
                
                P Offline
                P Offline
                paranoid android
                wrote on last edited by
                #7

                thanks a lot, this is much better than what I was doing previously.

                1 Reply Last reply
                0
                • P Philip Nicoletti

                  to save the Window position :

                  WINDOWPLACEMENT pwp;
                  BOOL            ret;
                  
                  ret = GetWindowPlacement(&pwp);
                  
                  
                  CString strBuffer;
                  
                  strBuffer.Format("%i %i %i %i %i %i %i %i %i %i",
                  	pwp.flags, pwp.showCmd,
                  	pwp.ptMinPosition.x , pwp.ptMinPosition.y , 
                  	pwp.ptMaxPosition.x , pwp.ptMaxPosition.y , 
                  	pwp.rcNormalPosition.left , pwp.rcNormalPosition.top , 
                  	pwp.rcNormalPosition.right , pwp.rcNormalPosition.bottom);
                  
                  
                  AfxGetApp()->WriteProfileString("Settings","windowPos",strBuffer);
                  

                  to restore the window position :

                  WINDOWPLACEMENT pwp;
                  CString strBuffer = AfxGetApp ()->GetProfileString("Settings","windowPos");
                  
                  int cRead = \_stscanf(strBuffer,"%i %i %i %i %i %i %i %i %i %i",
                  	&pwp.flags,&pwp.showCmd,
                  	&pwp.ptMinPosition.x , &pwp.ptMinPosition.y , 
                  	&pwp.ptMaxPosition.x , &pwp.ptMaxPosition.y ,
                  	&pwp.rcNormalPosition.left , &pwp.rcNormalPosition.top ,
                  	&pwp.rcNormalPosition.right , &pwp.rcNormalPosition.bottom);
                  
                  if (cRead == 10) SetWindowPlacement(&pwp);
                  
                  P Offline
                  P Offline
                  paranoid android
                  wrote on last edited by
                  #8

                  Just one thing that you forgot, when you restore the window's position you need to set pwp.length = sizeof(pwp) for anybody else that sees this. Tyler.

                  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