コード例 #1
0
ファイル: SkinButton.cpp プロジェクト: mikesimb/SkinDemo2
void CSkinButton::OnPaint() 
{
	if ( !m_res || !m_res->m_bInited )
	{
		Default();
		return;
	}
	//Note:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	// to draw button, cliprgn is needed
	//
	CPaintDC dc(this); // device context for painting
	CRect r;
	CMyBitmap bmp;
	GetClientRect(r);
	DrawImage(bmp);
	SetWindowRgn(bmp.CreateRgnFromFile(RGB(255,0,255)), TRUE );

	
	HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
	GetWindowRgn(hRgn);				
	::SelectClipRgn(dc.GetSafeHdc(), hRgn);
	bmp.Draw( &dc, r );	
	dc.SelectClipRgn(NULL);
	DeleteObject(hRgn);
	
	//dc.BitBlt( 0, 0, r.Width(), r.Height(), &memDC, 0, 0, SRCCOPY);
	DrawText( &dc );

	// TODO: Add your message handler code here
	// Do not call CButton::OnPaint() for painting messages
}
コード例 #2
0
HRGN CSkinWin::GetRegion(int w, int h)
{
    CWnd *pWnd = CWnd::FromHandle(m_hWnd);
    CRect wr;
    pWnd->GetWindowRect(wr);
	//SKIN_SHANG 右边框
	//wr.left+=m_BorderRightWidth;
    
    CRgn rgn;
    if ( m_bTrans )
    {
        CDC *pDC = pWnd->GetDC();
        CDC memDC;
        CMyBitmap bmp;
        CBitmap *obmp;
        memDC.CreateCompatibleDC(pDC);
        bmp.CreateCompatibleBitmap( pDC, w, m_TitleHeight );
        obmp = memDC.SelectObject(&bmp);
        /*
        memDC.FillSolidRect( 0, 0, w, h, 0 );
        DrawFrame( &memDC, 0, 0, w, h, 0 );
        */
        DrawTitle( &memDC, m_BorderLeftWidth , 0, 
                   wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, 0 );
        DrawLeft( &memDC, 0, 0, m_bmpLeft.Height(), 0 );
		//SKIN_SHANG 右边框
        DrawRight( &memDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), 0 );
        
        memDC.SelectObject(obmp);

		//wyw
		memDC.DeleteDC();

        pWnd->ReleaseDC( pDC );

        rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
        HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans );
        CRgn newrgn;
        newrgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
        newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR  );

		//wyw
		bmp.DeleteObject();
		DeleteObject(hrgn);
		rgn.DeleteObject();
        
        return (HRGN)newrgn.Detach();
    }
    else
        rgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height() );
        
    
    return (HRGN)rgn.Detach();
}
コード例 #3
0
void CSkinWin::OnNcPaint(HRGN rgn1)
{  
    CWnd *pWnd = CWnd::FromHandle(m_hWnd);
    CDC * pDC = pWnd->GetWindowDC();
    CRect wr;
    pWnd->GetWindowRect( wr );
    //SKIN_SHANG 右边框
	//wr.left+=m_BorderRightWidth;

    DWORD style = GetWindowLong( m_hWnd, GWL_STYLE );
    DWORD nCaption = style & WS_CAPTION ;
    if (nCaption == 0)
	{
		//wyw
		pWnd->ReleaseDC(pDC);

        return;
    }

//f ( (DWORD)rgn) 
//pDC->SelectClipRgn( CRgn::FromHandle(rgn) );

    //m_bActive = GetActiveWindow() == m_hWnd;
    int state = 0;
    if ( m_bActive)
        state = 0;
    else 
		state = 1;
    
    pDC->ExcludeClipRect(0, 0, wr.Width(), m_TitleHeight );
    DrawFrame(pDC, 0, 0, wr.Width(), wr.Height(), state, 0);    
    pDC->SelectClipRgn( NULL ); 

    CDC memDC, *pNewDC;
    CMyBitmap bmp;
    CBitmap  *obmp;
    memDC.CreateCompatibleDC( pDC );
    bmp.CreateCompatibleBitmap( pDC, wr.Width(), m_TitleHeight );
    obmp = memDC.SelectObject(&bmp);
    pNewDC = &memDC;
    
    DrawTitle( pNewDC, m_BorderLeftWidth , 0, 
               wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, state );
    DrawLeft( pNewDC, 0, 0, m_bmpLeft.Height(), state );
	//SKIN_SHANG 右边框
    DrawRight( pNewDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), state );
    
    CRgn newrgn;
    newrgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height());

    if ( m_bTrans )
	{
		CRgn rgn;
		rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
		
 		HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans );
