[英]Windows CE - disable CComboBox highlight
我正在使用Visual Studio 2008使用C ++和MFC為Windows CE 6編寫應用程序。
選擇元素后,我想刪除CComboBox派生類的藍色突出顯示。 根據此MSDN文章 ,我無法將組合框的樣式設置為LBS_OWNERDRAWFIXED或CBS_OWNERDRAWFIXED來在我的DrawItem函數上選擇選擇的顏色。
我嘗試使用消息CBN_SELCHANGE發送WM_KILLFOCUS消息。 它部分起作用:該控件失去了焦點(所選元素不再是藍色),但是如果再次單擊組合框,它不會顯示元素列表。
我讀過我可以使用paint事件設置突出顯示的顏色,但是我不知道或找不到如何執行此操作。
如何刪除組合框的藍色突出顯示?
編輯:組合框是只讀的(標志CBS_DROPDOWNLIST)
我發現了一個(骯臟的)workaroud,以防沒人能提供更好的方法:
創建組合框時設置了一個父級:
customCombo.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_DROPDOWN, CRect(0, 0, 0, 0), **PARENT**, COMBO_ID);
當我使用組合框完成操作時,以下幾行將焦點放在父元素上。
在CComboBox子類頭文件中:
public:
afx_msg void OnCbnSelchange();
afx_msg void OnCbnSelendcancel();
afx_msg void OnCbnSelendok();
在源文件中:
void CustomCombo::OnCbnSelchange() {
//give focus to parent
CWnd* cwnd = GetParent();
if (cwnd != NULL) {
cwnd->SetFocus();
}
}
void CustomCombo::OnCbnSelendcancel() {
//give focus to parent
CWnd* cwnd = GetParent();
if (cwnd != NULL) {
cwnd->SetFocus();
}
}
void CustomCombo::OnCbnSelendok() {
//give focus to parent
CWnd* cwnd = GetParent();
if (cwnd != NULL) {
cwnd->SetFocus();
}
}
在標題中:
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
在cpp中:
void CYourComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC* pDC = CDC::FromHandle (lpDrawItemStruct->hDC);
if (((LONG)(lpDrawItemStruct->itemID) >= 0) &&
(lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)))
{
// color item as you wish
}
if ((lpDrawItemStruct->itemAction & ODA_FOCUS) != 0)
pDC->DrawFocusRect(&lpDrawItemStruct->rcItem);
}
該模型是從這里獲取的:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.