⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skinwindow.cpp

📁 著名的下载软件核心Shareaza
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		pRect->top		+= rcAdjust.top;
		pRect->right	-= rcAdjust.right;
		pRect->bottom	-= rcAdjust.bottom;
	}
	else
	{
		pRect->left		-= rcAdjust.left;
		pRect->top		-= rcAdjust.top;
		pRect->right	+= rcAdjust.right;
		pRect->bottom	+= rcAdjust.bottom;
	}
}

void CSkinWindow::OnNcCalcSize(CWnd* pWnd, BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
	CalcWindowRect( &lpncsp->rgrc[0], TRUE, pWnd->IsZoomed() );
}

void CSkinWindow::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
	CRect rcWork;
	SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
	rcWork.OffsetRect( -rcWork.left, -rcWork.top );
	
	CRect rcAdjusted( &rcWork );
	CalcWindowRect( &rcAdjusted, FALSE, TRUE );
	
	if ( m_rcMaximise.left < 0 )
		rcWork.left = rcAdjusted.left;
	else
		rcWork.left -= m_rcMaximise.left;
	
	if ( m_rcMaximise.top < 0 )
		rcWork.top = rcAdjusted.top;
	else
		rcWork.top -= m_rcMaximise.top;
	
	if ( m_rcMaximise.right < 0 )
		rcWork.right = rcAdjusted.right;
	else
		rcWork.right += m_rcMaximise.right;
	
	if ( m_rcMaximise.bottom < 0 )
		rcWork.bottom = rcAdjusted.bottom;
	else
		rcWork.bottom += m_rcMaximise.bottom;
	
	lpMMI->ptMaxPosition.x	= rcWork.left;
	lpMMI->ptMaxPosition.y	= rcWork.top;
	lpMMI->ptMaxSize.x		= rcWork.right;
	lpMMI->ptMaxSize.y		= rcWork.bottom;
	
	lpMMI->ptMinTrackSize.x	= max( lpMMI->ptMinTrackSize.x, m_szMinSize.cx );
	lpMMI->ptMinTrackSize.y	= max( lpMMI->ptMinTrackSize.y, m_szMinSize.cy );
}

UINT CSkinWindow::OnNcHitTest(CWnd* pWnd, CPoint point, BOOL bResizable)
{
	CRect rc, rcAnchor;

	pWnd->GetWindowRect( &rc );
	
	if ( m_bAnchor[ SKINANCHOR_SYSTEM ] )
	{
		ResolveAnchor( rc, rcAnchor, SKINANCHOR_SYSTEM );
		if ( rcAnchor.PtInRect( point ) ) return HTSYSMENU;
	}
	
	if ( m_bAnchor[ SKINANCHOR_MINIMISE ] )
	{
		ResolveAnchor( rc, rcAnchor, SKINANCHOR_MINIMISE );
		if ( rcAnchor.PtInRect( point ) ) return HTREDUCE;
	}
	
	if ( m_bAnchor[ SKINANCHOR_MAXIMISE ] )
	{
		ResolveAnchor( rc, rcAnchor, SKINANCHOR_MAXIMISE );
		if ( rcAnchor.PtInRect( point ) ) return HTZOOM;
	}
	
	if ( m_bAnchor[ SKINANCHOR_CLOSE ] )
	{
		ResolveAnchor( rc, rcAnchor, SKINANCHOR_CLOSE );
		if ( rcAnchor.PtInRect( point ) ) return HTCLOSE;
	}
	
	if ( bResizable && ! pWnd->IsZoomed() )
	{
		if ( point.x >= rc.right - SIZEBOX_WIDTH && point.y >= rc.bottom - SIZEBOX_WIDTH )
			return HTBOTTOMRIGHT;
		
		if ( point.x < rc.left + m_rcResize.left )
		{
			if ( point.y < rc.top + m_rcResize.top ) return HTTOPLEFT;
			else if ( point.y >= rc.bottom - m_rcResize.bottom ) return HTBOTTOMLEFT;
			else return HTLEFT;
		}
		else if ( point.x >= rc.right - m_rcResize.right )
		{
			if ( point.y < rc.top + m_rcResize.top ) return HTTOPRIGHT;
			else if ( point.y >= rc.bottom - m_rcResize.bottom ) return HTBOTTOMRIGHT;
			else return HTRIGHT;
		}
		else if ( point.y < rc.top + m_rcResize.top )
		{
			if ( point.x < rc.left + m_rcResize.left ) return HTTOPLEFT;
			else if ( point.x >= rc.right - m_rcResize.right ) return HTTOPRIGHT;
			return HTTOP;
		}
		else if ( point.y >= rc.bottom - m_rcResize.bottom )
		{
			if ( point.x < rc.left + m_rcResize.left ) return HTBOTTOMLEFT;
			else if ( point.x >= rc.right - m_rcResize.right ) return HTBOTTOMRIGHT;
			return HTBOTTOM;
		}
	}
	
	OnNcCalcSize( pWnd, FALSE, (NCCALCSIZE_PARAMS*)&rc );
	
	if ( point.y < rc.top ) return HTCAPTION;
	
	return rc.PtInRect( point ) ? HTCLIENT : HTBORDER;
}

