| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979 |
- // SkinComboBox.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "Control.h"
- #include "SkinComboBox.h"
- static WNDPROC m_pWndProc=0;
- extern "C" LRESULT FAR PASCAL ComboBoxListBoxProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
- {
- return CallWindowProc(m_pWndProc, hWnd, nMsg, wParam, lParam);
- }
- //////////////////////////////////////////////////////////////////////////
- BEGIN_MESSAGE_MAP(CSkinComboBox_Edit, CEdit)
- ON_WM_ERASEBKGND()
- ON_WM_MOUSEMOVE()
- ON_WM_MOUSELEAVE()
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- ON_WM_CTLCOLOR_REFLECT()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_SETCURSOR()
- ON_WM_LBUTTONUP()
- END_MESSAGE_MAP()
- CSkinComboBox_Edit::CSkinComboBox_Edit( void )
- {
- m_hOwnerWnd = NULL;
- m_bMouseTracking = FALSE;
- m_bIsDefText = FALSE;
- }
- CSkinComboBox_Edit::~CSkinComboBox_Edit( void )
- {
- }
- void CSkinComboBox_Edit::SetOwnerWnd( HWND hWnd )
- {
- m_hOwnerWnd = hWnd;
- }
- void CSkinComboBox_Edit::SetDefaultText( LPCTSTR lpszText )
- {
- m_strDefText = lpszText;
- }
- BOOL CSkinComboBox_Edit::IsDefaultText()
- {
- return m_bIsDefText;
- }
- void CSkinComboBox_Edit::SetDefaultTextMode( BOOL bIsDefText )
- {
- if (bIsDefText == m_bIsDefText)
- return;
- m_bIsDefText = bIsDefText;
- if (m_bIsDefText)
- {
- SetWindowText(m_strDefText);
- }
- else
- {
- SetWindowText(_T(""));
- }
- }
- BOOL CSkinComboBox_Edit::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- void CSkinComboBox_Edit::OnMouseMove(UINT nFlags, CPoint point)
- {
- if (!m_bMouseTracking)
- {
- m_bMouseTracking = TRUE;
- TrackMouseLeave(GetSafeHwnd());
- if (::IsWindow(m_hOwnerWnd))
- ::SendMessage(m_hOwnerWnd, WM_CBO_EDIT_MOUSE_HOVER, 0, 0);
- }
- __super::OnMouseMove(nFlags, point);
- }
- void CSkinComboBox_Edit::OnMouseLeave()
- {
- m_bMouseTracking = FALSE;
- if (::IsWindow(m_hOwnerWnd))
- ::SendMessage(m_hOwnerWnd, WM_CBO_EDIT_MOUSE_LEAVE, 0, 0);
- __super::OnMouseLeave();
- }
- void CSkinComboBox_Edit::OnSetFocus(CWnd* pOldWnd)
- {
- __super::OnSetFocus(pOldWnd);
- if (m_bIsDefText)
- {
- m_bIsDefText = FALSE;
- SetWindowText(TEXT(""));
- }
- //将焦点返回到原焦点
- if ( GetStyle() & ES_READONLY )
- {
- if( pOldWnd != NULL && pOldWnd->GetSafeHwnd() != NULL )
- pOldWnd->SetFocus();
- }
- }
- void CSkinComboBox_Edit::OnLButtonDown(UINT nFlags, CPoint point)
- {
- //将焦点返回到原焦点
- if ( GetStyle() & ES_READONLY )
- {
- if (::IsWindow(m_hOwnerWnd))
- ::SendMessage(m_hOwnerWnd, WM_LBUTTONDOWN,0,0);
- return;
- }
- __super::OnLButtonDown(nFlags, point);
- }
- void CSkinComboBox_Edit::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- //将焦点返回到原焦点
- if ( GetStyle() & ES_READONLY )
- {
- return;
- }
- __super::OnLButtonDblClk(nFlags, point);
- }
- LRESULT CSkinComboBox_Edit::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- //如果只读属性,且有选中消息则过滤掉
- if ( ( GetStyle() & ES_READONLY ) && (message == EM_SETSEL) )
- {
- return TRUE;
- }
- return __super::DefWindowProc(message, wParam, lParam);
- }
- BOOL CSkinComboBox_Edit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- //将焦点返回到原焦点
- if ( GetStyle() & ES_READONLY )
- {
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- return TRUE;
- }
- return __super::OnSetCursor(pWnd, nHitTest, message);
- }
- void CSkinComboBox_Edit::OnKillFocus(CWnd* pNewWnd)
- {
- __super::OnKillFocus(pNewWnd);
- if (GetWindowTextLength() <= 0 && !m_strDefText.IsEmpty())
- {
- m_bIsDefText = TRUE;
- SetWindowText(m_strDefText);
- }
- }
- HBRUSH CSkinComboBox_Edit::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
- {
- bool bIsReadOnly = ((GetStyle() & ES_READONLY) != 0) ? true : false;
-
- pDC->SetBkMode(TRANSPARENT);
- if (m_bIsDefText)
- {
- if( bIsReadOnly )
- pDC->SetTextColor(m_colReadOnlyText);
- else pDC->SetTextColor(m_colDefText);
- }
- else
- {
- if( bIsReadOnly )
- pDC->SetTextColor(m_colReadOnlyText);
- else pDC->SetTextColor(m_colNormalText);
- }
- if ( m_colBack == RGB(255,255,255) ) return (HBRUSH)NULL_BRUSH;
- //背景色
- HBRUSH hBr = CreateSolidBrush(m_colBack);
- return (HBRUSH) hBr;
- //return (HBRUSH)NULL_BRUSH;
- }
- //////////////////////////////////////////////////////////////////////////
- BEGIN_MESSAGE_MAP(CSkinComboBox_ListBox, CListBox)
- ON_WM_SHOWWINDOW()
- ON_WM_DESTROY()
- ON_WM_RBUTTONUP()
- END_MESSAGE_MAP()
- CSkinComboBox_ListBox::CSkinComboBox_ListBox( void )
- {
- m_hOwnerWnd = NULL;
- m_pBackImgN = NULL;
- m_pSelectImg = NULL;
- }
- CSkinComboBox_ListBox::~CSkinComboBox_ListBox( void )
- {
- }
- void CSkinComboBox_ListBox::SetOwnerWnd( HWND hWnd )
- {
- m_hOwnerWnd = hWnd;
- }
- void CSkinComboBox_ListBox::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CListBox::OnShowWindow(bShow, nStatus);
- if (!bShow)
- {
- ::SendMessage(m_hOwnerWnd, WM_CBO_LIST_HIDE, 0, 0);
- }
- }
- BOOL CSkinComboBox_ListBox::SetBackNormalImage( LPCTSTR lpszFileName, CONST LPRECT lpNinePart /*= NULL*/ )
- {
- RenderEngine->RemoveImage(m_pBackImgN);
- m_pBackImgN = RenderEngine->GetImage(lpszFileName);
- if (m_pBackImgN != NULL)
- m_pBackImgN->SetNinePart(lpNinePart);
- return (m_pBackImgN != NULL) ? TRUE : FALSE;
- }
- BOOL CSkinComboBox_ListBox::SetSelectImage( LPCTSTR lpszFileName, CONST LPRECT lpNinePart /*= NULL*/ )
- {
- RenderEngine->RemoveImage(m_pSelectImg);
- m_pSelectImg = RenderEngine->GetImage(lpszFileName);
- if (m_pSelectImg != NULL)
- m_pSelectImg->SetNinePart(lpNinePart);
- return (m_pSelectImg != NULL) ? TRUE : FALSE;
- }
- void CSkinComboBox_ListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- //变量定义
- CRect rcItem=lpDrawItemStruct->rcItem;
- CDC * pDCControl=CDC::FromHandle(lpDrawItemStruct->hDC);
- //创建缓冲
- CDC BufferDC;
- CBitmap ImageBuffer;
- BufferDC.CreateCompatibleDC(pDCControl);
- ImageBuffer.CreateCompatibleBitmap(pDCControl,rcItem.Width(),rcItem.Height());
-
- //设置环境
- BufferDC.SelectObject(&ImageBuffer);
- BufferDC.SelectObject(GetCtrlFont());
- //获取字符
- CString strString;
- GetText(lpDrawItemStruct->itemID,strString);
- //计算位置
- CRect rcString;
- rcString.SetRect(4,0,rcItem.Width()-8,rcItem.Height());
- //颜色定义
- COLORREF crTextColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?m_colSelectText:m_colNormalText;
- COLORREF crBackColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?RGB(10,36,106):RGB(255,255,255);
- //绘画背景
- BufferDC.FillSolidRect(0,0,rcItem.Width(),rcItem.Height(),crBackColor);
- if ( (lpDrawItemStruct->itemState&ODS_SELECTED) != 0 )
- {
- if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() )
- {
- rcItem.DeflateRect(1,1,1,1);
- m_pSelectImg->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height()));
- }
- }
- //绘画字符
- BufferDC.SetBkMode(TRANSPARENT);
- BufferDC.SetTextColor(crTextColor);
- BufferDC.DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE);
- //绘画界面
- pDCControl->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,0,0,SRCCOPY);
- //清理资源
- BufferDC.DeleteDC();
- ImageBuffer.DeleteObject();
- }
- void CSkinComboBox_ListBox::OnDestroy()
- {
- __super::OnDestroy();
- RenderEngine->RemoveImage(m_pBackImgN);
- RenderEngine->RemoveImage(m_pSelectImg);
- }
- void CSkinComboBox_ListBox::DrawListFrame()
- {
- CRect rcWindow;
- GetWindowRect(&rcWindow);
- rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top);
- CDC *pDC = GetWindowDC();
- if( pDC == NULL ) pDC = GetDC();
- RenderEngine->DrawRect(pDC->GetSafeHdc(),rcWindow,1,m_colFrameNormal);
- ReleaseDC(pDC);
- }
- void CSkinComboBox_ListBox::OnRButtonUp(UINT nFlags, CPoint point)
- {
- CRect rcItem(0,0,0,0);
- int nIndex = -1;
- for (int i =0; i<GetCount(); i++)
- {
- GetItemRect(i, &rcItem);
- if(rcItem.PtInRect(point))
- {
- if ( m_hOwnerWnd != NULL ) nIndex = i;
-
- break;
- }
- }
- ::PostMessage(m_hOwnerWnd,WM_CBO_LIST_RBUTTONUP,nIndex,0);
- __super::OnRButtonUp(nFlags, point);
- }
- //////////////////////////////////////////////////////////////////////////
- // CSkinComboBox
- IMPLEMENT_DYNAMIC(CSkinComboBox, CComboBox)
- CSkinComboBox::CSkinComboBox()
- {
- m_lpBgImgN = NULL;
- m_lpBgImgH = NULL;
- m_lpArrowImgN = NULL;
- m_lpArrowImgH = NULL;
- m_lpArrowImgP = NULL;
- m_bFocus = m_bPress = m_bHover = m_bMouseTracking = FALSE;
- m_bArrowPress = FALSE;
- m_bArrowHover = FALSE;
- m_nArrowWidth = 17;
- m_rcArrow.SetRectEmpty();
- m_cyItemHeight = 15;
- m_nEditHeight = 20;
- }
- CSkinComboBox::~CSkinComboBox()
- {
- }
- BEGIN_MESSAGE_MAP(CSkinComboBox, CComboBox)
- ON_WM_CREATE()
- ON_WM_ERASEBKGND()
- ON_WM_PAINT()
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_MOUSELEAVE()
- ON_WM_DESTROY()
- ON_WM_SIZE()
- ON_MESSAGE(WM_CBO_EDIT_MOUSE_HOVER, OnEditMouseHover)
- ON_MESSAGE(WM_CBO_EDIT_MOUSE_LEAVE, OnEditMouseLeave)
- ON_MESSAGE(WM_CBO_LIST_RBUTTONUP,OnRButtonUp)
- ON_MESSAGE(WM_CBO_LIST_HIDE, OnListHide)
- ON_MESSAGE(WM_CTLCOLORLISTBOX,OnCtlColorListBox)
- END_MESSAGE_MAP()
- BOOL CSkinComboBox::SetBgNormalPic( LPCTSTR lpszFileName, RECT * lpNinePart /*= NULL*/ )
- {
- RenderEngine->RemoveImage(m_lpBgImgN);
- m_lpBgImgN = RenderEngine->GetImage(lpszFileName);
- if (m_lpBgImgN != NULL)
- m_lpBgImgN->SetNinePart(lpNinePart);
- return (m_lpBgImgN != NULL) ? TRUE : FALSE;
- }
- BOOL CSkinComboBox::SetBgHotPic( LPCTSTR lpszFileName, RECT * lpNinePart /*= NULL*/ )
- {
- RenderEngine->RemoveImage(m_lpBgImgH);
- m_lpBgImgH = RenderEngine->GetImage(lpszFileName);
- if (m_lpBgImgH != NULL)
- m_lpBgImgH->SetNinePart(lpNinePart);
- return (m_lpBgImgH != NULL) ? TRUE : FALSE;
- }
- BOOL CSkinComboBox::SetArrowNormalPic( LPCTSTR lpszFileName )
- {
- RenderEngine->RemoveImage(m_lpArrowImgN);
- m_lpArrowImgN = RenderEngine->GetImage(lpszFileName);
- return (m_lpArrowImgN != NULL) ? TRUE : FALSE;
- }
- BOOL CSkinComboBox::SetArrowHotPic( LPCTSTR lpszFileName )
- {
- RenderEngine->RemoveImage(m_lpArrowImgH);
- m_lpArrowImgH =RenderEngine->GetImage(lpszFileName);
- return (m_lpArrowImgH != NULL) ? TRUE : FALSE;
- }
- BOOL CSkinComboBox::SetArrowPushedPic( LPCTSTR lpszFileName )
- {
- RenderEngine->RemoveImage(m_lpArrowImgP);
- m_lpArrowImgP = RenderEngine->GetImage(lpszFileName);
- return (m_lpArrowImgP != NULL) ? TRUE : FALSE;
- }
- void CSkinComboBox::SetDefaultText( LPCTSTR lpszText )
- {
- m_SkinComboBoxEdit.SetDefaultText(lpszText);
- }
- BOOL CSkinComboBox::IsDefaultText()
- {
- return m_SkinComboBoxEdit.IsDefaultText();
- }
- void CSkinComboBox::SetArrowWidth( int nWidth )
- {
- m_nArrowWidth = nWidth;
- }
- // CSkinComboBox 消息处理程序
- void CSkinComboBox::PreSubclassWindow()
- {
- //变量定义
- COMBOBOXINFO ComboBoxInfo;
- ComboBoxInfo.cbSize=sizeof(ComboBoxInfo);
- //绑定控件
- if (GetComboBoxInfo(&ComboBoxInfo)==TRUE)
- {
- if (ComboBoxInfo.hwndItem!=NULL)
- {
- m_SkinComboBoxEdit.SetOwnerWnd(GetSafeHwnd());
- m_SkinComboBoxEdit.SubclassWindow(ComboBoxInfo.hwndItem);
- }
- if (ComboBoxInfo.hwndList!=NULL)
- {
- m_SkinComboBoxList.SetOwnerWnd(GetSafeHwnd());
- m_SkinComboBoxList.SubclassWindow(ComboBoxInfo.hwndList);
- }
- }
- CComboBox::PreSubclassWindow();
- }
- int CSkinComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CComboBox::OnCreate(lpCreateStruct) == -1)
- return -1;
- //变量定义
- COMBOBOXINFO ComboBoxInfo;
- ComboBoxInfo.cbSize=sizeof(ComboBoxInfo);
- //绑定控件
- if (GetComboBoxInfo(&ComboBoxInfo)==TRUE)
- {
- if (ComboBoxInfo.hwndItem!=NULL)
- {
- m_SkinComboBoxEdit.SetOwnerWnd(GetSafeHwnd());
- m_SkinComboBoxEdit.SubclassWindow(ComboBoxInfo.hwndItem);
- }
- if (ComboBoxInfo.hwndList!=NULL)
- {
- m_SkinComboBoxList.SetOwnerWnd(GetSafeHwnd());
- m_SkinComboBoxList.SubclassWindow(ComboBoxInfo.hwndList);
- }
- }
- //设置默认字体
- SetFont(CFont::FromHandle(RenderEngine->GetDeaultFont()));
- return 0;
- }
- BOOL CSkinComboBox::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- void CSkinComboBox::OnPaint()
- {
- CPaintDC dc(this);
- CRect rcClient;
- GetClientRect(&rcClient);
- CMemoryDC MemDC(&dc,rcClient);
- CRect rcArrow;
- HRGN hRgn2 = NULL;
- if (m_lpArrowImgN != NULL && !m_lpArrowImgN->IsNull())
- {
- int cxIcon = m_nArrowWidth;
- int cyIcon = m_lpArrowImgN->GetHeight();
- CalcCenterRect(rcClient, cxIcon, cyIcon, rcArrow);
- rcArrow.right = rcClient.right - 2;
- rcArrow.left = rcArrow.right - cxIcon;
- }
- DrawParentWndBg(GetSafeHwnd(),MemDC->GetSafeHdc());
- if (m_bHover)
- {
- if (m_lpBgImgH != NULL && !m_lpBgImgH->IsNull())
- {
- m_lpBgImgH->Draw(&MemDC, rcClient);
- }
- else
- {
- if (m_lpBgImgN != NULL && !m_lpBgImgN->IsNull())
- m_lpBgImgN->Draw(&MemDC, rcClient);
- }
- }
- else
- {
- if (m_lpBgImgN != NULL && !m_lpBgImgN->IsNull())
- m_lpBgImgN->Draw(&MemDC, rcClient);
- }
- if (m_bArrowPress)
- {
- if (m_lpArrowImgP != NULL && !m_lpArrowImgP->IsNull())
- m_lpArrowImgP->Draw(&MemDC, rcArrow);
- }
- else if (m_bArrowHover)
- {
- if (m_lpArrowImgH != NULL && !m_lpArrowImgH->IsNull())
- m_lpArrowImgH->Draw(&MemDC, rcArrow);
- }
- else
- {
- if (m_lpArrowImgN != NULL && !m_lpArrowImgN->IsNull())
- m_lpArrowImgN->Draw(&MemDC, rcArrow);
- }
- //绘制边框
- m_SkinComboBoxList.DrawListFrame();
- }
- void CSkinComboBox::OnLButtonDown(UINT nFlags, CPoint point)
- {
- //设置焦点
- SetFocus();
- //效验数据
- if( m_SkinComboBoxEdit.GetSafeHwnd() == NULL ) return;
- if ( (m_SkinComboBoxEdit.GetStyle() & ES_READONLY) == 0 )
- {
- if (VerdictOverButton(point))
- {
- m_bArrowPress = TRUE;
- //显示列表
- ShowDropDown(GetDroppedState()==FALSE);
- }
- }
- else
- {
- m_bArrowPress = TRUE;
- //显示列表
- ShowDropDown(GetDroppedState()==FALSE);
- m_SkinComboBoxEdit.SetSel(0,0);
- }
- //更新按钮
- RedrawWindow(&m_rcArrow,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- //__super::OnLButtonDown(nFlags, point);
- }
- void CSkinComboBox::OnMouseMove(UINT nFlags, CPoint point)
- {
- BOOL bRePaint = FALSE;
- if (!m_bMouseTracking)
- {
- TrackMouseLeave(GetSafeHwnd());
- m_bMouseTracking = TRUE;
- m_bHover = TRUE;
- bRePaint = TRUE;
- }
- if (VerdictOverButton(point))
- {
- if (!m_bArrowHover)
- {
- m_bArrowHover = TRUE;
- bRePaint = TRUE;
- }
- }
- else
- {
- if (m_bArrowHover)
- {
- m_bArrowHover = FALSE;
- bRePaint = TRUE;
- }
- }
- if (bRePaint)
- RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- __super::OnMouseMove(nFlags, point);
- }
- void CSkinComboBox::OnMouseLeave()
- {
- m_bMouseTracking = FALSE;
- if (!m_SkinComboBoxList.IsWindowVisible())
- {
- CPoint pt;
- GetCursorPos(&pt);
- CRect rcWindow;
- GetWindowRect(&rcWindow);
- if (!rcWindow.PtInRect(pt))
- m_bHover = FALSE;
- m_bArrowHover = FALSE;
- RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- }
- __super::OnMouseLeave();
- }
- void CSkinComboBox::OnDestroy()
- {
- __super::OnDestroy();
- RenderEngine->RemoveImage(m_lpBgImgN);
- RenderEngine->RemoveImage(m_lpBgImgH);
- RenderEngine->RemoveImage(m_lpArrowImgN);
- RenderEngine->RemoveImage(m_lpArrowImgH);
- RenderEngine->RemoveImage(m_lpArrowImgP);
- RemoveScorll();
- }
- void CSkinComboBox::OnSize(UINT nType, int cx, int cy)
- {
- __super::OnSize(nType, cx, cy);
- if ( m_SkinComboBoxEdit.GetSafeHwnd() == NULL ) return;
-
- CRect rcClient;
- GetClientRect(&rcClient);
- CRect rcEdit;
- m_SkinComboBoxEdit.GetWindowRect(&rcEdit);
- ScreenToClient(&rcEdit);
- CDC* pDC = m_SkinComboBoxEdit.GetDC();
- TEXTMETRIC tm = {0};
- pDC->GetTextMetrics(&tm);
- int nFontHeight = tm.tmHeight + tm.tmExternalLeading;
- int nMargin = (rcEdit.Height() - nFontHeight) / 2;
- m_SkinComboBoxEdit.ReleaseDC(pDC);
- rcEdit.DeflateRect(0, nMargin);
- rcEdit.right = rcClient.right - 2 - m_nArrowWidth;
- m_SkinComboBoxEdit.MoveWindow(&rcEdit, FALSE);
- m_rcArrow.left = rcClient.right - 2 - m_nArrowWidth;
- m_rcArrow.right = m_rcArrow.left + m_nArrowWidth;
- m_rcArrow.top = rcClient.top;
- m_rcArrow.bottom = rcClient.bottom;
- }
- LRESULT CSkinComboBox::OnEditMouseHover( WPARAM wParam, LPARAM lParam )
- {
- if (!m_bHover)
- {
- m_bHover = TRUE;
- RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- }
- return 0;
- }
- LRESULT CSkinComboBox::OnEditMouseLeave( WPARAM wParam, LPARAM lParam )
- {
- CPoint pt;
- GetCursorPos(&pt);
- CRect rcWindow;
- GetWindowRect(&rcWindow);
- if (!rcWindow.PtInRect(pt))
- {
- if (m_bHover)
- {
- m_bHover = FALSE;
- RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- }
- }
- return 0;
- }
- LRESULT CSkinComboBox::OnListHide( WPARAM wParam, LPARAM lParam )
- {
- m_bHover = FALSE;
- m_bArrowHover = FALSE;
- m_bArrowPress = FALSE;
- RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- return 0;
- }
- bool CSkinComboBox::VerdictOverButton( CPoint MousePoint )
- {
- //获取位置
- CRect rcClient;
- GetClientRect(&rcClient);
- //下拉列表
- if ((rcClient.PtInRect(MousePoint)==TRUE)&&((GetStyle()&CBS_SIMPLE)!=0)) return true;
- //坐标计算
- if ((MousePoint.y>(rcClient.Height()-1))||(MousePoint.y<1)) return false;
- if ((MousePoint.x<(rcClient.Width()-(INT)m_rcArrow.Width()-1))||(MousePoint.x>(rcClient.Width()-1))) return false;
- return true;
- }
- void CSkinComboBox::SetDropList()
- {
- //效验数据
- if ( m_SkinComboBoxEdit.GetSafeHwnd() == NULL ) return;
-
- //m_SkinComboBoxEdit.EnableWindow(FALSE);
- m_SkinComboBoxEdit.SetReadOnly();
- }
- void CSkinComboBox::SetEditTextColor( COLORREF col )
- {
- //效验数据
- if ( m_SkinComboBoxEdit.GetSafeHwnd() == NULL ) return;
-
- if ( (m_SkinComboBoxEdit.GetStyle() & ES_READONLY) == 0)
- m_SkinComboBoxEdit.m_colNormalText = col;
- else m_SkinComboBoxEdit.m_colReadOnlyText = col;
- RedrawWindow(NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
- }
- CSkinComboBox_Edit * CSkinComboBox::GetEditWnd()
- {
- if ( m_SkinComboBoxEdit.GetSafeHwnd() == NULL ) return NULL;
-
- return &m_SkinComboBoxEdit;
- }
- CSkinComboBox_ListBox * CSkinComboBox::GetListBoxWnd()
- {
- if ( m_SkinComboBoxList.GetSafeHwnd() == NULL ) return NULL;
- return &m_SkinComboBoxList;
- }
- void CSkinComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
- {
- lpMeasureItemStruct->itemHeight = m_cyItemHeight;
- }
- void CSkinComboBox::SetAllItemHeight(UINT cyItemHeight)
- {
- m_cyItemHeight = cyItemHeight;
- }
- LRESULT CSkinComboBox::OnCtlColorListBox( WPARAM wParam, LPARAM lParam )
- {
- HWND hListBoxWnd = m_SkinComboBoxList.GetSafeHwnd();
- if ( hListBoxWnd == NULL)
- {
- HWND hWnd = (HWND)lParam;
- if (hWnd != 0 && hWnd != m_hWnd)
- {
- hListBoxWnd = hWnd;
- m_pWndProc = (WNDPROC)GetWindowLong(hListBoxWnd, GWL_WNDPROC);
- SetWindowLong(hListBoxWnd, GWL_WNDPROC, (LONG)ComboBoxListBoxProc);
- }
- }
- return DefWindowProc(WM_CTLCOLORLISTBOX, wParam, lParam);
- }
- BOOL CSkinComboBox::SetScrollImage( LPCTSTR pszFileName )
- {
- if ( m_SkinComboBoxList.GetSafeHwnd() == FALSE ) return FALSE;
-
- return m_SkinComboBoxList.SetScrollImage(&m_SkinComboBoxList,pszFileName);
- }
- LRESULT CSkinComboBox::OnRButtonUp( WPARAM wParam, LPARAM lParam )
- {
- CWnd *pWnd = GetParent();
- if ( (pWnd != NULL) && (pWnd->GetSafeHwnd() != NULL) )
- {
- pWnd->PostMessage(WM_CBO_RBUTTONUP,wParam,lParam);
- }
- return 0L;
- }
- BOOL CSkinComboBox::CreateControl(CWnd* pParentWnd)
- {
- if( !Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWN | CBS_SORT |WS_VSCROLL | WS_TABSTOP,CRect(0,0,0,0),pParentWnd,0) )
- return FALSE;
- m_pOwnWnd = this;
- return TRUE;
- }
- void CSkinComboBox::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
- {
- ISkinControl::SetAttribute(pstrName,pstrValue);
- LPTSTR pstr = NULL;
- if( _tcscmp(pstrName, _T("droplist")) == 0 )
- {
- if( _tcscmp(pstrValue, _T("true")) == 0 )
- {
- ModifyStyle(0,CBS_OWNERDRAWVARIABLE|CBS_HASSTRINGS);
- SetDropList();
- }
- }
- else if( _tcscmp(pstrName, _T("defaulttext")) == 0 ) SetDefaultText(pstrValue);
- else if( _tcscmp(pstrName, _T("arrownormalimg")) == 0 ) SetArrowNormalPic(pstrValue);
- else if( _tcscmp(pstrName, _T("arrowhotimg")) == 0 ) SetArrowHotPic(pstrValue);
- else if( _tcscmp(pstrName, _T("arrowpushimg")) == 0 ) SetArrowPushedPic(pstrValue);
- else if( _tcscmp(pstrName, _T("arrowwidth")) == 0 ) SetArrowWidth(_ttoi(pstrValue));
- else if( _tcscmp(pstrName, _T("boxheight")) == 0 ) SetEditItemHeight(_ttoi(pstrValue));
- else if( _tcscmp(pstrName, _T("itemheight")) == 0 ) SetAllItemHeight(_ttoi(pstrValue));
- else if( _tcscmp(pstrName, _T("textcolor")) == 0 )
- {
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- SetEditTextColor( _tcstoul(pstrValue, &pstr, 16));
- }
- else if( _tcscmp(pstrName, _T("bkcolor")) == 0 )
- {
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- m_SkinComboBoxEdit.m_colBack = _tcstoul(pstrValue, &pstr, 16);
- }
- else if( _tcscmp(pstrName, _T("format")) == 0 )
- {
- m_SkinComboBoxEdit.ModifyStyle(0,_ttoi(pstrValue));
- }
- }
- void CSkinComboBox::ParseItem(CXmlNode *root )
- {
- if( root == NULL ) return;
- int nAttributes = root->GetAttributeCount();
- LPCTSTR pstrClass = NULL;
- LPCTSTR pstrName = NULL;
- LPCTSTR pstrValue = NULL;
- for( int i = 0; i < nAttributes; i++ )
- {
- pstrClass = root->GetName();
- pstrName = root->GetAttributeName(i);
- pstrValue = root->GetAttributeValue(i);
- if( _tcscmp(pstrClass, _T("normalimage")) == 0 )
- {
- if( _tcscmp(pstrName, _T("value")) == 0 ) SetBgNormalPic(pstrValue);
- else if( _tcscmp(pstrName, _T("ninepart")) == 0 )
- {
- LPTSTR pstr = NULL;
- CRect rc;
- rc.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
- rc.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- rc.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- rc.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- if (m_lpBgImgN != NULL)
- m_lpBgImgN->SetNinePart(&rc);
- }
- }
- else if( _tcscmp(pstrClass, _T("hotimage")) == 0 )
- {
- if( _tcscmp(pstrName, _T("value")) == 0 ) SetBgHotPic(pstrValue);
- else if( _tcscmp(pstrName, _T("ninepart")) == 0 )
- {
- LPTSTR pstr = NULL;
- CRect rc;
- rc.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
- rc.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- rc.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- rc.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- if (m_lpBgImgH != NULL)
- m_lpBgImgH->SetNinePart(&rc);
- }
- }
- else if( _tcscmp(pstrClass, _T("item")) == 0 )
- {
- if( _tcscmp(pstrName, _T("text")) == 0 ) AddString(pstrValue);
- }
- else if( _tcscmp(pstrClass, _T("ListBox")) == 0 )
- {
- LPTSTR pstr = NULL;
- CSkinComboBox_ListBox *pListBox = GetListBoxWnd();
- if ( pListBox != NULL && pListBox->GetSafeHwnd() != NULL )
- {
- if( _tcscmp(pstrName, _T("selectimage")) == 0 ) pListBox->SetSelectImage(pstrValue);
- else if( _tcscmp(pstrName, _T("ninepart")) == 0 )
- {
- CRect rc;
- rc.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
- rc.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- rc.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- rc.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
- if (pListBox->m_pSelectImg != NULL)
- pListBox->m_pSelectImg->SetNinePart(&rc);
- }
- }
- else if( _tcscmp(pstrName, _T("framecolor")) == 0 )
- {
- if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
- SetFrameColor( _tcstoul(pstrValue, &pstr, 16));
- }
- }
- }
- }
|