//wyw 防止内存增大 		
//		newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR);

 		pDC->SelectClipRgn( &newrgn ); 
 		
 		//wyw
 		DeleteObject(hrgn);
		rgn.DeleteObject();
	}
	else
		SetWindowRgn(m_hWnd, newrgn, FALSE);

    if (m_sysmenu){
		if( m_downHitTest == HTCLOSE )
			DrawButton( pNewDC, 0, 1 );
		else if ( m_moveHitTest == HTCLOSE)
			DrawButton( pNewDC, 0, 2 );
		else
			DrawButton( pNewDC, 0, 0 );
	}
	/*if ( m_downHitTest == HTMAXBUTTON )
        DrawButton( pNewDC, 1, 1 );
    else if ( m_moveHitTest == HTMAXBUTTON)
        DrawButton( pNewDC, 1, 2 );
    else
        DrawButton( pNewDC, 1, 0 );  

    if ( m_downHitTest == HTMINBUTTON )
        DrawButton( pNewDC, 2, 1 );
    else if ( m_moveHitTest == HTMINBUTTON)
        DrawButton( pNewDC, 2, 2 );
    else
        DrawButton( pNewDC, 2, 0 ); // liub_modify 去除弹出面板(去掉按钮)
   if ( m_downHitTest == HTMINBUTTON )
        DrawButton( pNewDC, 2, 1 );
    else if ( m_moveHitTest == HTMINBUTTON)
        DrawButton( pNewDC, 2, 2 );
    else
        DrawButton( pNewDC, 2, 0 );    */
	if ( m_downHitTest == HTMINBUTTON )
        DrawButton( pNewDC, 1, 1 );
    else if ( m_moveHitTest == HTMINBUTTON)
        DrawButton( pNewDC, 1, 2 );
    else
        DrawButton( pNewDC, 1, 0 ); 

          

    int cx = GetSystemMetrics(SM_CXSMICON);
    int cy = GetSystemMetrics(SM_CYSMICON);
    HICON hi = (HICON)SendMessage( m_hWnd, WM_GETICON, ICON_SMALL, 0);
    if ( !hi )
    {
//#ifdef IDR_MAINFRAME
        hi = AfxGetApp()->LoadIcon(g_SetData.Main_szMainIcon);
//#endif
    }
    //draw icon
//     ::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, (HICON)
//         CopyImage( hi, IMAGE_ICON, 
//         cx, cy, 0), cx, cy, 0, 0, DI_NORMAL);

#if 0 //wyw
	//draw icon
	::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, (HICON)
		CopyImage( hi, IMAGE_ICON, cx, cy, 0), cx, cy, 0, 0, DI_NORMAL);
#else
	if (NULL != hi) {
		HICON hIcon = (HICON)CopyImage( hi, IMAGE_ICON, cx, cy, 0);
		ASSERT(NULL != hIcon);
		::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, hIcon, cx, cy, 0, 0, DI_NORMAL);
		DestroyIcon(hIcon);
	}
#endif

    //draw text
    if ( m_title.IsEmpty() )
        pWnd->GetWindowText(m_title);

    if (m_bActive)
        pNewDC->SetTextColor( m_colTitle1 );
    else
        pNewDC->SetTextColor( m_colTitle2 );

    CFont font, *ofont;
    font.CreatePointFont( GetSystemMetrics(SM_CYSMCAPTION), _T("System") );
    ofont = pNewDC->SelectObject(&font);

    pNewDC->SetBkMode(TRANSPARENT);
    pNewDC->DrawText( m_title, CRect( m_textShift, m_textShiftVer, wr.Width() - m_bmpTitle.Width() + m_titleoff2, 
        m_TitleHeight ), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_WORD_ELLIPSIS  );

    pNewDC->SelectObject(&font);

    pDC->BitBlt( 0, 0, wr.Width(),
        m_TitleHeight, pNewDC, 0, 0, SRCCOPY );

    pDC->SelectClipRgn(NULL);

	//wyw
	memDC.SelectObject(obmp);

	#ifdef FEATURE_VERSION_ITELCO
		if(m_pHookedWnd == AfxGetMainWnd())
		{
			pWnd = CWnd::FromHandle(m_hWnd);
			pDC = pWnd->GetWindowDC();
			CRect rtWnd,rtTitle;
			pWnd->GetWindowRect(&rtWnd); 
			CRect m_rtIcon;
			rtTitle.left = GetSystemMetrics(SM_CXFRAME); 
			rtTitle.top = GetSystemMetrics(SM_CYFRAME); 
			//rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME); 
			rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE); 

			m_rtIcon.left = rtTitle.left + 350;  
			m_rtIcon.top = rtTitle.top - 1; 
			//m_rtIcon.right = m_rtIcon.left + 323;   //323
			//m_rtIcon.bottom = m_rtIcon.top + 20;    //25

			HICON hLogInfo;

			hLogInfo = (HICON)::LoadImage(NULL,
										  g_SetData.Main_szTitleLogoIcon, 
										  IMAGE_ICON,
										  248, 24, 
										  LR_LOADFROMFILE|LR_DEFAULTCOLOR);
			DWORD dword = GetLastError();

			//IDR_MAINFRAME  IDI_ICON_INFO
			BOOL BRes = ::DrawIconEx(pDC->m_hDC, m_rtIcon.left, m_rtIcon.top,
									 hLogInfo, 0,
									 0, 0, NULL, DI_NORMAL); 
			dword = GetLastError();

		}
	#endif

	//wyw
	font.DeleteObject();
	bmp.DeleteObject();
	newrgn.DeleteObject();
	memDC.DeleteDC();
	pWnd->ReleaseDC(pDC);
}