void CSkinWindow::OnNcPaint(CWnd* pWnd)
{
	CWindowDC dc( pWnd );
	Paint( pWnd, dc, FALSE );
}

BOOL CSkinWindow::OnNcActivate(CWnd* pWnd, BOOL bActive)
{
	CWindowDC dc( pWnd );
	Paint( pWnd, dc, TRUE, bActive ? TS_TRUE : TS_FALSE );
	return FALSE;
}

void CSkinWindow::OnSetText(CWnd* pWnd)
{
	CWindowDC dc( pWnd );
	Paint( pWnd, dc, TRUE );
}

void CSkinWindow::OnSize(CWnd* pWnd)
{
	if ( pWnd->IsIconic() ) return;
	
	if ( pWnd->IsZoomed() )
	{
		pWnd->SetWindowRgn( NULL, TRUE );
	}
	else if ( m_pRegionXML )
	{
		SelectRegion( pWnd );
	}
	else if ( CoolInterface.IsNewWindows() )
	{
		CRect rcWnd;
		
		pWnd->GetWindowRect( &rcWnd );
		rcWnd.OffsetRect( -rcWnd.left, -rcWnd.top );
		rcWnd.right++; rcWnd.bottom++;
		
		HRGN hRgn = CreateRectRgnIndirect( &rcWnd );
		pWnd->SetWindowRgn( hRgn, TRUE );
	}
}

BOOL CSkinWindow::OnEraseBkgnd(CWnd* pWnd, CDC* pDC)
{
	if ( m_bmWatermark.m_hObject == NULL ) return FALSE;
	
	if ( ! m_dcSkin.m_hDC ) m_dcSkin.CreateCompatibleDC( pDC );
	CBitmap* pOldImage = (CBitmap*)m_dcSkin.SelectObject( &m_bmWatermark );
	
	BITMAP pWatermark;
	CRect rc;
	
	pWnd->GetClientRect( &rc );
	m_bmWatermark.GetBitmap( &pWatermark );
	
	for ( int nY = rc.top ; nY < rc.bottom ; nY += pWatermark.bmHeight )
	{
		for ( int nX = rc.left ; nX < rc.right ; nX += pWatermark.bmWidth )
		{
			pDC->BitBlt( nX, nY, pWatermark.bmWidth, pWatermark.bmHeight, &m_dcSkin, 0, 0, SRCCOPY );
		}
	}
	
	m_dcSkin.SelectObject( pOldImage );
	return TRUE;
}

void CSkinWindow::OnNcMouseMove(CWnd* pWnd, UINT nHitTest, CPoint point)
{
	int nAnchor = 0;
	if ( nHitTest == HTSYSMENU ) nAnchor = SKINANCHOR_SYSTEM;
	else if ( nHitTest == HTREDUCE ) nAnchor = SKINANCHOR_MINIMISE;
	else if ( nHitTest == HTZOOM ) nAnchor = SKINANCHOR_MAXIMISE;
	else if ( nHitTest == HTCLOSE ) nAnchor = SKINANCHOR_CLOSE;

	if ( m_nDownAnchor && m_nDownAnchor != nAnchor )
	{
		if ( ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) == 0 )
			m_nDownAnchor = 0;
		nAnchor = 0;
	}

	if ( nAnchor != m_nHoverAnchor )
	{
		m_nHoverAnchor = nAnchor;
		CWindowDC dc( pWnd );
		Paint( pWnd, dc, TRUE );
	}	
}

