www.pudn.com > shelllist.rar > MyCombo.cpp
/*--------------------------------------------------------
*Copyright 中国频道-厦门精通科技(www.china-channel.com)
*
* BY:张建新(zhangjx@china-channel.com)
*
*--------------------------------------------------------*/
/*---------------------------------------------------------
* 实现下拉框式的列表在位编辑
*--------------------------------------------------------*/
#include "stdafx.h"
#include "ClientFTP.h"
#include "MyCombo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyCombo
CMyCombo::CMyCombo()
{
m_bESC = FALSE;
m_bInplaceEdit = FALSE;
}
CMyCombo::~CMyCombo()
{
}
BEGIN_MESSAGE_MAP(CMyCombo, CComboBox)
//{{AFX_MSG_MAP(CMyCombo)
ON_WM_CHAR()
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_KILLFOCUS()
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyCombo message handlers
void CMyCombo::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(m_bInplaceEdit && (nChar == VK_ESCAPE || nChar == VK_RETURN))
{
if(nChar == VK_ESCAPE)
{
m_bESC = TRUE;
}
this->SendMessage(WM_CLOSE);
}
}
int CMyCombo::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CComboBox::OnCreate(lpCreateStruct) == -1)
return -1;
if(m_bInplaceEdit)
{
ASSERT(m_strList.GetCount() > 0);
for(POSITION pos = m_strList.GetHeadPosition() ; pos != NULL ; )
{
AddString((LPCTSTR)(m_strList.GetNext(pos)));
}
SetCurSel(0);
}
return 0;
}
void CMyCombo::OnDestroy()
{
CComboBox::OnDestroy();
if(m_bInplaceEdit)
{
CListCtrl& theCtrl = ((CListView*)GetParent())->GetListCtrl();
CString str;
GetWindowText(str);
LV_DISPINFO dispinfo;
dispinfo.hdr.hwndFrom = theCtrl.m_hWnd;
dispinfo.hdr.idFrom = GetDlgCtrlID();
dispinfo.hdr.code = LVN_ENDLABELEDIT;
dispinfo.item.mask = LVIF_TEXT;
dispinfo.item.iItem = theCtrl.GetNextItem(-1, LVNI_SELECTED);
dispinfo.item.iSubItem = 0;
dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
dispinfo.item.cchTextMax = str.GetLength();
GetParent()->SendMessage(WM_NOTIFY,
theCtrl.GetDlgCtrlID(), (LPARAM)&dispinfo);
}
}
void CMyCombo::OnKillFocus(CWnd* pNewWnd)
{
CComboBox::OnKillFocus(pNewWnd);
if(m_bInplaceEdit)
{
if(pNewWnd != this->GetParent())
{
OnDestroy();
}
}
}
void CMyCombo::OnSelchange()
{
int iSel = this->GetCurSel();
if(!m_bInplaceEdit)
{
GetParent()->SendMessage(MM_COMBO_SELCHANGE, iSel, this->GetDlgCtrlID());
}
}