As a best solution, you need to subclass edit control of (drop down) combo box.
To do this:
First, create a MFC class named CCaretlessCBEdit. Select CEdit as its base class.
class CCaretlessCBEdit : public CEdit
{
...
};
Then, put lines below into its class definition in the header file to handle the events WM_SETFOCUS and EM_SETSEL.
afx_msg void OnSetFocus(CWnd* pOldWnd);<br />
afx_msg LRESULT OnSetSel(WPARAM wParam, LPARAM lParam);
Then, add following lines to implementation file with message map entries.
BEGIN_MESSAGE_MAP(CCaretlessCBEdit, CEdit)
ON_WM_SETFOCUS()
ON_MESSAGE(EM_SETSEL, OnSetSel)
END_MESSAGE_MAP()
LRESULT CCaretlessCBEdit::OnSetSel(WPARAM wParam, LPARAM lParam)
{
LRESULT lRet = DefWindowProc(EM_SETSEL, wParam, lParam);
HideCaret();
return lRet;
}
void CCaretlessCBEdit::OnSetFocus(CWnd* pOldWnd)
{
CEdit::OnSetFocus(pOldWnd);
HideCaret();
}
Then add following lines inside OnInitDialog() function in your dialog that hosts combo box. Beware of IDC_YOURCOMBO1, replace it with your own.
BOOL CYourDlg::OnInitDialog()
{
...
CDialog::OnInitDialog();
CWnd* pWnd = GetDlgItem(IDC_YOURCOMBO1)->GetWindow(GW_CHILD);
if(pWnd->GetSafeHwnd())
m_ctrlCBEdit.SubclassWindow(pWnd->GetSafeHwnd());
...
}
Lastly, put following line somewhere within your dialog class definition.
CCaretlessCBEdit m_ctrlCBEdit;
Dont' forget to include new control's header file in your dialog's header file.
#include "CaretlessCBEdit.h"
PS. As a shorter solution, while handling the set focus notification of combo within dialog class without subclassing the edit control. After the control gets EM_SETSEL message when getting focus for the first time, caret would be still there.