BOOL CSkinWindow::OnNcLButtonDown(CWnd* pWnd, UINT nHitTest, CPoint point)
{
	int nAnchor = 0;
	if ( nHitTest == HTSYSMENU ) nAnchor = SKINANCHOR_SYSTEM;
	else if ( nHitTest == HTREDUCE ) nAnchor = SKINANCHOR_MINIMISE;
	else if ( nHitTest == HTZOOM ) nAnchor = SKINANCHOR_MAXIMISE;
	else if ( nHitTest == HTCLOSE ) nAnchor = SKINANCHOR_CLOSE;
	else return FALSE;

	m_nHoverAnchor = m_nDownAnchor = nAnchor;

	if ( nAnchor == SKINANCHOR_SYSTEM )
	{
		CRect rcWindow, rcSystem;

		pWnd->GetWindowRect( &rcWindow );
		ResolveAnchor( rcWindow, rcSystem, SKINANCHOR_SYSTEM );
		CMenu* pPopup = pWnd->GetSystemMenu( FALSE );

		CWindowDC dc( pWnd );
		Paint( pWnd, dc, TRUE );

		DWORD nTime = GetTickCount();

		UINT nCmdID = pPopup->TrackPopupMenu( TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD,
			rcSystem.left, rcSystem.bottom, pWnd, NULL );

		m_nHoverAnchor = m_nDownAnchor = 0;

		if ( nCmdID )
		{
			pWnd->PostMessage( WM_SYSCOMMAND, nCmdID, MAKELONG( rcSystem.left, rcSystem.bottom ) );
		}
		else if ( GetTickCount() - nTime < 300 )
		{
			GetCursorPos( &point );
			if ( OnNcHitTest( pWnd, point, FALSE ) == HTSYSMENU )
			{
				pWnd->PostMessage( WM_SYSCOMMAND, SC_CLOSE, MAKELONG( rcSystem.left, rcSystem.bottom ) );
			}
		}
	}

	CWindowDC dc( pWnd );
	Paint( pWnd, dc, TRUE );

	return TRUE;
}

BOOL CSkinWindow::OnNcLButtonUp(CWnd* pWnd, UINT nHitTest, CPoint point)
{
	if ( ! m_nDownAnchor ) return FALSE;

	if ( m_nDownAnchor == m_nHoverAnchor )
	{
		switch ( m_nDownAnchor )
		{
		case SKINANCHOR_MINIMISE:
			pWnd->PostMessage( WM_SYSCOMMAND, SC_MINIMIZE );
			break;
		case SKINANCHOR_MAXIMISE:
			pWnd->PostMessage( WM_SYSCOMMAND, pWnd->IsZoomed() ? SC_RESTORE : SC_MAXIMIZE );
			break;
		case SKINANCHOR_CLOSE:
			pWnd->PostMessage( WM_SYSCOMMAND, SC_CLOSE );
			break;
		}
	}

	m_nHoverAnchor = 0;
	m_nDownAnchor = 0;
	
	CWindowDC dc( pWnd );
	Paint( pWnd, dc, TRUE );

	return FALSE;
}

BOOL CSkinWindow::OnNcLButtonDblClk(CWnd* pWnd, UINT nHitTest, CPoint point)
{
	if ( nHitTest == HTSYSMENU )
	{
		pWnd->PostMessage( WM_SYSCOMMAND, SC_CLOSE );
		return TRUE;
	}

	return FALSE;
}

//////////////////////////////////////////////////////////////////////
// CSkinWindow paint

void CSkinWindow::Prepare(CDC* pDC)
{
	if ( m_dcSkin.m_hDC == NULL )
		m_dcSkin.CreateCompatibleDC( pDC );
	if ( m_hoSkin == NULL )
		m_hoSkin = (HBITMAP)m_dcSkin.SelectObject( &m_bmSkin )->GetSafeHandle();
}

