// ComboBoxListCtrl4.cpp : implementation file // #include "stdafx.h" #include "ComboListCtrl5.h" #include #include "ylgl.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define IDC_ComboBox 0X01 #define PROPERTY_ITEM 0x02 #define PROPERTY_SUB 0x03 ///////////////////////////////////////////////////////////////////////////// // CComboBoxListCtrl5 extern CFont g_listctrlfont; //ComboBox//////////////////////////////////////////////////////////////////////// CListCtrlComboBox5::CListCtrlComboBox5() { } CListCtrlComboBox5::~CListCtrlComboBox5() { } BEGIN_MESSAGE_MAP(CListCtrlComboBox5, CComboBox) //{{AFX_MSG_MAP(CListCtrlComboBox5) ON_WM_KILLFOCUS() ON_WM_SETFOCUS() ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CListCtrlComboBox5 message handlers void CListCtrlComboBox5::SetCtrlData(DWORD dwData) { m_dwData = dwData; } DWORD CListCtrlComboBox5::GetCtrlData() { return m_dwData; } void CListCtrlComboBox5::OnKillFocus(CWnd* pNewWnd) { CComboBox::OnKillFocus(pNewWnd); CWnd* pParent = this->GetParent(); ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,m_bExchange,0); } BOOL CListCtrlComboBox5::PreTranslateMessage(MSG* pMsg) { if(pMsg->message == WM_KEYDOWN) { if(pMsg->wParam == VK_RETURN) { CWnd* pParent = this->GetParent(); m_bExchange = TRUE; ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,m_bExchange,0); } else if(pMsg->wParam == VK_ESCAPE) { CWnd* pParent = this->GetParent(); m_bExchange = FALSE; ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,m_bExchange,0); } } return CComboBox::PreTranslateMessage(pMsg); } void CListCtrlComboBox5::OnSetFocus(CWnd* pOldWnd) { CComboBox::OnSetFocus(pOldWnd); m_bExchange = TRUE; } void CListCtrlComboBox5::OnCloseup() { // TODO: Add your control notification handler code here CWnd* pParent = this->GetParent(); ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,m_bExchange,0); } //DateTimeCtrl//////////////////////////////////////////////////////////////////////// CMyDateTimeCtrl::CMyDateTimeCtrl() { } CMyDateTimeCtrl::~CMyDateTimeCtrl() { } BEGIN_MESSAGE_MAP(CMyDateTimeCtrl, CDateTimeCtrl) //{{AFX_MSG_MAP(CMyDateTimeCtrl) ON_WM_KILLFOCUS() ON_WM_SETFOCUS() ON_CONTROL_REFLECT(DTN_CLOSEUP, OnCloseup) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyDateTimeCtrl message handlers void CMyDateTimeCtrl::OnSetFocus(CWnd* pOldWnd) {//MessageBox("setfocus"); CDateTimeCtrl::OnSetFocus(pOldWnd); } void CMyDateTimeCtrl::OnKillFocus(CWnd* pNewWnd) {//MessageBox("killfocus"); // CWnd* pParent = this->GetParent(); // ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,1,0); } BOOL CMyDateTimeCtrl::PreTranslateMessage(MSG* pMsg) { if(pMsg->message == WM_KEYDOWN) { if(pMsg->wParam == VK_RETURN) { CWnd* pParent = this->GetParent(); ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,1,0); } else if(pMsg->wParam == VK_ESCAPE) { CWnd* pParent = this->GetParent(); ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,0,0); } } return CDateTimeCtrl::PreTranslateMessage(pMsg); } void CMyDateTimeCtrl::OnCloseup() { // TODO: Add your control notification handler code here // CWnd* pParent = this->GetParent(); // ::PostMessage(pParent->GetSafeHwnd(),WM_USER_ComboBox_END,1,0); } ///ListCtrl///////////////////////////////////////////////////// CComboBoxListCtrl5::CComboBoxListCtrl5() { // m_pComboBox->m_hWnd = NULL; } CComboBoxListCtrl5::~CComboBoxListCtrl5() { } BEGIN_MESSAGE_MAP(CComboBoxListCtrl5, CListCtrl) //{{AFX_MSG_MAP(CComboBoxListCtrl5) ON_WM_LBUTTONDBLCLK() ON_WM_LBUTTONDOWN() ON_WM_PARENTNOTIFY() ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList) //}}AFX_MSG_MAP ON_MESSAGE(WM_USER_ComboBox_END,OnComboBoxEnd) END_MESSAGE_MAP() void CComboBoxListCtrl5::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult ) { NMLVCUSTOMDRAW* pLVCD = reinterpret_cast( pNMHDR ); // Take the default processing unless we set this to something else below. *pResult = 0; // First thing - check the draw stage. If it's the control's prepaint // stage, then tell Windows we want messages for every item. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage ) { *pResult = CDRF_NOTIFYITEMDRAW; } else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage ) { // This is the prepaint stage for an item. Here's where we set the // item's text color. Our return value will tell Windows to draw the // item itself, but it will use the new color we set here. // We'll cycle the colors through red, green, and light blue. COLORREF crText; int pos=pLVCD->nmcd.dwItemSpec; if(pos%2) { pLVCD->clrTextBk = g_gridcol1; } else { pLVCD->clrTextBk = g_gridcol2; } // Tell Windows to paint the control itself. *pResult = CDRF_DODEFAULT; } } void CComboBoxListCtrl5::OnLButtonDown(UINT nFlags, CPoint point) { ::PostMessage(this->GetSafeHwnd(),WM_USER_ComboBox_END,1,0); CListCtrl::OnLButtonDown( nFlags, point) ; } void CComboBoxListCtrl5::OnLButtonDblClk(UINT nFlags, CPoint point) { CRect rcCtrl; LVHITTESTINFO lvhti; lvhti.pt = point; int nItem = CListCtrl::SubItemHitTest(&lvhti); if(nItem == -1) return; int nSubItem = lvhti.iSubItem; CListCtrl::GetSubItemRect(nItem,nSubItem,LVIR_LABEL,rcCtrl); rcCtrl.top -=4; if(nSubItem==3 || nSubItem==5 || nSubItem==7) { rcCtrl.bottom +=200; rcCtrl.top +=2; ShowComboBox(TRUE,nItem,nSubItem,rcCtrl); } else if(nSubItem==4 || nSubItem==6 || nSubItem==8) ShowDateCtrl(TRUE,nItem,nSubItem,rcCtrl); CListCtrl::OnLButtonDblClk(nFlags, point); } void CComboBoxListCtrl5::ShowDateCtrl(BOOL bShow,int nItem,int nIndex,CRect rcCtrl) { if(m_DateCtrl.m_hWnd == NULL) { m_DateCtrl.Create(WS_CHILD,CRect(0,0,0,0),this,IDC_ComboBox); m_DateCtrl.ShowWindow(SW_HIDE); } if(bShow == TRUE) { CString strItem = CListCtrl::GetItemText(nItem,nIndex); if(strItem.GetLength ()==10) { CTime tm(atoi(strItem.Mid (0,4)), atoi(strItem.Mid (5,2)), atoi(strItem.Mid (8,2)), 0,0,0); m_DateCtrl.SetTime(&tm); } else { CTime tm=CTime::GetCurrentTime (); CTimeSpan dt(3, 0, 0, 0); tm+=dt; m_DateCtrl.SetTime(&tm); } m_DateCtrl.MoveWindow(rcCtrl); m_DateCtrl.ShowWindow(SW_SHOW); ::SetFocus(m_DateCtrl.GetSafeHwnd()); m_nSub=nIndex; m_nItem=nItem; } else m_DateCtrl.ShowWindow(SW_HIDE); } void CComboBoxListCtrl5::ShowComboBox(BOOL bShow,int nItem,int nIndex,CRect rcCtrl) { if(0)//m_pComboBox->m_hWnd == NULL) { m_pComboBox->Create(WS_VSCROLL|WS_CHILD|CBS_DROPDOWNLIST,CRect(0,0,0,0),this,IDC_ComboBox); m_pComboBox->ShowWindow(SW_HIDE); for(int i=0; iAddString (g_List1array.ElementAt (i).ElementAt (0)); m_pComboBox->AddString (""); } if(bShow == TRUE) { CString strItem = CListCtrl::GetItemText(nItem,nIndex); ClientToScreen(rcCtrl); GetParent()->ScreenToClient(rcCtrl); m_pComboBox->MoveWindow(rcCtrl); m_pComboBox->ShowWindow(SW_SHOW); m_pComboBox->SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); ::SetFocus(m_pComboBox->GetSafeHwnd()); m_pComboBox->ResetContent(); m_pComboBox->AddString(strItem); m_pComboBox->SetCurSel (0); m_pComboBox->SetCtrlData(MAKEWPARAM(nIndex,nItem)); m_pComboBox->RefDroppedWidth(); } else m_pComboBox->ShowWindow(SW_HIDE); } #ifdef VC60 void CComboBoxListCtrl5::OnComboBoxEnd(WPARAM wParam,LPARAM lParam) { if(m_DateCtrl.m_hWnd) { if(m_DateCtrl.IsWindowVisible ()) { if(wParam == TRUE) { CString strText(_T("")); CTime tm; m_DateCtrl.GetTime(tm); strText=tm.Format ("%Y-%m-%d"); CListCtrl::SetItemText(m_nItem,m_nSub,strText); } if(lParam == FALSE) m_DateCtrl.ShowWindow(SW_HIDE); return; } } if(m_pComboBox->m_hWnd) {if(!m_pComboBox->IsWindowVisible ())return; if(wParam == TRUE) { CString strText(_T("")); int pos=m_pComboBox->GetCurSel (); if(pos!=-1) { m_pComboBox->GetLBText (pos, strText); DWORD dwData = m_pComboBox->GetCtrlData(); int nItem= dwData>>16; int nIndex = dwData&0x0000ffff; CListCtrl::SetItemText(nItem,nIndex,strText); } } else { } if(lParam == FALSE) m_pComboBox->ShowWindow(SW_HIDE); } } #else LRESULT CComboBoxListCtrl5::OnComboBoxEnd(WPARAM wParam,LPARAM lParam) { if(m_DateCtrl.m_hWnd) { if(m_DateCtrl.IsWindowVisible ()) { if(wParam == TRUE) { CString strText(_T("")); CTime tm; m_DateCtrl.GetTime(tm); strText=tm.Format ("%Y-%m-%d"); CListCtrl::SetItemText(m_nItem,m_nSub,strText); } if(lParam == FALSE) m_DateCtrl.ShowWindow(SW_HIDE); return 0; } } if(m_pComboBox->m_hWnd) { if(!m_pComboBox->IsWindowVisible ())return 0; if(wParam == TRUE) { CString strText(_T("")); int pos=m_pComboBox->GetCurSel (); if(pos!=-1) { m_pComboBox->GetLBText (pos, strText); DWORD dwData = m_pComboBox->GetCtrlData(); int nItem= dwData>>16; int nIndex = dwData&0x0000ffff; CListCtrl::SetItemText(nItem,nIndex,strText); } } else { } if(lParam == FALSE) m_pComboBox->ShowWindow(SW_HIDE); } return 0; } #endif void CComboBoxListCtrl5::OnParentNotify(UINT message, LPARAM lParam) { CListCtrl::OnParentNotify(message, lParam); ////////////////////////////////////////////////////////////////////////// CHeaderCtrl* pHeaderCtrl = CListCtrl::GetHeaderCtrl(); if(pHeaderCtrl == NULL) return; CRect rcHeader; pHeaderCtrl->GetWindowRect(rcHeader); ScreenToClient(rcHeader); //The x coordinate is in the low-order word and the y coordinate is in the high-order word. CPoint pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); if(rcHeader.PtInRect(pt) && message == WM_LBUTTONDOWN) { if(m_pComboBox->m_hWnd != NULL) { DWORD dwStyle = m_pComboBox->GetStyle(); if((dwStyle&WS_VISIBLE) == WS_VISIBLE) { m_pComboBox->ShowWindow(SW_HIDE); } } if(m_DateCtrl.m_hWnd) { if(m_DateCtrl.IsWindowVisible ())m_DateCtrl.ShowWindow(SW_HIDE); } } } BOOL CComboBoxListCtrl5::PreTranslateMessage(MSG* pMsg) { /* if(pMsg->message == WM_LBUTTONUP) { if(m_DateCtrl.m_hWnd) { if(m_DateCtrl.IsWindowVisible ()) { ::PostMessage(this->GetSafeHwnd(),WM_USER_ComboBox_END,1,0); m_DateCtrl.ShowWindow(SW_HIDE); } } }*/ return CListCtrl::PreTranslateMessage(pMsg); } BOOL CComboBoxListCtrl5::Key_Shift(int& nItem,int& nSub) { int nItemCount = CListCtrl::GetItemCount(); DWORD dwData = m_pComboBox->GetCtrlData(); nItem= dwData>>16; nSub = dwData&0x0000ffff; CHeaderCtrl* pHeader = CListCtrl::GetHeaderCtrl(); if(pHeader == NULL) return FALSE; short sRet = GetKeyState(VK_SHIFT); int nSubcCount = pHeader->GetItemCount(); sRet = sRet >>15; if(sRet == 0) { nSub += 1; if(nSub >= nSubcCount) { if(nItem == nItemCount-1) { nItem = 0; nSub = 0; } else { nSub = 0; nItem += 1; } } if(nItem >= nItemCount) nItem = nItemCount-1; return FALSE; } else { nSub -= 1; if(nSub < 0) { nSub = nSubcCount -1; nItem --; } if(nItem < 0) nItem = nItemCount-1; return TRUE; } return FALSE; } BOOL CComboBoxListCtrl5::Key_Ctrl(int& nItem,int &nSub) { short sRet = GetKeyState(VK_CONTROL); DWORD dwData = m_pComboBox->GetCtrlData(); nItem= dwData>>16; nSub = dwData&0x0000ffff; sRet = sRet >>15; int nItemCount = CListCtrl::GetItemCount(); if(sRet == 0) { } else { nItem = nItem >=nItemCount-1? 0:nItem+=1; return TRUE; } return FALSE; } void CComboBoxListCtrl5::InitStyle() { SetFont (&g_listctrlfont); SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP); } #undef SubclassWindow void CComboBoxListCtrl5::PreSubclassWindow() { // the list control must have the report style. CListCtrl::PreSubclassWindow(); m_ctlHeader.SubclassWindow ( GetHeaderCtrl()->GetSafeHwnd()); }