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.
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);
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);
::ReleaseDC(m_hWnd,hdcScreen);
DeleteObject(hBitMap);
DeleteDC(hdcMemory);
hdcMemory=NULL;
}
void CWindowAnimateDlg::OnTimer(UINT_PTR nIDEvent)
{
switch(nIDEvent)
{
case 1:
{
CRect rect;
GetWindowRect(&rect);
CRect nRect;
int l,t,r,b;
l=m_targetRect.left-rect.left;
t=m_targetRect.top-rect.top;
r=m_targetRect.right-rect.right;
b=m_targetRect.bottom-rect.bottom;
nRect.SetRect(
rect.left+(l>0?l/5+1:l/5-1),
rect.top+(t>0?t/5+1:t/5-1),
rect.right+(r>0?r/5+1:r/5-1),
rect.bottom+(b>0?b/5+1:b/5-1)
);
if(
abs(l)<2&&
abs(t)<2&&
abs(r)<2&&
abs(b)<2
)
{
KillTimer(1);
MoveWindow(&m_targetRect);
break;
}
MoveWindow(&nRect);
}
}
CDialog::OnTimer(nIDEvent);
}
void CWindowAnimateDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
CDialog::OnWindowPosChanged(lpwndpos);
if(!(lpwndpos->flags&SWP_NOSIZE))
DrawBackground();
}
void CWindowAnimateDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if(m_state==1)
{
m_state=2;
m_targetRect.SetRect(550,300,650,400);
SetTimer(1,30,NULL);
}
else if(m_state==2)
{
m_state=1;
m_targetRect.SetRect(150,150,950,550);
SetTimer(1,30,NULL);
}
CDialog::OnLButtonDown(nFlags, point);
}
|