Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

144 lines
3.3 KiB
C++

// InputCombo.cpp : implementation file
//
#include "stdafx.h"
#include "NewUI.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInputCombo
IMPLEMENT_DYNAMIC(CInputCombo, CComboBox)
CInputCombo::CInputCombo()
{
}
CInputCombo::~CInputCombo()
{
}
BEGIN_MESSAGE_MAP(CInputCombo, CComboBox)
//{{AFX_MSG_MAP(CInputCombo)
ON_CONTROL_REFLECT(CBN_EDITCHANGE, OnEditchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CInputCombo::OnEditchange()
{
CString text;
GetWindowText(text);
int newPos=FindString(-1,text);
if (newPos!=-1)
{
if (!GetDroppedState())
{
CString text1;
GetLBText(newPos,text1);
DWORD pos=GetEditSel();
ShowDropDown();
SetWindowText(text1);
SetEditSel(HIWORD(pos),text1.GetLength());
}
}
else if (GetDroppedState())
ShowDropDown(false);
}
BOOL CInputCombo::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==WM_KEYDOWN)
{
int nVirtKey = (int)pMsg->wParam;
CString text1,text;
GetWindowText(text);
if (GetDroppedState()&&(nVirtKey==VK_RETURN||nVirtKey==VK_TAB))
{
int newPos=FindString(-1,text);
if (newPos>=0)
GetLBText(newPos ,text1);
ShowDropDown(false);
if (text1==text)
SetCurSel(newPos);
else
{
InsertString(newPos,text);
SetCurSel(newPos);
}
return true;
}
}
return CComboBox::PreTranslateMessage(pMsg);
}
///////////////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CUIDlg, CModelessDialog)
CUIDlg::CUIDlg(UINT id, CWnd* pParent /*=NULL*/)
: CModelessDialog(id, pParent),tipToolColor(RGB(0,0,200))
{
}
BEGIN_MESSAGE_MAP(CUIDlg, CModelessDialog)
//{{AFX_MSG_MAP(CObjPreviewDlg)
ON_WM_DESTROY()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CUIDlg::OnInitDialog()
{
CModelessDialog::OnInitDialog();
m_wndToolTip.Create(this);
m_wndToolTip.Activate(true);
m_wndToolTip.SetMaxTipWidth(250);
m_wndToolTip.SetDelayTime(TTDT_AUTOPOP, 4*m_wndToolTip.GetDelayTime(TTDT_AUTOPOP));
return TRUE;
}
void CUIDlg::OnDestroy()
{
m_wndToolTip.DestroyWindow();
CModelessDialog::OnDestroy();
}
BOOL CUIDlg::PreTranslateMessage(MSG* pMsg)
{
CToolInfo toolInfo;
if (pMsg->message >= WM_MOUSEFIRST &&
pMsg->message <= WM_MOUSELAST&&m_wndToolTip.GetToolInfo(toolInfo,FromHandle(pMsg->hwnd)))
{
MSG msg;
memcpy(&msg, pMsg, sizeof(MSG));
m_wndToolTip.RelayEvent(&msg);
}
return CModelessDialog::PreTranslateMessage(pMsg);
}
BOOL CUIDlg::AddTip(UINT idControl,const TCHAR *str)
{
CWnd *pWnd = GetDlgItem(idControl);
if (!pWnd)
return FALSE;
if (str==NULL)
{
HINSTANCE hInstance=AfxGetInstanceHandle();
int nRet;
CString strTip;
if (!hInstance)
nRet=strTip.LoadString(idControl);
else
{
TCHAR szTemp[1024]=_T("");
nRet=::LoadString(hInstance, idControl, szTemp, 1024);
if (nRet)
strTip=szTemp;
}
if (nRet)
return m_wndToolTip.AddTool(pWnd,strTip)!=0;
}
return m_wndToolTip.AddTool(pWnd,str)!=0;
}
HBRUSH CUIDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CModelessDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->IsWindowEnabled())
{
CToolInfo toolInfo;
if (m_wndToolTip.GetToolInfo(toolInfo, pWnd))
pDC->SetTextColor(tipToolColor);
}
return hbr;
}