void CSkinWindow::Paint(CWnd* pWnd, CDC& dc, BOOL bCaption, TRISTATE bActive)
{
	HICON hIcon = NULL;
	CString strCaption;
	CRect rc, rcItem;
	
	Prepare( &dc );
	
	pWnd->GetWindowRect( &rc );
	rc.OffsetRect( -rc.left, -rc.top );
	
	if ( bActive == TS_UNKNOWN )
	{
		if ( pWnd->IsKindOf( RUNTIME_CLASS(CMDIChildWnd) ) )
		{
			CMDIFrameWnd* pFrame = ((CMDIChildWnd*)pWnd)->GetMDIFrame();
			bActive = pFrame->MDIGetActive() == pWnd ? TS_TRUE : TS_FALSE;
		}
		else
		{
			bActive = CWnd::GetForegroundWindow() == pWnd ? TS_TRUE : TS_FALSE;
		}
	}
	
	BOOL bZoomed = pWnd->IsZoomed();
	
	if ( m_bCaption )
	{
		pWnd->GetWindowText( strCaption );
		if ( m_bCaptionCaps ) strCaption.MakeUpper();
	}
	
	if ( m_bAnchor[ SKINANCHOR_ICON ] )
	{
		hIcon = pWnd->GetIcon( FALSE );
		if ( hIcon == NULL ) hIcon = pWnd->GetIcon( TRUE );
	}
	
	int nCaptionHeight = 0;
	
	if ( m_bPart[ SKINPART_TOP_LEFT ] ) nCaptionHeight = max( nCaptionHeight, m_rcPart[ SKINPART_TOP_LEFT ].Height() );
	if ( m_bPart[ SKINPART_TOP ] ) nCaptionHeight = max( nCaptionHeight, m_rcPart[ SKINPART_TOP ].Height() );
	if ( m_bPart[ SKINPART_TOP_RIGHT ] ) nCaptionHeight = max( nCaptionHeight, m_rcPart[ SKINPART_TOP_RIGHT ].Height() );
	CDC* pDC = CoolInterface.GetBuffer( dc, CSize( rc.Width(), nCaptionHeight ) );
	
	for ( int nAnchor = SKINANCHOR_SYSTEM ; nAnchor <= SKINANCHOR_CLOSE ; nAnchor++ )
	{
		if ( m_bAnchor[ nAnchor ] )
		{
			int nPart = ( nAnchor - SKINANCHOR_SYSTEM ) * 3 + SKINPART_SYSTEM;
			
			if ( m_nHoverAnchor == nAnchor )
				nPart += ( m_nDownAnchor == nAnchor ? 2 : 1 );
			else
				nPart += ( m_nDownAnchor == nAnchor ? 0 : 0 );
			
			if ( m_bPart[ nPart ] )
			{
				ResolveAnchor( rc, rcItem, nAnchor );
				
				pDC->BitBlt( rcItem.left, rcItem.top,
					m_rcPart[ nPart ].Width(), m_rcPart[ nPart ].Height(), &m_dcSkin,
					m_rcPart[ nPart ].left, m_rcPart[ nPart ].top, SRCCOPY );
				pDC->ExcludeClipRect( rcItem.left, rcItem.top,
					rcItem.left + m_rcPart[ nPart ].Width(),
					rcItem.top + m_rcPart[ nPart ].Height() );
			}
		}
	}
	
	CRect rcLeft( &rc ), rcTop( &rc ), rcRight( &rc ), rcBottom( &rc );
	
	if ( bActive == TS_FALSE && m_bPart[ SKINPART_IA_TOP_LEFT ] )
	{
		pDC->BitBlt( 0, 0, m_rcPart[ SKINPART_IA_TOP_LEFT ].Width(),
			m_rcPart[ SKINPART_IA_TOP_LEFT ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_IA_TOP_LEFT ].left,
			m_rcPart[ SKINPART_IA_TOP_LEFT ].top, SRCCOPY );
		rcLeft.top += m_rcPart[ SKINPART_IA_TOP_LEFT ].Height();
		rcTop.left += m_rcPart[ SKINPART_IA_TOP_LEFT ].Width();
	}
	else if ( m_bPart[ SKINPART_TOP_LEFT ] )
	{
		pDC->BitBlt( 0, 0, m_rcPart[ SKINPART_TOP_LEFT ].Width(),
			m_rcPart[ SKINPART_TOP_LEFT ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_TOP_LEFT ].left,
			m_rcPart[ SKINPART_TOP_LEFT ].top, SRCCOPY );
		rcLeft.top += m_rcPart[ SKINPART_TOP_LEFT ].Height();
		rcTop.left += m_rcPart[ SKINPART_TOP_LEFT ].Width();
	}
	
	if ( bActive == TS_FALSE && m_bPart[ SKINPART_IA_TOP_RIGHT ] )
	{
		pDC->BitBlt( rc.Width() - m_rcPart[ SKINPART_IA_TOP_RIGHT ].Width(), 0,
			m_rcPart[ SKINPART_IA_TOP_RIGHT ].Width(),
			m_rcPart[ SKINPART_IA_TOP_RIGHT ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_IA_TOP_RIGHT ].left,
			m_rcPart[ SKINPART_IA_TOP_RIGHT ].top, SRCCOPY );
		rcTop.right -= m_rcPart[ SKINPART_IA_TOP_RIGHT ].Width();
		rcRight.top += m_rcPart[ SKINPART_IA_TOP_RIGHT ].Height();
	}
	else if ( m_bPart[ SKINPART_TOP_RIGHT ] )
	{
		pDC->BitBlt( rc.Width() - m_rcPart[ SKINPART_TOP_RIGHT ].Width(), 0,
			m_rcPart[ SKINPART_TOP_RIGHT ].Width(),
			m_rcPart[ SKINPART_TOP_RIGHT ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_TOP_RIGHT ].left,
			m_rcPart[ SKINPART_TOP_RIGHT ].top, SRCCOPY );
		rcTop.right -= m_rcPart[ SKINPART_TOP_RIGHT ].Width();
		rcRight.top += m_rcPart[ SKINPART_TOP_RIGHT ].Height();
	}
	
	if ( m_bPart[ SKINPART_BOTTOM_LEFT ] && ! bCaption )
	{
		dc.BitBlt( 0, rc.Height() - m_rcPart[ SKINPART_BOTTOM_LEFT ].Height(),
			m_rcPart[ SKINPART_BOTTOM_LEFT ].Width(),
			m_rcPart[ SKINPART_BOTTOM_LEFT ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_BOTTOM_LEFT ].left,
			m_rcPart[ SKINPART_BOTTOM_LEFT ].top, SRCCOPY );
		rcBottom.left += m_rcPart[ SKINPART_BOTTOM_LEFT ].Width();
		rcLeft.bottom -= m_rcPart[ SKINPART_BOTTOM_LEFT ].Height();
	}
	
	if ( m_bPart[ SKINPART_BOTTOM_RIGHT ] && ! bCaption )
	{
		dc.BitBlt( rc.Width() - m_rcPart[ SKINPART_BOTTOM_RIGHT ].Width(),
			rc.Height() - m_rcPart[ SKINPART_BOTTOM_RIGHT ].Height(),
			m_rcPart[ SKINPART_BOTTOM_RIGHT ].Width(),
			m_rcPart[ SKINPART_BOTTOM_RIGHT ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_BOTTOM_RIGHT ].left,
			m_rcPart[ SKINPART_BOTTOM_RIGHT ].top, SRCCOPY );
		rcRight.bottom -= m_rcPart[ SKINPART_BOTTOM_RIGHT ].Height();
		rcBottom.right -= m_rcPart[ SKINPART_BOTTOM_RIGHT ].Width();
	}
	
	if ( m_bPart[ SKINPART_LEFT_TOP ] && ! bCaption )
	{
		dc.BitBlt( 0, rcLeft.top, m_rcPart[ SKINPART_LEFT_TOP ].Width(),
			m_rcPart[ SKINPART_LEFT_TOP ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_LEFT_TOP ].left,
			m_rcPart[ SKINPART_LEFT_TOP ].top, SRCCOPY );
		rcLeft.top += m_rcPart[ SKINPART_LEFT_TOP ].Height();
	}
	
	if ( m_bPart[ SKINPART_LEFT_BOTTOM ] && ! bCaption )
	{
		dc.BitBlt( 0, rcLeft.bottom - m_rcPart[ SKINPART_LEFT_BOTTOM ].Height(),
			m_rcPart[ SKINPART_LEFT_BOTTOM ].Width(),
			m_rcPart[ SKINPART_LEFT_BOTTOM ].Height(), &m_dcSkin,
			m_rcPart[ SKINPART_LEFT_BOTTOM ].left,
			m_rcPart[ SKINPART_LEFT_BOTTOM ].top, SRCCOPY );
		rcLeft.bottom -= m_rcPart[ SKINPART_LEFT_BOTTOM ].Height();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -