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. how to avoid window swing when it zoom out from center point

how to avoid window swing when it zoom out from center point

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformstutorialquestion
7 Posts 3 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.
  • O Offline
    O Offline
    onlywjh
    wrote on last edited by
    #1

    hi everyone. i want to create a window which can zoom out from the center,but the window swung when i use MoveWindow/SetWindowPos to reposition and resize the window. it was just like the situation below. 1:____[--]____ (original place) 2:___[--]_____ (rePosition) the right side of the window has gone astern 3:___[----]___ (reSize) 4:__[----]____ (rePosition) 5:__[------]__ (reSize) 6:_[------]___ (rePosition) 7:_[--------]_ (final place) does anyone has the solution about that? code as below.

    //draw window background with gdi+ and UpdateLayerdWindow
    void CWindowAnimateDlg::DrawBackground()
    {
    CDC* dc=this->GetWindowDC();
    HDC hdcMemory=CreateCompatibleDC(dc->GetSafeHdc());

    CRect rct;
    GetWindowRect(&rct);
    //{
    	BITMAPINFO bmih;
    	ZeroMemory( &bmih, sizeof( BITMAPINFO ) );
    	bmih.bmiHeader.biSize                  = sizeof (BITMAPINFOHEADER) ;
    	bmih.bmiHeader.biWidth                = rct.Width() ;
    	bmih.bmiHeader.biHeight                = rct.Height() ;
    	bmih.bmiHeader.biPlanes                = 1 ;
    	bmih.bmiHeader.biBitCount              = 32;        
    	bmih.bmiHeader.biCompression          = BI\_RGB ;
    	bmih.bmiHeader.biSizeImage            = 0 ;
    	bmih.bmiHeader.biXPelsPerMeter        = 0 ;
    	bmih.bmiHeader.biYPelsPerMeter        = 0 ;
    	bmih.bmiHeader.biClrUsed              = 0 ;
    	bmih.bmiHeader.biClrImportant          = 0 ;
    
    //}
    
    HBITMAP hBitMap;
    hBitMap = CreateDIBSection (NULL,   &bmih, 0, NULL, NULL, 0) ;
    
    HBITMAP oldBitmap=(HBITMAP)SelectObject(hdcMemory,hBitMap);
    
    //GDI+
    Graphics gpc(hdcMemory);
    gpc.SetCompositingMode(CompositingModeSourceCopy);
    
    DWORD dwExStyle=GetWindowLong(m\_hWnd,GWL\_EXSTYLE);
    SetWindowLongA(m\_hWnd,GWL\_EXSTYLE,dwExStyle|WS\_EX\_LAYERED);
    
    HDC hdcScreen=::GetDC(m\_hWnd);
    CDC cdc;
    cdc.Attach(hdcScreen);
    CDC cdc2;
    cdc2.Attach(hdcMemory);
    
    if(m\_bkImage)
    {
    	gpc.DrawImage(
    		m\_bkImage,
    		Rect(0,0,rct.Width(),rct.Height()),
    		0,0,m\_bkImage->GetWidth(),m\_bkImage->GetHeight(),
    		UnitPixel
    		);
    }
    
    POINT ptWinPos={rct.left,rct.top};
    POINT ptSrc={0,0};
    SIZE sizeWindow={rct.Width(),rct.Height()};
    BLENDFUNCTION blend;
    blend.BlendOp=0; 
    blend.BlendFlags=0; 
    blend.AlphaFormat=AC\_SRC\_ALPHA; 
    blend.SourceConstantAlpha=255;
    
    UpdateLayeredWindow( &cdc,&ptWinPos,
                        &sizeWindow,&cdc2,&ptSrc,0,&blend,ULW\_ALPHA);
    
    ::SelectObject(hdcMemory,oldBitmap);
    ReleaseDC(dc);
    gpc.ReleaseHDC(hdcMemory)
    
    _ R O 4 Replies Last reply
    0
    • O onlywjh

      hi everyone. i want to create a window which can zoom out from the center,but the window swung when i use MoveWindow/SetWindowPos to reposition and resize the window. it was just like the situation below. 1:____[--]____ (original place) 2:___[--]_____ (rePosition) the right side of the window has gone astern 3:___[----]___ (reSize) 4:__[----]____ (rePosition) 5:__[------]__ (reSize) 6:_[------]___ (rePosition) 7:_[--------]_ (final place) does anyone has the solution about that? code as below.

      //draw window background with gdi+ and UpdateLayerdWindow
      void CWindowAnimateDlg::DrawBackground()
      {
      CDC* dc=this->GetWindowDC();
      HDC hdcMemory=CreateCompatibleDC(dc->GetSafeHdc());

      CRect rct;
      GetWindowRect(&rct);
      //{
      	BITMAPINFO bmih;
      	ZeroMemory( &bmih, sizeof( BITMAPINFO ) );
      	bmih.bmiHeader.biSize                  = sizeof (BITMAPINFOHEADER) ;
      	bmih.bmiHeader.biWidth                = rct.Width() ;
      	bmih.bmiHeader.biHeight                = rct.Height() ;
      	bmih.bmiHeader.biPlanes                = 1 ;
      	bmih.bmiHeader.biBitCount              = 32;        
      	bmih.bmiHeader.biCompression          = BI\_RGB ;
      	bmih.bmiHeader.biSizeImage            = 0 ;
      	bmih.bmiHeader.biXPelsPerMeter        = 0 ;
      	bmih.bmiHeader.biYPelsPerMeter        = 0 ;
      	bmih.bmiHeader.biClrUsed              = 0 ;
      	bmih.bmiHeader.biClrImportant          = 0 ;
      
      //}
      
      HBITMAP hBitMap;
      hBitMap = CreateDIBSection (NULL,   &bmih, 0, NULL, NULL, 0) ;
      
      HBITMAP oldBitmap=(HBITMAP)SelectObject(hdcMemory,hBitMap);
      
      //GDI+
      Graphics gpc(hdcMemory);
      gpc.SetCompositingMode(CompositingModeSourceCopy);
      
      DWORD dwExStyle=GetWindowLong(m\_hWnd,GWL\_EXSTYLE);
      SetWindowLongA(m\_hWnd,GWL\_EXSTYLE,dwExStyle|WS\_EX\_LAYERED);
      
      HDC hdcScreen=::GetDC(m\_hWnd);
      CDC cdc;
      cdc.Attach(hdcScreen);
      CDC cdc2;
      cdc2.Attach(hdcMemory);
      
      if(m\_bkImage)
      {
      	gpc.DrawImage(
      		m\_bkImage,
      		Rect(0,0,rct.Width(),rct.Height()),
      		0,0,m\_bkImage->GetWidth(),m\_bkImage->GetHeight(),
      		UnitPixel
      		);
      }
      
      POINT ptWinPos={rct.left,rct.top};
      POINT ptSrc={0,0};
      SIZE sizeWindow={rct.Width(),rct.Height()};
      BLENDFUNCTION blend;
      blend.BlendOp=0; 
      blend.BlendFlags=0; 
      blend.AlphaFormat=AC\_SRC\_ALPHA; 
      blend.SourceConstantAlpha=255;
      
      UpdateLayeredWindow( &cdc,&ptWinPos,
                          &sizeWindow,&cdc2,&ptSrc,0,&blend,ULW\_ALPHA);
      
      ::SelectObject(hdcMemory,oldBitmap);
      ReleaseDC(dc);
      gpc.ReleaseHDC(hdcMemory)
      
      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      AnimateWindow[^]

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      O 2 Replies Last reply
      0
      • _ _Superman_

        AnimateWindow[^]

        «_Superman_»
        I love work. It gives me something to do between weekends.

        Microsoft MVP (Visual C++)

        Polymorphism in C

        O Offline
        O Offline
        onlywjh
        wrote on last edited by
        #3

        thanks for your reply. but, AnimateWindow does not help i think. i want to move the window from one Rect to another Rect smoothly.

        1 Reply Last reply
        0
        • _ _Superman_

          AnimateWindow[^]

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          O Offline
          O Offline
          onlywjh
          wrote on last edited by
          #4

          and, why SetWindowPos make the window 'resize' and 'reposition' seperetely? does anybody know? thank you.

          1 Reply Last reply
          0
          • O onlywjh

            hi everyone. i want to create a window which can zoom out from the center,but the window swung when i use MoveWindow/SetWindowPos to reposition and resize the window. it was just like the situation below. 1:____[--]____ (original place) 2:___[--]_____ (rePosition) the right side of the window has gone astern 3:___[----]___ (reSize) 4:__[----]____ (rePosition) 5:__[------]__ (reSize) 6:_[------]___ (rePosition) 7:_[--------]_ (final place) does anyone has the solution about that? code as below.

            //draw window background with gdi+ and UpdateLayerdWindow
            void CWindowAnimateDlg::DrawBackground()
            {
            CDC* dc=this->GetWindowDC();
            HDC hdcMemory=CreateCompatibleDC(dc->GetSafeHdc());

            CRect rct;
            GetWindowRect(&rct);
            //{
            	BITMAPINFO bmih;
            	ZeroMemory( &bmih, sizeof( BITMAPINFO ) );
            	bmih.bmiHeader.biSize                  = sizeof (BITMAPINFOHEADER) ;
            	bmih.bmiHeader.biWidth                = rct.Width() ;
            	bmih.bmiHeader.biHeight                = rct.Height() ;
            	bmih.bmiHeader.biPlanes                = 1 ;
            	bmih.bmiHeader.biBitCount              = 32;        
            	bmih.bmiHeader.biCompression          = BI\_RGB ;
            	bmih.bmiHeader.biSizeImage            = 0 ;
            	bmih.bmiHeader.biXPelsPerMeter        = 0 ;
            	bmih.bmiHeader.biYPelsPerMeter        = 0 ;
            	bmih.bmiHeader.biClrUsed              = 0 ;
            	bmih.bmiHeader.biClrImportant          = 0 ;
            
            //}
            
            HBITMAP hBitMap;
            hBitMap = CreateDIBSection (NULL,   &bmih, 0, NULL, NULL, 0) ;
            
            HBITMAP oldBitmap=(HBITMAP)SelectObject(hdcMemory,hBitMap);
            
            //GDI+
            Graphics gpc(hdcMemory);
            gpc.SetCompositingMode(CompositingModeSourceCopy);
            
            DWORD dwExStyle=GetWindowLong(m\_hWnd,GWL\_EXSTYLE);
            SetWindowLongA(m\_hWnd,GWL\_EXSTYLE,dwExStyle|WS\_EX\_LAYERED);
            
            HDC hdcScreen=::GetDC(m\_hWnd);
            CDC cdc;
            cdc.Attach(hdcScreen);
            CDC cdc2;
            cdc2.Attach(hdcMemory);
            
            if(m\_bkImage)
            {
            	gpc.DrawImage(
            		m\_bkImage,
            		Rect(0,0,rct.Width(),rct.Height()),
            		0,0,m\_bkImage->GetWidth(),m\_bkImage->GetHeight(),
            		UnitPixel
            		);
            }
            
            POINT ptWinPos={rct.left,rct.top};
            POINT ptSrc={0,0};
            SIZE sizeWindow={rct.Width(),rct.Height()};
            BLENDFUNCTION blend;
            blend.BlendOp=0; 
            blend.BlendFlags=0; 
            blend.AlphaFormat=AC\_SRC\_ALPHA; 
            blend.SourceConstantAlpha=255;
            
            UpdateLayeredWindow( &cdc,&ptWinPos,
                                &sizeWindow,&cdc2,&ptSrc,0,&blend,ULW\_ALPHA);
            
            ::SelectObject(hdcMemory,oldBitmap);
            ReleaseDC(dc);
            gpc.ReleaseHDC(hdcMemory)
            
            R Offline
            R Offline
            Rozis
            wrote on last edited by
            #5

            I guess it is because reposition and size lead both to a repaint of the window. You could use validaterect() or validatewindowrgn() (these are GDI-functions, look for GDI+ equivalents) after reposition so windows believes there's no need to repaint. Then repainting only occurs after size showing the reposition also. Hope this will work...

            1 Reply Last reply
            0
            • O onlywjh

              hi everyone. i want to create a window which can zoom out from the center,but the window swung when i use MoveWindow/SetWindowPos to reposition and resize the window. it was just like the situation below. 1:____[--]____ (original place) 2:___[--]_____ (rePosition) the right side of the window has gone astern 3:___[----]___ (reSize) 4:__[----]____ (rePosition) 5:__[------]__ (reSize) 6:_[------]___ (rePosition) 7:_[--------]_ (final place) does anyone has the solution about that? code as below.

              //draw window background with gdi+ and UpdateLayerdWindow
              void CWindowAnimateDlg::DrawBackground()
              {
              CDC* dc=this->GetWindowDC();
              HDC hdcMemory=CreateCompatibleDC(dc->GetSafeHdc());

              CRect rct;
              GetWindowRect(&rct);
              //{
              	BITMAPINFO bmih;
              	ZeroMemory( &bmih, sizeof( BITMAPINFO ) );
              	bmih.bmiHeader.biSize                  = sizeof (BITMAPINFOHEADER) ;
              	bmih.bmiHeader.biWidth                = rct.Width() ;
              	bmih.bmiHeader.biHeight                = rct.Height() ;
              	bmih.bmiHeader.biPlanes                = 1 ;
              	bmih.bmiHeader.biBitCount              = 32;        
              	bmih.bmiHeader.biCompression          = BI\_RGB ;
              	bmih.bmiHeader.biSizeImage            = 0 ;
              	bmih.bmiHeader.biXPelsPerMeter        = 0 ;
              	bmih.bmiHeader.biYPelsPerMeter        = 0 ;
              	bmih.bmiHeader.biClrUsed              = 0 ;
              	bmih.bmiHeader.biClrImportant          = 0 ;
              
              //}
              
              HBITMAP hBitMap;
              hBitMap = CreateDIBSection (NULL,   &bmih, 0, NULL, NULL, 0) ;
              
              HBITMAP oldBitmap=(HBITMAP)SelectObject(hdcMemory,hBitMap);
              
              //GDI+
              Graphics gpc(hdcMemory);
              gpc.SetCompositingMode(CompositingModeSourceCopy);
              
              DWORD dwExStyle=GetWindowLong(m\_hWnd,GWL\_EXSTYLE);
              SetWindowLongA(m\_hWnd,GWL\_EXSTYLE,dwExStyle|WS\_EX\_LAYERED);
              
              HDC hdcScreen=::GetDC(m\_hWnd);
              CDC cdc;
              cdc.Attach(hdcScreen);
              CDC cdc2;
              cdc2.Attach(hdcMemory);
              
              if(m\_bkImage)
              {
              	gpc.DrawImage(
              		m\_bkImage,
              		Rect(0,0,rct.Width(),rct.Height()),
              		0,0,m\_bkImage->GetWidth(),m\_bkImage->GetHeight(),
              		UnitPixel
              		);
              }
              
              POINT ptWinPos={rct.left,rct.top};
              POINT ptSrc={0,0};
              SIZE sizeWindow={rct.Width(),rct.Height()};
              BLENDFUNCTION blend;
              blend.BlendOp=0; 
              blend.BlendFlags=0; 
              blend.AlphaFormat=AC\_SRC\_ALPHA; 
              blend.SourceConstantAlpha=255;
              
              UpdateLayeredWindow( &cdc,&ptWinPos,
                                  &sizeWindow,&cdc2,&ptSrc,0,&blend,ULW\_ALPHA);
              
              ::SelectObject(hdcMemory,oldBitmap);
              ReleaseDC(dc);
              gpc.ReleaseHDC(hdcMemory)
              
              O Offline
              O Offline
              onlywjh
              wrote on last edited by
              #6

              anyone has other ideas?

              1 Reply Last reply
              0
              • O onlywjh

                hi everyone. i want to create a window which can zoom out from the center,but the window swung when i use MoveWindow/SetWindowPos to reposition and resize the window. it was just like the situation below. 1:____[--]____ (original place) 2:___[--]_____ (rePosition) the right side of the window has gone astern 3:___[----]___ (reSize) 4:__[----]____ (rePosition) 5:__[------]__ (reSize) 6:_[------]___ (rePosition) 7:_[--------]_ (final place) does anyone has the solution about that? code as below.

                //draw window background with gdi+ and UpdateLayerdWindow
                void CWindowAnimateDlg::DrawBackground()
                {
                CDC* dc=this->GetWindowDC();
                HDC hdcMemory=CreateCompatibleDC(dc->GetSafeHdc());

                CRect rct;
                GetWindowRect(&rct);
                //{
                	BITMAPINFO bmih;
                	ZeroMemory( &bmih, sizeof( BITMAPINFO ) );
                	bmih.bmiHeader.biSize                  = sizeof (BITMAPINFOHEADER) ;
                	bmih.bmiHeader.biWidth                = rct.Width() ;
                	bmih.bmiHeader.biHeight                = rct.Height() ;
                	bmih.bmiHeader.biPlanes                = 1 ;
                	bmih.bmiHeader.biBitCount              = 32;        
                	bmih.bmiHeader.biCompression          = BI\_RGB ;
                	bmih.bmiHeader.biSizeImage            = 0 ;
                	bmih.bmiHeader.biXPelsPerMeter        = 0 ;
                	bmih.bmiHeader.biYPelsPerMeter        = 0 ;
                	bmih.bmiHeader.biClrUsed              = 0 ;
                	bmih.bmiHeader.biClrImportant          = 0 ;
                
                //}
                
                HBITMAP hBitMap;
                hBitMap = CreateDIBSection (NULL,   &bmih, 0, NULL, NULL, 0) ;
                
                HBITMAP oldBitmap=(HBITMAP)SelectObject(hdcMemory,hBitMap);
                
                //GDI+
                Graphics gpc(hdcMemory);
                gpc.SetCompositingMode(CompositingModeSourceCopy);
                
                DWORD dwExStyle=GetWindowLong(m\_hWnd,GWL\_EXSTYLE);
                SetWindowLongA(m\_hWnd,GWL\_EXSTYLE,dwExStyle|WS\_EX\_LAYERED);
                
                HDC hdcScreen=::GetDC(m\_hWnd);
                CDC cdc;
                cdc.Attach(hdcScreen);
                CDC cdc2;
                cdc2.Attach(hdcMemory);
                
                if(m\_bkImage)
                {
                	gpc.DrawImage(
                		m\_bkImage,
                		Rect(0,0,rct.Width(),rct.Height()),
                		0,0,m\_bkImage->GetWidth(),m\_bkImage->GetHeight(),
                		UnitPixel
                		);
                }
                
                POINT ptWinPos={rct.left,rct.top};
                POINT ptSrc={0,0};
                SIZE sizeWindow={rct.Width(),rct.Height()};
                BLENDFUNCTION blend;
                blend.BlendOp=0; 
                blend.BlendFlags=0; 
                blend.AlphaFormat=AC\_SRC\_ALPHA; 
                blend.SourceConstantAlpha=255;
                
                UpdateLayeredWindow( &cdc,&ptWinPos,
                                    &sizeWindow,&cdc2,&ptSrc,0,&blend,ULW\_ALPHA);
                
                ::SelectObject(hdcMemory,oldBitmap);
                ReleaseDC(dc);
                gpc.ReleaseHDC(hdcMemory)
                
                O Offline
                O Offline
                onlywjh
                wrote on last edited by
                #7

                it seems did not work with the solution below .

                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