Click here to Skip to main content
15,886,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C++ PinPopular
Rick York11-Aug-10 21:39
mveRick York11-Aug-10 21:39 
QuestionLNK2001 - Help needed Pin
Hari_1611-Aug-10 20:07
Hari_1611-Aug-10 20:07 
AnswerRe: LNK2001 - Help needed Pin
«_Superman_»11-Aug-10 20:09
professional«_Superman_»11-Aug-10 20:09 
GeneralRe: LNK2001 - Help needed Pin
Hari_1611-Aug-10 20:50
Hari_1611-Aug-10 20:50 
GeneralRe: LNK2001 - Help needed Pin
Hari_1611-Aug-10 21:22
Hari_1611-Aug-10 21:22 
AnswerRe: LNK2001 - Help needed Pin
Rick York11-Aug-10 21:40
mveRick York11-Aug-10 21:40 
GeneralRe: LNK2001 - Help needed Pin
Hari_1611-Aug-10 23:01
Hari_1611-Aug-10 23:01 
Questionhow to avoid window swing when it zoom out from center point Pin
onlywjh11-Aug-10 16:31
onlywjh11-Aug-10 16:31 
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);
    ::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(//next place .non linear fade
				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(//very close target place
				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);
}

AnswerRe: how to avoid window swing when it zoom out from center point Pin
«_Superman_»11-Aug-10 18:59
professional«_Superman_»11-Aug-10 18:59 
GeneralRe: how to avoid window swing when it zoom out from center point Pin
onlywjh13-Aug-10 0:36
onlywjh13-Aug-10 0:36 
GeneralRe: how to avoid window swing when it zoom out from center point Pin
onlywjh13-Aug-10 0:38
onlywjh13-Aug-10 0:38 
AnswerRe: how to avoid window swing when it zoom out from center point Pin
Rozis13-Aug-10 11:09
Rozis13-Aug-10 11:09 
AnswerRe: how to avoid window swing when it zoom out from center point Pin
onlywjh17-Aug-10 20:58
onlywjh17-Aug-10 20:58 
AnswerRe: how to avoid window swing when it zoom out from center point Pin
onlywjh17-Aug-10 21:08
onlywjh17-Aug-10 21:08 
QuestionRotated text using Drawtext Pin
Mary Chennai11-Aug-10 8:15
Mary Chennai11-Aug-10 8:15 
AnswerRe: Rotated text using Drawtext Pin
Chris Losinger11-Aug-10 8:19
professionalChris Losinger11-Aug-10 8:19 
GeneralRe: Rotated text using Drawtext Pin
Mary Chennai11-Aug-10 8:38
Mary Chennai11-Aug-10 8:38 
GeneralRe: Rotated text using Drawtext Pin
Luc Pattyn11-Aug-10 8:48
sitebuilderLuc Pattyn11-Aug-10 8:48 
GeneralRe: Rotated text using Drawtext Pin
Maximilien11-Aug-10 9:00
Maximilien11-Aug-10 9:00 
GeneralRe: Rotated text using Drawtext Pin
CPallini11-Aug-10 22:20
mveCPallini11-Aug-10 22:20 
QuestionReading chunks of Data Pin
AbhiHcl11-Aug-10 3:05
AbhiHcl11-Aug-10 3:05 
AnswerRe: Reading chunks of Data Pin
CPallini11-Aug-10 3:27
mveCPallini11-Aug-10 3:27 
AnswerRe: Reading chunks of Data Pin
elchupathingy11-Aug-10 3:34
elchupathingy11-Aug-10 3:34 
GeneralRe: Reading chunks of Data Pin
AbhiHcl11-Aug-10 3:42
AbhiHcl11-Aug-10 3:42 
GeneralRe: Reading chunks of Data Pin
Cool_Dev11-Aug-10 4:47
Cool_Dev11-Aug-10 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.