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 COXComboPickerCtrl::OnPaint() { // Detect OS. If the OS is XP or higher we use the OS painting routines, // else we do custom painting. OSVERSIONINFO ovi = {0}; ovi.dwOSVersionInfoSize = sizeof OSVERSIONINFO; GetVersionEx(&ovi); bool bXPOrHigher = (ovi.dwMajorVersion >= 5) && (ovi.dwMinorVersion >= 1); if( (m_pDropDown==NULL) || bXPOrHigher ) { Default(); return; } CPaintDC dcPaint(this); BOOL bIsEnabled=IsWindowEnabled(); CRect rectClient; GetClientRect(rectClient); // draw dropdown button CRect rectDropdownButton=GetDropdownButtonRect(); dcPaint.DrawFrameControl(rectDropdownButton,DFC_SCROLL, DFCS_SCROLLDOWN | (GetDroppedState() ? DFCS_PUSHED|DFCS_FLAT : 0) | (bIsEnabled ? 0 : DFCS_INACTIVE)); // draw border dcPaint.Draw3dRect(rectClient,::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DHILIGHT)); rectClient.DeflateRect(1,1); dcPaint.Draw3dRect(rectClient,::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DFACE)); rectClient.DeflateRect(1,1); // adjust for dropdown button rectClient.right=rectDropdownButton.left; rectClient.DeflateRect(1,1); // do default painting DRAWITEMSTRUCT dis={ sizeof(&dis) }; dis.CtlType=ODT_COMBOBOX; dis.CtlID=GetDlgCtrlID(); dis.itemID=0; dis.itemAction=ODA_DRAWENTIRE; dis.hwndItem=GetSafeHwnd(); dis.hDC=dcPaint.GetSafeHdc(); dis.rcItem=rectClient; dis.itemData=0; dis.itemState=((::GetFocus()==GetSafeHwnd() && !GetDroppedState()) ? ODS_FOCUS : 0); DrawItem(&dis); }
BOOL CXTPSyntaxEditColorComboBox::PreTranslateMessage(MSG* pMsg) { switch (pMsg->message) { case WM_KEYDOWN: { switch (pMsg->wParam) { case VK_ESCAPE: { if (GetDroppedState() == TRUE) { ShowDropDown(FALSE); NotifyOwner(CBN_SELENDCANCEL); return TRUE; } } break; case VK_SPACE: case VK_RETURN: { if (GetDroppedState() == TRUE) { m_iPrevSel = GetLBCurSel(); ShowDropDown(FALSE); NotifyOwner(CBN_SELENDOK); return TRUE; } } break; case VK_UP: case VK_DOWN: { if (GetDroppedState() == FALSE) { m_iPrevSel = GetCurSel(); ShowDropDown(TRUE); return TRUE; } } break; } } } return CComboBox::PreTranslateMessage(pMsg); }
BOOL CSchemaCombo::PreTranslateMessage(MSG* pMsg) { if ( pMsg->message == WM_KEYDOWN ) { if ( pMsg->wParam == VK_SPACE || pMsg->wParam == VK_RETURN ) { if ( GetDroppedState() ) { if ( ! OnClickItem( GetCurSel(), TRUE ) ) { ShowDropDown( FALSE ); } return TRUE; } else if ( pMsg->wParam == VK_SPACE ) { ShowDropDown(); return TRUE; } } else if ( pMsg->wParam == VK_DOWN ) { if ( OnClickItem( GetCurSel() + 1, TRUE ) ) { return TRUE; } } } return CComboBox::PreTranslateMessage( pMsg ); }
BOOL CMyComboBox::PreTranslateMessage(MSG* pMsg) { bool ctrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0; if ( pMsg->message == WM_KEYDOWN){ switch( pMsg->wParam ){ case 'C': if ( ctrl ){ Copy(); return TRUE; } break; case 'X': if ( ctrl ) { Cut(); return TRUE; } break; case 'V': if ( ctrl ) { Paste(); return TRUE; } break; case VK_DOWN: if ( GetDroppedState() == FALSE ){ ShowDropDown( TRUE ); } break; } } return CComboBox::PreTranslateMessage(pMsg); }
LRESULT COXComboPickerCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { #if defined (_WINDLL) #if defined (_AFXDLL) AFX_MANAGE_STATE(AfxGetAppModuleState()); #else AFX_MANAGE_STATE(AfxGetStaticModuleState()); #endif #endif LRESULT lResult=0; switch(message) { case CB_GETDROPPEDSTATE: lResult=GetDroppedState(); break; case CB_SHOWDROPDOWN: ShowDropDown((BOOL)wParam); break; default: lResult=CComboBox::WindowProc(message,wParam,lParam); break; } return lResult; }
BOOL CLocalComboBox::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN) { CFormatBar* pBar = (CFormatBar*)GetParent(); switch (pMsg->wParam) { case VK_ESCAPE: pBar->SyncToView(); pBar->NotifyOwner(NM_RETURN); return TRUE; case VK_RETURN: pBar->NotifyOwner(NM_RETURN); return TRUE; case VK_TAB: pBar->GetNextDlgTabItem(this)->SetFocus(); return TRUE; case VK_UP: case VK_DOWN: if ((GetKeyState(VK_MENU) >= 0) && (GetKeyState(VK_CONTROL) >=0) && !GetDroppedState()) { ShowDropDown(); return TRUE; } } } return CComboBox::PreTranslateMessage(pMsg); }
void CMyComboBox::OnCbnEditchange() { // ユーザがテキストを変更したらコンボを閉じる if ( GetDroppedState() != FALSE ){ ShowDropDown( FALSE ); } }
// Preview window void CTypefaceCombo::ShowPreview() { if (GetDroppedState()) { UpdatePreview(); MovePreview(); m_pPreviewWnd->ShowWindow(SW_SHOWNOACTIVATE); } }
BOOL CHistoryCombo::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN) { bool bShift = !!(GetKeyState(VK_SHIFT) & 0x8000); int nVirtKey = (int) pMsg->wParam; if (nVirtKey == VK_RETURN) return OnReturnKeyPressed(); else if (nVirtKey == VK_DELETE && bShift && GetDroppedState() ) { RemoveSelectedItem(); return TRUE; } if (nVirtKey == 'A' && (GetKeyState(VK_CONTROL) & 0x8000 ) ) { CEdit *edit = GetEditCtrl(); if (edit) edit->SetSel(0, -1); return TRUE; } } else if (pMsg->message == WM_MOUSEMOVE && this->m_bDyn ) { if ((pMsg->wParam & MK_LBUTTON) == 0) { CPoint pt; pt.x = LOWORD(pMsg->lParam); pt.y = HIWORD(pMsg->lParam); OnMouseMove((UINT)pMsg->wParam, pt); return TRUE; } } else if ((pMsg->message == WM_MOUSEWHEEL || pMsg->message == WM_MOUSEHWHEEL) && !GetDroppedState()) { return TRUE; } return CComboBoxEx::PreTranslateMessage(pMsg); }
int CXTPSyntaxEditColorComboBox::GetLBCurSel() const { if (GetDroppedState() == TRUE) { HWND hWnd = ::FindWindow(_T("ComboLBox"), NULL); if (::IsWindow(hWnd)) { return (int)::SendMessage(hWnd, LB_GETCURSEL, 0, 0); } } return LB_ERR; }
COXComboPickerCtrl::~COXComboPickerCtrl() { if(m_pDropDown!=NULL) { if(m_pDropDown->GetWindow()!=NULL && ::IsWindow(m_pDropDown->GetWindow()->GetSafeHwnd()) && GetDroppedState()) { ShowDropDown(FALSE); } m_pDropDown->SetOwnerCombo(NULL); } }
void COXComboPickerCtrl::OnKillFocus(CWnd* pNewWnd) { if(pNewWnd!=this && m_pDropDown!=NULL && pNewWnd!=m_pDropDown->GetContainer() && pNewWnd!=m_pDropDown->GetContainer()->GetAttachedWindow()) { if(GetDroppedState()) { ShowDropDown(FALSE); } } CComboBox::OnKillFocus(pNewWnd); }
BOOL CInPlaceList::OnEditchange() { // TODO: Add your control notification handler code here m_bEdit = TRUE; DWORD dwGetSel = GetEditSel(); WORD wStart = LOWORD(dwGetSel); WORD wEnd = HIWORD(dwGetSel); GetWindowText(m_sTypedText); CString sEditText(m_sTypedText); sEditText.MakeLower(); CString sTemp, sFirstOccurrence; const BOOL bEmpty = m_sTypedText.IsEmpty(); POSITION pos = m_PtrList.GetHeadPosition(); while(! bEmpty && pos) { CItemData* pData = m_PtrList.GetNext(pos); sTemp = pData->m_sItem; sTemp.MakeLower(); if (StringIsLike(sEditText + "*", sTemp)) AddItem(pData); else DeleteItem(pData); } if(GetCount() < 1 || bEmpty) { if(GetDroppedState()) ShowDropDown(FALSE); else { pos = m_PtrList.GetHeadPosition(); while(pos) AddItem(m_PtrList.GetNext(pos)); } } else { ShowDropDown(); FitDropDownToItems(); } UpdateText(m_sTypedText); SetEditSel(wStart,wEnd); m_bEdit = FALSE; return Default() != 0; }
void COXComboPickerCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) { if(m_pDropDown!=NULL) { if(!GetDroppedState()) { ShowDropDown(TRUE); } } else { CComboBox::OnLButtonDblClk(nFlags,point); } }
BOOL CHistoryCombo::PreTranslateMessage(MSG* pMsg) { switch (pMsg->message) { case WM_KEYDOWN: { bool bShift = !!(GetKeyState(VK_SHIFT) & 0x8000); int nVirtKey = (int) pMsg->wParam; if (nVirtKey == VK_RETURN) return OnReturnKeyPressed(); else if (nVirtKey == VK_DELETE && bShift && GetDroppedState() ) { RemoveSelectedItem(); return TRUE; } } break; case WM_MOUSEMOVE: { if ((pMsg->wParam & MK_LBUTTON) == 0) { CPoint pt; pt.x = LOWORD(pMsg->lParam); pt.y = HIWORD(pMsg->lParam); OnMouseMove((UINT)pMsg->wParam, pt); return TRUE; } } break; case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: if (!GetDroppedState()) return TRUE; } return CComboBoxEx::PreTranslateMessage(pMsg); }
void COXComboPickerCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if(m_pDropDown!=NULL) { if(!GetDroppedState() && (nChar==VK_UP || nChar==VK_DOWN || nChar==VK_RETURN)) { ShowDropDown(TRUE); return; } if(GetDroppedState()) { CWnd* pDropdownCtrl=m_pDropDown->GetContainer()->GetAttachedWindow(); ASSERT(::IsWindow(pDropdownCtrl->GetSafeHwnd())); if(::IsWindow(pDropdownCtrl->GetSafeHwnd())) { pDropdownCtrl->SendMessage(WM_KEYDOWN,nChar,MAKELONG(nRepCnt,nFlags)); return; } } } CComboBox::OnKeyDown(nChar,nRepCnt,nFlags); }
BOOL COXComboPickerCtrl::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN && GetDroppedState()) { if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE || pMsg->wParam==VK_CANCEL) { ::TranslateMessage(pMsg); ::DispatchMessage(pMsg); return TRUE; } } return CComboBox::PreTranslateMessage(pMsg); }
void CSearchBox::OnEditchange() { // TODO: Add your control notification handler code here DWORD dwEditSel = GetEditSel(); CString strText; GetWindowText( strText ); int nFind = FindString( 0, strText ); SetCurSel( nFind ); if( !GetDroppedState() ) ShowDropDown( ); SetWindowText( strText ); SetEditSel( 0, -1 ); SetEditSel( LOWORD(dwEditSel), HIWORD(dwEditSel) ); }
BOOL CXTPSyntaxEditColorComboBox::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { if (GetDroppedState() == TRUE) { HWND hWnd = ::FindWindow(_T("ComboLBox"), NULL); if (::IsWindow(hWnd)) { ::SendMessage(hWnd, WM_SETREDRAW, FALSE, 0); BOOL bRet = CComboBox::OnMouseWheel(nFlags, zDelta, pt); ::SendMessage(hWnd, WM_SETREDRAW, TRUE, 0); ::RedrawWindow(hWnd, NULL, (HRGN)NULL, RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_FRAME | RDW_INVALIDATE | RDW_ERASE); return bRet; } } return CComboBox::OnMouseWheel(nFlags, zDelta, pt); }
BOOL CBCGFontComboBox::PreTranslateMessage(MSG* pMsg) { if (m_bToolBarMode && pMsg->message == WM_KEYDOWN && !CBCGToolbarFontCombo::IsFlatMode ()) { CBCGToolBar* pBar = (CBCGToolBar*) GetParent (); switch (pMsg->wParam) { case VK_ESCAPE: if (BCGGetTopLevelFrame (this) != NULL) { BCGGetTopLevelFrame (this)->SetFocus (); } return TRUE; case VK_TAB: if (pBar != NULL) { pBar->GetNextDlgTabItem (this)->SetFocus(); } return TRUE; case VK_UP: case VK_DOWN: if ((GetKeyState(VK_MENU) >= 0) && (GetKeyState(VK_CONTROL) >=0) && !GetDroppedState()) { ShowDropDown(); return TRUE; } } } return CComboBox::PreTranslateMessage(pMsg); }
///////////////////////////////////////////////////////////////////////////// // CCSTMCombo message handlers void CCSTMCombo::DrawBorder(CDC* pDC) { CRect rcItem; DWORD dwExStyle = GetExStyle(); int nBorderWidth = 0; GetWindowRect(&rcItem); ScreenToClient(&rcItem); if (dwExStyle & WS_EX_DLGMODALFRAME) { nBorderWidth += 3; } if (dwExStyle & WS_EX_CLIENTEDGE) { nBorderWidth += 2; } if (dwExStyle & WS_EX_STATICEDGE && !(dwExStyle & WS_EX_DLGMODALFRAME)) { nBorderWidth ++; } if(m_bDrawOutline) { pDC->Draw3dRect(rcItem, m_clrOutLineColor,m_clrOutLineColor ); rcItem.DeflateRect(1,1); } COLORREF colorBoard = m_clr3DFace; if(m_bDrawFlat) { colorBoard = m_clrBackColor; nBorderWidth = m_bDrawOutline ? 1 : 2; } if (m_bDrawFlat == FALSE) { rcItem.InflateRect(1, 1); if (dwExStyle & WS_EX_CLIENTEDGE) { pDC->Draw3dRect(rcItem, m_clr3DDkShadow, m_clr3DLight); rcItem.InflateRect(1, 1); pDC->Draw3dRect(rcItem, m_clr3DShadow, m_clr3DHilight); rcItem.InflateRect(1, 1); } if (dwExStyle & WS_EX_STATICEDGE && !(dwExStyle & WS_EX_DLGMODALFRAME)) { pDC->Draw3dRect(rcItem, m_clr3DShadow, m_clr3DHilight); rcItem.InflateRect(1, 1); } if (dwExStyle & WS_EX_DLGMODALFRAME) { pDC->Draw3dRect(rcItem, m_clr3DFace, m_clr3DFace); rcItem.InflateRect(1, 1); pDC->Draw3dRect(rcItem, m_clr3DHilight, m_clr3DShadow); rcItem.InflateRect(1, 1); pDC->Draw3dRect(rcItem, m_clr3DLight, m_clr3DDkShadow); } } for (int nLoop = 0; nLoop < nBorderWidth; nLoop++) { pDC->Draw3dRect(rcItem, colorBoard, colorBoard); rcItem.DeflateRect(1, 1); } //Button Draw rcItem.left = rcItem.right - ::GetSystemMetrics( SM_CXHTHUMB ); m_rcButton = rcItem; BOOL bDropped = GetDroppedState(); DrawBitmap(pDC,m_rcButton,bDropped); }
void COXComboPickerCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { ASSERT(lpDrawItemStruct->CtlType==ODT_COMBOBOX); ASSERT((lpDrawItemStruct->CtlType & ODS_COMBOBOXEDIT)==0); BOOL bHasFocus=(GetFocus()==this && !GetDroppedState()); CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); ASSERT(pDC!=NULL); int nSavedDC=pDC->SaveDC(); CRect rectItem=lpDrawItemStruct->rcItem; // adjustment for focus rectangle rectItem.InflateRect(1,1); // draw background pDC->FillSolidRect(rectItem,(IsWindowEnabled() ? ::GetSysColor(COLOR_WINDOW) : ::GetSysColor(COLOR_BTNFACE))); rectItem.DeflateRect(1,1); if(m_pDropDown==NULL || !m_pDropDown->IsThereSelectedItem()) { return; } // draw image // CImageList* pImageList=m_pDropDown->GetSelectedItemImage(); if(pImageList!=NULL) { ASSERT(pImageList->GetImageCount()>0); if(pImageList->GetImageCount()>0) { CRect rectImage=rectItem; IMAGEINFO imageInfo; VERIFY(pImageList->GetImageInfo(0,&imageInfo)); CRect rectImageSize=imageInfo.rcImage; if(rectImageSize.Height()<rectImage.Height()) { rectImage.top+=(rectImage.Height()-rectImageSize.Height())/2; rectImage.bottom=rectImage.top+rectImageSize.Height(); } rectImage.right=rectImage.left+rectImageSize.Width(); pImageList->Draw(pDC,0,rectImage.TopLeft(), ILD_TRANSPARENT/*|(bHasFocus ? ILD_FOCUS : 0)*/); // update rectItem rectItem.left=rectImage.right+1; } // we are responsible for deleting the image list object delete pImageList; } // //////////////////////////////////////// // draw text // CString sText=m_pDropDown->GetSelectedItemText(); if(!sText.IsEmpty()) { // set colors if(bHasFocus) { pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { pDC->SetTextColor(m_pDropDown->GetSelectedItemTextColor()); } // set font CFont* pFont=m_pDropDown->GetSelectedItemFont(); if(pFont!=NULL) { pDC->SelectObject(pFont); } CRect rectText=rectItem; rectText.left++; CRect rectTextSize=rectText; pDC->DrawText(sText,rectTextSize,DT_LEFT|DT_CALCRECT|DT_SINGLELINE); if(rectTextSize.Height()<rectText.Height()) { rectText.top+=(rectText.Height()-rectTextSize.Height())/2; rectText.bottom=rectText.top+rectTextSize.Height(); } if(rectText.Width()>rectTextSize.Width()) { rectText.right=rectText.left+rectTextSize.Width(); } if(bHasFocus) { CRect rectTextFocus=rectText; rectTextFocus.InflateRect(1,1); pDC->DrawFocusRect(rectTextFocus); } pDC->DrawText(sText,rectText,DT_LEFT|DT_VCENTER|DT_SINGLELINE); } // //////////////////////////////////////// if(nSavedDC!=0) { pDC->RestoreDC(nSavedDC); } }
void COXComboPickerCtrl::ShowDropDown(BOOL bShowIt/*=TRUE*/) { if(m_pDropDown==NULL || GetDroppedState()==bShowIt) { return; } COXDropDownContainer* pDropdownCtrl=m_pDropDown->GetContainer(); ASSERT(::IsWindow(pDropdownCtrl->GetSafeHwnd())); ASSERT(pDropdownCtrl->GetAttachedWindow()==m_pDropDown->GetWindow()); if(bShowIt) { ASSERT(::IsWindow(GetSafeHwnd())); // move dropdown control CRect rect; GetWindowRect(rect); pDropdownCtrl->SetWindowPos(NULL,rect.left,rect.bottom-1,0,0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE); m_pDropDown->ShowDropDown(bShowIt); // emulate CBN_DROPDOWN notification CWnd* pParentWnd=GetParent(); if(pParentWnd!=NULL) { pParentWnd->SendMessage( WM_COMMAND,MAKEWPARAM(CBN_DROPDOWN,GetDlgCtrlID())); } // bring dropdown control to the top ::SetWindowPos(pDropdownCtrl->GetSafeHwnd(), HWND_TOPMOST,0,0,0,0,SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); pDropdownCtrl->ShowWindow(SW_SHOWNA); pDropdownCtrl->GetAttachedWindow()->ShowWindow(SW_SHOWNA); if(m_pDropDown->NeedFocus()) { pDropdownCtrl->GetAttachedWindow()->SetFocus(); } // redraw the contents RedrawWindow(); } else { if(::IsWindow(GetSafeHwnd())) { // emulate CBN_CLOSEUP notification CWnd* pParentWnd=GetParent(); if(pParentWnd!=NULL) { pParentWnd->SendMessage( WM_COMMAND,MAKEWPARAM(CBN_CLOSEUP,GetDlgCtrlID())); } } m_pDropDown->ShowDropDown(bShowIt); // hide dropdown control pDropdownCtrl->ShowWindow(SW_HIDE); if(::IsWindow(GetSafeHwnd())) { // redraw the contents RedrawWindow(); } } }