how to avoid window swing when it zoom out from center point
-
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)
-
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)
«_Superman_»
I love work. It gives me something to do between weekends. -
«_Superman_»
I love work. It gives me something to do between weekends. -
«_Superman_»
I love work. It gives me something to do between weekends. -
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)
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...
-
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)
-
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)