📄 mycombobox.cpp
字号:
#include "stdafx.h"
#include "Sys.h"
#include "MyComboBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyComboBox
CMyComboBox::CMyComboBox(int iItem, int iSubItem, CString sInitText)
{
m_iItem = iItem;
m_iSubItem = iSubItem;
m_bESC = FALSE;
}
CMyComboBox::CMyComboBox()
{
}
CMyComboBox::~CMyComboBox()
{
}
BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
//{{AFX_MSG_MAP(CMyComboBox)
ON_WM_KILLFOCUS()
ON_WM_CHAR()
ON_WM_NCDESTROY()
ON_WM_CREATE()
ON_WM_SETTINGCHANGE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyComboBox message handlers
void CMyComboBox::OnKillFocus(CWnd* pNewWnd)
{
CComboBox::OnKillFocus(pNewWnd);
CString str;
GetWindowText(str);
LV_DISPINFO dispinfo;
dispinfo.hdr.hwndFrom=GetParent()->m_hWnd;
dispinfo.hdr.idFrom=GetDlgCtrlID();
dispinfo.hdr.code=LVN_ENDLABELEDIT;
dispinfo.item.iItem=m_iItem;
dispinfo.item.iSubItem=m_iSubItem;
dispinfo.item.pszText=m_bESC?NULL:LPTSTR((LPCTSTR)str);
dispinfo.item.cchTextMax=str.GetLength();
GetParent()->GetParent()->SendMessage(WM_NOTIFY,GetParent()->GetDlgCtrlID(),
(LPARAM)&dispinfo);
GetParent()->UpdateWindow ();
GetParent()->SetFocus();
DestroyWindow();
// TODO: Add your message handler code here
}
void CMyComboBox::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if (nChar==VK_ESCAPE||nChar==VK_RETURN)
{
if(nChar==VK_ESCAPE)
m_bESC=TRUE;
GetParent()->SetFocus();
return;
}
CComboBox::OnChar(nChar, nRepCnt, nFlags);
}
void CMyComboBox::OnNcDestroy()
{
CComboBox::OnNcDestroy();
delete this;
// TODO: Add your message handler code here
}
int CMyComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CComboBox::OnCreate(lpCreateStruct) == -1)
return -1;
CFont* font=GetParent()->GetFont();
SetFont(font);
SetWindowText(m_sInitText);
SetFocus();
// SetSel( 0, -1 );
SetFocus ();
// TODO: Add your specialized creation code here
return 0;
}
void CMyComboBox::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
{
CComboBox::OnSettingChange(uFlags, lpszSection);
// TODO: Add your message handler code here
}
void CMyComboBox::SetParaNum(int iItem, int iSubItem, CString sInitText)
{
m_iItem = iItem;
m_iSubItem = iSubItem;
m_bESC = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -