// ComboBoxAuto.cpp : 自動補完コンボボックス // #include "stdafx.h" #include "ComboBoxAuto.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CComboBoxAuto CComboBoxAuto::CComboBoxAuto() { m_bAdd = true; m_bAuto = m_bDo = true; m_max = 10; } CComboBoxAuto::~CComboBoxAuto() { } CString CComboBoxAuto::toString()const { CString s; GetWindowText(s); return s; } CString CComboBoxAuto::GetAllString()const { CString t, s = toString(); int i, n = GetCount(); for (i=0;imessage == WM_KEYDOWN) { UINT nChar = pMsg->wParam; m_bDo = nChar != VK_DELETE && nChar != VK_BACK; } return CComboBox::PreTranslateMessage(pMsg); } void CComboBoxAuto::OnKillfocus() { if (!m_bAdd) return; CString s; GetWindowText(s); if (s.IsEmpty()) return; int i = FindStringExact(-1,s); if (i != CB_ERR) DeleteString(i); InsertString(0,s); SetWindowText(s); while ((i = GetCount()) > m_max) DeleteString(i-1); } void CComboBoxAuto::OnEditupdate() { if (!m_bAuto || !m_bDo) return; CString s; GetWindowText(s); int i = s.GetLength(); if (SelectString(-1,s) == CB_ERR) SetWindowText(s); SetEditSel(i,-1); } void CComboBoxAuto::OnDropFiles(HDROP hDropInfo) { int n; char buf[MAX_PATH+1]; n = ::DragQueryFile(hDropInfo,0xffffffff,buf,sizeof(buf)-1); if (n != 1) return; *buf = 0; ::DragQueryFile(hDropInfo,0,buf,sizeof(buf)-1); ::DragFinish(hDropInfo); SetWindowText(buf); } void CComboBoxAuto::OnDropdown() { OnKillfocus(); }