WTL自绘界面库(CQsButton)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                WTL自绘界面库(CQsButton)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                概述:
 Buton 按鈕對于大家并不陌生,本文章主要是實現基于Wtl CButton 的基礎上來,實現重繪,主要是通過 DrawItem( LPDRAWITEMSTRUCT lpdis )來實現重繪,與通常的控件繪制是一樣的,先繪制背景、然后繪制控件,最后提交。
CQsButton 詳細代碼實現:
#pragma once;#include "QsInclude.h" #include "UserMessage.h"#define BS_BTNTESTTOP 0x00000001 //表示Button標題在下方 #define BS_BTNTESTBOTTOM 0x00000002 //表示Button標題在上方 #define BS_BTNTESTCENTER 0x00000004 //表示Button標題在中間/* CQsButton class */ class CQsButton :public CImageMgrCtrlBase< CQsButton>,public CWindowImpl<CQsButton, CButton>,public COwnerDraw< CQsButton > {typedef CWindowImpl< CQsButton, CButton > theBaseClass;typedef CImageMgrCtrlBase< CQsButton> theImageCtrlBaseClass;private:volatile UINT m_uCurState; //當前按鈕狀態volatile bool m_bMouseDown; //鼠標左鍵按下BOOL m_bTransBKGnd; //是否使用透明背景volatile bool m_bMouseTrack; //鼠標是否進入DWORD dwtxtStyle; //Button 標題在Button中顯示樣式CMenuHandle m_mnPopMenu; //right mouse button pop menuCWindow m_wndMenuNotify; //pop up menu notify windowint m_npost; //字體離Button中線的距離Image* m_pImageForegrd; //前景圖片CRect m_foregrdrect; //前景圖片顯示的區域BOOL m_bunifycolr; //是否統一到Normal一種狀態下的顏色BOOL m_bunifyfont; //是否統一到Normal一種狀態下的顏色BOOL m_bflagBK;CRect m_RectText; //字顯示區域public:DECLARE_WND_SUPERCLASS(TEXT("QSBUTTON"), CButton::GetWndClassName())BEGIN_MSG_MAP( CQsButton )MESSAGE_HANDLER( WM_ERASEBKGND, OnEraseBKGnd )MESSAGE_HANDLER( WM_LBUTTONDOWN, OnLButtonDown )MESSAGE_HANDLER( WM_LBUTTONUP, OnLButtonUp )MESSAGE_HANDLER( WM_RBUTTONUP, OnRButtonUp )MESSAGE_HANDLER( WM_MOUSELEAVE, OnMouseLeave )MESSAGE_HANDLER( WM_MOUSEMOVE, OnMouseMove )CHAIN_MSG_MAP_ALT( COwnerDraw< CQsButton >, 1 )CHAIN_MSG_MAP( theImageCtrlBaseClass )DEFAULT_REFLECTION_HANDLER()END_MSG_MAP()/*! \fn CQsButton()* \param N/A* \return no return* \brief CQsButton's default constructor.*/CQsButton():m_bMouseDown( false ),m_uCurState( CONTROL_BTN_NORMAL ),m_bTransBKGnd( FALSE ),m_bMouseTrack( TRUE ){m_uFirstPos = CONTROL_BTN_FIRST;m_uLastPos = CONTROL_BTN_LAST;m_pImageForegrd = NULL;m_bunifycolr = FALSE;m_bunifyfont = FALSE;m_bflagBK = TRUE;m_npost =0;m_RectText.left=0;m_RectText.top=0;m_RectText.right=0;m_RectText.bottom=0;}/***@method ~CQsButton*@brief QsButton類的構造函數* *@return */~CQsButton(){ClearForeGroundImage();}/***@method Create*@brief Use this function to subclass one window* *@param HWND hWndParent parent window*@param ATL::_U_RECT rect = NULL create window rect*@param LPCTSTR szWindowName = NULL the window name*@param DWORD dwStyle = 0 base window style*@param DWORD dwExStyle = 0 extended window style*@param ATL::_U_MENUorID MenuOrID = 0U menu or ID*@param LPVOID lpCreateParam = NULL create param*@return HWND BOOL success return TRUE, failed return FALSE*/HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,DWORD dwStyle = 0, DWORD dwExStyle = 0,ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL){return theBaseClass::Create( hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);}/***@method SetButTextRect*@brief 設置微調ButText的顯示區域* *@param CRect rect*@return void*/void SetButTextRect(CRect rect){m_RectText = rect;}/***@method SetBtnUnifycolr*@brief 設置各種狀態下使用一種字體顏色* *@param BOOL bunifycolr*@return void*/void SetBtnUnifycolr(BOOL bunifycolr){m_bunifycolr = bunifycolr;}/***@method SetBtnUnifFont*@brief 設置各種狀態下使用一種字體* *@return void*/void SetBtnUnifFont(BOOL bunifyfont){m_bunifyfont = bunifyfont;}/***@method SetBtnUnit*@brief 設置統一的* *@param BOOL bunifycolr*@param BOOL bunifyfont*@return void*/void SetBtnUnit(BOOL bunifycolr,BOOL bunifyfont){m_bunifycolr = bunifycolr;m_bunifyfont = bunifyfont;}/***@method SetBtnBK*@brief 是否繪制背景* *@param BOOL bFlagBk*@return void*/void SetBtnBK(BOOL bFlagBk){m_bflagBK = bFlagBk;}/***@method SetForegroudImage*@brief 設置前景圖片的和圖片的大小* *@param Image * pImge*@param CRect rect*@return void*/void SetForegroudImage(Image* pImge, CRect rect){if(pImge != NULL){ClearForeGroundImage();m_pImageForegrd = pImge->Clone();}m_foregrdrect = rect;}/***@method GetForegroudImage*@brief 得到前景圖片對象* *@return Image**/Image* GetForegroudImage(){return m_pImageForegrd;}/***@method ClearForeGroundImage*@brief 清除前景圖片 * *@param Image * pImge*@param CRect rect*@return void*/void ClearForeGroundImage(){if(m_pImageForegrd != NULL ){delete m_pImageForegrd;m_pImageForegrd = NULL;}}/***@method SetTextStyle*@brief 設置Button標題的顯示方式* *@param DWORD dwtxtStyle = BS_BTNTESTCENTER,默認值為中間顯示*@return void*/void SetTextStyle(DWORD dwtxtStyle = BS_BTNTESTCENTER){m_dwQsStyle = dwtxtStyle; }/***@method GetCustomState*@brief GetCustomState's default constructor.* *@param void*@return UINT current state of control*/UINT GetCustomState( void ){return m_uCurState;}/***@method DrawItem*@brief draw item.* *@param LPDRAWITEMSTRUCT lpdis lpdis draw item struct*@return void*/void DrawItem( LPDRAWITEMSTRUCT lpdis ){int width = lpdis->rcItem.right - lpdis->rcItem.left;int height = lpdis->rcItem.bottom - lpdis->rcItem.top;//創建內存作圖對象WTL::CDC memDC;memDC.CreateCompatibleDC( lpdis->hDC );WTL::CBitmap memBitmap;memBitmap.CreateCompatibleBitmap( lpdis->hDC, width, height );HBITMAP hOldBmp = memDC.SelectBitmap( memBitmap );//獲得控件背景memDC.SetBkMode( TRANSPARENT );::SendMessage( GetParent(), WM_DRAWBKGNDUI, ( WPARAM )memDC.m_hDC, ( LPARAM )lpdis->hwndItem );//繪制按鈕DrawButton( memDC.m_hDC, lpdis->rcItem );//提交圖像::BitBlt( lpdis->hDC, 0, 0, width, height, memDC.m_hDC, 0, 0, SRCCOPY );memDC.SelectBitmap( hOldBmp );}/***@method SubclassWindow*@brief Use this function to subclass one window* *@param HWND hWnd subclass binding window handle*@return BOOL BOOL success return TRUE, failed return FALSE*/BOOL SubclassWindow( HWND hWnd ){BOOL bRet = theBaseClass::SubclassWindow( hWnd );UINT nBS = GetButtonStyle();SetButtonStyle( nBS | BS_OWNERDRAW );return bRet;}/***@method ClearImage*@brief Clear the image of state* *@param UINT uState = 0xFFFFFFFF the state image to clear*@return void*/void ClearImage( UINT uState = 0xFFFFFFFF ){if( uState != 0xFFFFFFFF ){if( GetImage( uState ) ){CCtrlImageMgr::ClearImage( uState );Invalidate();}}else{CCtrlImageMgr::ClearImage( uState );Invalidate();}}/***@method SetTransBKGnd*@brief Set background transparent attitude* *@param BOOL bFlag Set the background transparent flag*@return void*/void SetTransBKGnd( BOOL bFlag ){m_bTransBKGnd = bFlag;}/***@method SetRClickPopMenu*@brief Set Right button click to popup menu, is both PopupMenu and Notify is valid, right click will popup menu,BESURE RELEASE menu when menu no longer use.* *@param CMenuHandle PopupMenu Context menu to popup, THIS PARAM IS ONLY A REFERENCE OF HANDLE*@param CWindow Notify Window menu command to notify*@return void*/void SetRClickPopMenu(CMenuHandle PopupMenu, CWindow Notify){ATLASSERT(PopupMenu.IsMenu());ATLASSERT(Notify.IsWindow());m_mnPopMenu = PopupMenu;m_wndMenuNotify = Notify;}/***@method SetWindowTextEx*@brief 設置Button顯示的標題* *@param LPCTSTR lpszString 標題字符串*@param int nPostion 字符離Button中心的垂直距離*@return void*/void SetWindowTextEx(LPCTSTR lpszString,int nPostion = 0){::SetWindowText(m_hWnd,lpszString);m_npost = nPostion;}protected:/***@method OnLButtonDown*@brief 鼠標左鍵被按下消息響應函數* *@param UINT uMsg 消息類型*@param WPARAM wParam*@param LPARAM lParam*@param BOOL& bHandled*@return LRESULT*/LRESULT OnLButtonDown( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled ){m_bMouseDown = true;Invalidate();bHandled = FALSE;return 0;}/***@method OnMouseMove*@brief 鼠標進入消息響應函數* *@param UINT uMsg 消息類型*@param WPARAM wParam*@param LPARAM lParam*@param BOOL& bHandled*@return LRESULT*/LRESULT OnMouseMove( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled ){if ( m_bMouseTrack ){// 向父窗口發送BN_MOUSEIN擴展通知消息HWND hParent = GetParent();if ( NULL != hParent ){WPARAM wParam = MAKELONG( ::GetWindowLong(m_hWnd, GWL_ID), BN_MOUSEIN );::PostMessage( hParent, WM_COMMANDEX, wParam, (LPARAM)m_hWnd );}}if( m_uCurState != CONTROL_BTN_MOUSEIN || m_bMouseTrack){Invalidate();// 啟動鼠標離開時間TRACKMOUSEEVENT tme;tme.cbSize = sizeof(tme);tme.hwndTrack = m_hWnd;tme.dwFlags = TME_LEAVE|TME_HOVER;TrackMouseEvent(&tme);m_bMouseTrack = FALSE;}bHandled = FALSE;return 0;}/***@method OnMouseLeave*@brief 鼠標離開消息響應函數* *@param UINT uMsg 消息類型*@param WPARAM wParam*@param LPARAM lParam*@param BOOL& bHandled*@return LRESULT*/LRESULT OnMouseLeave( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled ){if(!m_bMouseTrack){Invalidate();bHandled = FALSE;m_bMouseTrack = TRUE;// 向父窗口發送BN_MOUSEOUT擴展通知消息HWND hParent = GetParent();if ( NULL != hParent ){WPARAM wParam = MAKELONG( ::GetWindowLong(m_hWnd, GWL_ID), BN_MOUSEOUT );::PostMessage( hParent, WM_COMMANDEX, wParam, (LPARAM)m_hWnd );}}return 0;}/***@method OnLButtonUp*@brief 鼠標左鍵被放開消息響應函數* *@param UINT uMsg 消息類型*@param WPARAM wParam*@param LPARAM lParam*@param BOOL& bHandled*@return LRESULT*/LRESULT OnLButtonUp( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled ){m_bMouseDown = false;Invalidate();bHandled = FALSE;return 0;}/***@method OnRButtonUp*@brief 鼠標左鍵被放開消息響應函數* *@param UINT uMsg 消息類型*@param WPARAM wParam*@param LPARAM lParam*@param BOOL& bHandled*@return LRESULT*/LRESULT OnRButtonUp( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/ ){RECT rc; // client area of window POINT pt; // location of mouse click if (m_mnPopMenu.IsMenu() && m_wndMenuNotify.IsWindow()){// Convert the mouse position to client coordinates. GetCursorPos(&pt);::ScreenToClient(m_hWnd, &pt); ::GetClientRect(m_hWnd, &rc); // If the position is in the client area, display a // shortcut menu. if (PtInRect(&rc, pt)) { ::ClientToScreen(m_hWnd, &pt); m_mnPopMenu.TrackPopupMenuEx(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_wndMenuNotify.m_hWnd, NULL);return TRUE; } }return 0;}/***@method OnEraseBKGnd*@brief 背景繪制消息函數* *@param UINT uMsg 消息類型*@param WPARAM wParam*@param LPARAM lParam*@param BOOL& bHandled*@return LRESULT*/LRESULT OnEraseBKGnd( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/ ){//禁止繪制底色return 0;}private:/***@method GetButtonTextFormat*@brief 得到Button文字的對齊方式(用DrawText()輸出時的格式)* *@param const LONG lStyle 控件風格 *@return UINT 用DrawText()輸出時的格式 button上的字必須是一行 */UINT GetButtonTextFormat(const LONG lStyle){UINT uFormat = DT_SINGLELINE;//button上的字必須是一行//x方向if ( (lStyle & BS_CENTER)==BS_CENTER )//x方向,中uFormat |= DT_CENTER;else if ( (lStyle & BS_RIGHT)==BS_RIGHT )//x方向,右uFormat |= DT_RIGHT;else if ( (lStyle & BS_LEFT) == BS_LEFT )//x方向,左uFormat |= DT_LEFT|DT_END_ELLIPSIS;else//缺省,x中uFormat |= DT_CENTER;//y方向if ( (lStyle & BS_VCENTER ) == BS_VCENTER )//y,中uFormat |= DT_VCENTER;else if ( (lStyle & BS_TOP)==BS_TOP )//y方向,上uFormat |= DT_TOP;else if ( (lStyle & BS_BOTTOM)==BS_BOTTOM )//y方向,下uFormat |= DT_BOTTOM;else//缺省,y中uFormat |= DT_VCENTER;return uFormat;}/***@method DrawButton*@brief 繪制按鈕函數* *@param HDC hDC 作圖設備句柄*@param RECT itemRect 按鈕位置*@return void*/void DrawButton( HDC hDC, RECT itemRect ){HDC hdc = hDC;SetBkMode( hdc, TRANSPARENT );int width = itemRect.right - itemRect.left;int height = itemRect.bottom - itemRect.top;// UINT itemState = GetState();// LONG lStyle = GetWindowLong( GWL_STYLE );BOOL bIsDisabled = !IsWindowEnabled();//( ( lStyle & WS_DISABLED ) != 0 ); //是否被禁止BOOL bIsFocused = ( ::GetFocus() == m_hWnd );// BOOL bIsPressed = ( ( itemState & ODS_SELECTED ) == ODS_SELECTED );//判斷鼠標是否在按鈕上CRect rc;GetWindowRect( rc );//POINT pt;//GetCursorPos( &pt );//BOOL bMouseIn = rc.PtInRect( pt );POINT pt;GetCursorPos( &pt );BOOL bMouseIn =FALSE;HWND hwnd = WindowFromPoint(pt);if(hwnd==m_hWnd){bMouseIn = TRUE;}if(m_bflagBK==TRUE){DrawBkGnd( hdc, width, height, bIsDisabled, bMouseIn, bIsFocused );}DrawForeground( hdc, width, height, bIsDisabled, bMouseIn, bIsFocused );}protected:/***@method DrawBkGnd*@brief 繪制按鈕背景函數* *@param HDC hDC 作圖設備句柄*@param int cx 按鈕寬度*@param int cy 按鈕高度*@param BOOL bDisabled*@param BOOL bMoveIn*@param BOOL bFocused*@return void*/virtual void DrawBkGnd( HDC hDC, int cx, int cy, BOOL bDisabled, BOOL bMoveIn, BOOL bFocused ){UINT uState = CONTROL_BTN_NORMAL;//如果當前處于失效狀態if( bDisabled ){if( GetImage( CONTROL_BTN_DISABLED ) )uState = CONTROL_BTN_DISABLED;}else if( bMoveIn ) //如果當前鼠標在按鈕上{if( m_bMouseDown && GetImage( CONTROL_BTN_MOUSEDOWN ) ){uState = CONTROL_BTN_MOUSEDOWN;}else if( GetImage( CONTROL_BTN_MOUSEIN ) ){uState = CONTROL_BTN_MOUSEIN;}else{uState = m_uCurState;}}else if( bFocused ){if( GetImage( CONTROL_BTN_FOCUS ) ){uState = CONTROL_BTN_FOCUS;}}Image *pImage = GetImage( uState );//繪制圖片if( NULL != pImage ){Graphics graph( hDC );graph.SetPageScale( 1.0 );graph.SetPageUnit( UnitPixel ); graph.SetSmoothingMode( SmoothingModeNone );//graph.DrawImage( pImage, 0, 0, cx, cy );DrawImageEx( graph, pImage, RectF(0,0,(REAL)cx,(REAL)cy), RectF(0, 0, REAL(pImage->GetWidth()), REAL(pImage->GetHeight())), 5, 5 );graph.ReleaseHDC( hDC );}m_uCurState = uState;}/***@method DrawForeground*@brief 繪制按鈕前景函數* *@param HDC hDC 作圖設備句柄*@param int cx 按鈕寬度*@param int cy 按鈕高度*@param BOOL bDisabled*@param BOOL bMoveIn*@param BOOL bFocused*@return void*/virtual void DrawForeground( HDC hDC, int cx, int cy, BOOL bDisabled, BOOL bMoveIn, BOOL bFocused ){UINT uState = CONTROL_BTN_NORMAL;UINT uFontState = CONTROL_BTN_NORMAL;//如果當前處于失效狀態if( bDisabled ){if( GetCtrlIcon( CONTROL_BTN_DISABLED ) )uState = CONTROL_BTN_DISABLED;uFontState = CONTROL_BTN_DISABLED;}else if( bMoveIn ) //如果當前鼠標在按鈕上{if( m_bMouseDown ){if( GetCtrlIcon( CONTROL_BTN_MOUSEDOWN ) )uState = CONTROL_BTN_MOUSEDOWN;uFontState = CONTROL_BTN_MOUSEDOWN;}else{if( GetCtrlIcon( CONTROL_BTN_MOUSEIN ) )uState = CONTROL_BTN_MOUSEIN;uFontState = CONTROL_BTN_MOUSEIN;}}else if( bFocused ){if( GetCtrlIcon( CONTROL_BTN_FOCUS ) )uState = CONTROL_BTN_FOCUS;uFontState = CONTROL_BTN_FOCUS;}Image *pImage = GetCtrlIcon( uState );HFONT hFont = NULL; if(m_bunifyfont == TRUE) //統一使用一種字體Normal{hFont = GetStateFont( CONTROL_BTN_NORMAL );}else{hFont = GetStateFont( uFontState ); }//獲得當前按鈕文字CString strText;int len = GetWindowTextLength() + 1;GetWindowText( strText.GetBuffer( len ), len );strText.ReleaseBuffer();WTL::CDCHandle dc( hDC );HFONT hOldFont = dc.SelectFont( hFont );//計算文字長度 SIZE sSize;::GetTextExtentPoint32( dc.m_hDC, strText, strText.GetLength(), &sSize );CRect textRect;if(m_dwQsStyle&BS_BTNTESTTOP){textRect = CRect( 0, 0, cx, cy - cy/2 - m_npost);}else if(m_dwQsStyle & BS_BTNTESTBOTTOM){textRect = CRect( 0, cy - cy/2 + m_npost, cx, cy);}else{textRect = CRect( 0, 0, cx, cy);}Image* pFroegroud = GetForegroudImage();//繪制前景色if(NULL != pFroegroud) //不考慮字體顯示的前景圖片{Graphics graph( hDC );graph.SetPageScale( 1.0 );graph.SetPageUnit( UnitPixel ); graph.SetSmoothingMode( SmoothingModeNone );RectF rectf(m_foregrdrect.left,m_foregrdrect.top,m_foregrdrect.Width(),m_foregrdrect.Height());graph.DrawImage( pFroegroud,rectf);//DrawImageEx( graph, pImage, RectF(REAL(left), REAL(top), REAL(pImage->GetWidth()), REAL(pImage->GetHeight())), RectF(0, 0, REAL(pImage->GetWidth()), REAL(pImage->GetHeight())), 5, 5 );graph.ReleaseHDC( hDC );}//繪制圖標if( NULL != pImage ){int wth = sSize.cx;wth += ( pImage->GetWidth() + 1 );// int xtmp = cx - wth;int ytmp = cy - pImage->GetHeight();int left = 5;//( xtmp < 0 ? 0 : xtmp ) / 2;int top = ( ytmp < 0 ? 0 : ytmp ) / 2;Graphics graph( hDC );graph.SetPageScale( 1.0 );graph.SetPageUnit( UnitPixel ); graph.SetSmoothingMode( SmoothingModeNone );//graph.DrawImage( pImage, left, top );DrawImageEx( graph, pImage, RectF(REAL(left), REAL(top), REAL(pImage->GetWidth()), REAL(pImage->GetHeight())), RectF(0, 0, REAL(pImage->GetWidth()), REAL(pImage->GetHeight())), 5, 5 );graph.ReleaseHDC( hDC );textRect = CRect( left + pImage->GetWidth() + 5, 0, left + wth + 5, cy );}//繪制文字if( strText.GetLength() > 0 ){LONG lStyle = GetWindowLong( GWL_STYLE );if(m_bunifycolr == TRUE) //統一使用一種顏色Normal{dc.SetTextColor( GetFontColor( CONTROL_BTN_NORMAL ) );}else{dc.SetTextColor( GetFontColor( uFontState ) );}textRect.left = textRect.left+m_RectText.left;textRect.top = textRect.top+m_RectText.top;textRect.right = textRect.right+m_RectText.right;textRect.bottom = textRect.bottom+m_RectText.bottom;dc.DrawText( strText, -1, &textRect, GetButtonTextFormat( lStyle ) );}dc.SelectFont( hOldFont );::DeleteObject( hFont );}/***@method DrawImageEx*@brief * *@param Graphics& graph*@param Image *pImg*@param RectF rtfPanel*@param RectF rtfImage*@param REAL rWidth*@param REAL rHeight*@return void*/void DrawImageEx( Graphics& graph, Image *pImg, RectF rtfPanel, RectF rtfImage, REAL rWidth, REAL rHeight ){// 繪制左上角區域RectF rtfLeftUp( rtfPanel.X, rtfPanel.Y, rWidth, rHeight );graph.DrawImage( pImg, rtfLeftUp, rtfImage.X, rtfImage.Y, rWidth, rWidth, UnitPixel );// 繪制上邊欄區域RectF rtfMidUp( rtfPanel.X + rWidth, rtfPanel.Y, rtfPanel.Width - 2 * rWidth, rHeight );graph.DrawImage( pImg, rtfMidUp, rtfImage.X + rWidth,rtfImage.Y,rtfImage.Width - 2 * rWidth, rHeight, UnitPixel );// 繪制右上角區域RectF rtfRightUp( rtfPanel.X + rtfPanel.Width - rWidth, rtfPanel.Y, rWidth, rHeight );graph.DrawImage( pImg, rtfRightUp, rtfImage.X + rtfImage.Width - rWidth, rtfImage.Y, rWidth, rHeight, UnitPixel );// 繪制左邊區域RectF rtfLeftMid( rtfPanel.X, rtfPanel.Y + rHeight, rWidth, rtfPanel.Height - 2 * rHeight );graph.DrawImage( pImg, rtfLeftMid, rtfImage.X, rHeight, rWidth, rtfImage.Height - 2 * rHeight, UnitPixel );// 繪制中央區域RectF rtfMidMid( rtfPanel.X + rWidth, rtfPanel.Y + rHeight, rtfPanel.Width - 2 * rWidth, rtfPanel.Height - 2 * rHeight );graph.DrawImage( pImg, rtfMidMid, rtfImage.X + rWidth,rtfImage.Y + rHeight,rtfImage.Width - 2 * rWidth, rtfImage.Height - 2 * rHeight, UnitPixel );// 繪制右邊區域RectF rtfRightMid( rtfPanel.X + rtfPanel.Width - rWidth, rtfPanel.Y + rHeight, rWidth, rtfPanel.Height - 2 * rHeight );graph.DrawImage( pImg, rtfRightMid, rtfImage.X +rtfImage.Width - rWidth, rtfImage.Y + rHeight, rWidth, rtfImage.Height - 2 * rHeight, UnitPixel );// 繪制左下角區域RectF rtfLeftDown( rtfPanel.X, rtfPanel.Y + rtfPanel.Height - rHeight, rWidth, rHeight );graph.DrawImage( pImg, rtfLeftDown, rtfImage.X, rtfImage.Y + rtfImage.Height - rHeight, rWidth, rWidth, UnitPixel );// 繪制下邊欄區域RectF rtfMidDown( rtfPanel.X + rWidth, rtfPanel.Y + rtfPanel.Height - rHeight, rtfPanel.Width - 2 * rWidth, rHeight );graph.DrawImage( pImg, rtfMidDown, rtfImage.X + rWidth,rtfImage.Y + rtfImage.Height - rHeight,rtfImage.Width - 2 * rWidth, rHeight, UnitPixel );// 繪制右上角RectF rtfRightDown( rtfPanel.X + rtfPanel.Width - rWidth, rtfPanel.Y + rtfPanel.Height - rHeight, rWidth, rHeight );graph.DrawImage( pImg, rtfRightDown, rtfImage.X + rtfImage.Width - rWidth, rtfImage.Y + rtfImage.Height - rHeight, rWidth, rHeight, UnitPixel );}};總結
以上是生活随笔為你收集整理的WTL自绘界面库(CQsButton)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 因该如何搭建自己的网校系统呢?
- 下一篇: Crosswalk入门
