How manage the lose focus from CListCtrl Control
-
Hi i am doing a program with a clistctrl with custom draw and i have custom highlight color bar. Now my problem is when i am with mouse on CListCtrl the bar is color i wish, when i leave to go on other control i don't know how change the color in gray of the highlight bar, i post the code for you:
void CPubFoldersView::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pCD = (NMLVCUSTOMDRAW*)pNMHDR;
int nRow = pCD->nmcd.dwItemSpec;
CListCtrl& m_MainTable = GetListCtrl();
CString szInEvidence;//Remove standard highlighting of selected (sub)item. pCD->nmcd.uItemState = CDIS\_DEFAULT; if (VirtualRowArray.GetCount()) szInEvidence=VirtualRowArray\[nRow\].Field\[4\]; switch(pCD->nmcd.dwDrawStage) { case CDDS\_PREPAINT: \*pResult = CDRF\_NOTIFYSUBITEMDRAW; break; case CDDS\_ITEMPREPAINT: \*pResult = CDRF\_NOTIFYSUBITEMDRAW; break; case CDDS\_ITEMPREPAINT|CDDS\_SUBITEM: { if (m\_MainTable.GetItemState(nRow, LVIS\_SELECTED)==LVIS\_SELECTED && m\_MainTable.GetItemState(nRow, LVIS\_FOCUSED)==LVIS\_FOCUSED) { pCD->clrTextBk = RGB(167,205,240); //Selected color \*pResult = CDRF\_NEWFONT; } if (m\_MainTable.GetItemState(nRow, LVIS\_SELECTED)==LVIS\_SELECTED && m\_MainTable.GetItemState(nRow, LVIS\_FOCUSED)!=LVIS\_FOCUSED) { pCD->clrTextBk = RGB(197, 206, 216); //Only focused color \*pResult = CDRF\_NEWFONT; } } break; default: \*pResult = CDRF\_DODEFAULT; }
}
-
Hi i am doing a program with a clistctrl with custom draw and i have custom highlight color bar. Now my problem is when i am with mouse on CListCtrl the bar is color i wish, when i leave to go on other control i don't know how change the color in gray of the highlight bar, i post the code for you:
void CPubFoldersView::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pCD = (NMLVCUSTOMDRAW*)pNMHDR;
int nRow = pCD->nmcd.dwItemSpec;
CListCtrl& m_MainTable = GetListCtrl();
CString szInEvidence;//Remove standard highlighting of selected (sub)item. pCD->nmcd.uItemState = CDIS\_DEFAULT; if (VirtualRowArray.GetCount()) szInEvidence=VirtualRowArray\[nRow\].Field\[4\]; switch(pCD->nmcd.dwDrawStage) { case CDDS\_PREPAINT: \*pResult = CDRF\_NOTIFYSUBITEMDRAW; break; case CDDS\_ITEMPREPAINT: \*pResult = CDRF\_NOTIFYSUBITEMDRAW; break; case CDDS\_ITEMPREPAINT|CDDS\_SUBITEM: { if (m\_MainTable.GetItemState(nRow, LVIS\_SELECTED)==LVIS\_SELECTED && m\_MainTable.GetItemState(nRow, LVIS\_FOCUSED)==LVIS\_FOCUSED) { pCD->clrTextBk = RGB(167,205,240); //Selected color \*pResult = CDRF\_NEWFONT; } if (m\_MainTable.GetItemState(nRow, LVIS\_SELECTED)==LVIS\_SELECTED && m\_MainTable.GetItemState(nRow, LVIS\_FOCUSED)!=LVIS\_FOCUSED) { pCD->clrTextBk = RGB(197, 206, 216); //Only focused color \*pResult = CDRF\_NEWFONT; } } break; default: \*pResult = CDRF\_DODEFAULT; }
}
Perhaps I misunderstand your problem, but it sounds like all you are missing is to check if the list control itself has focus. If it does, you set the color as you are doing now, otherwise you set the gray color. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
-
Perhaps I misunderstand your problem, but it sounds like all you are missing is to check if the list control itself has focus. If it does, you set the color as you are doing now, otherwise you set the gray color. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
-
Right. In that case the other control has the focus, not the list control. Note, that this is different than a row within the list control having the focus state. Your code for that could look something like this (I did not try to compile it so there might be errors):
case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
{
if (::GetFocus() != m_MainTable.m_hWnd)
{
pCD->clrTextBk = RGB(192, 192, 192); //Gray
*pResult = CDRF_NEWFONT;
}
else
{
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)==LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(167,205,240); //Selected color
*pResult = CDRF_NEWFONT;
}
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)!=LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(197, 206, 216); //Only focused color
*pResult = CDRF_NEWFONT;
}
}
break;
}Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
-
Right. In that case the other control has the focus, not the list control. Note, that this is different than a row within the list control having the focus state. Your code for that could look something like this (I did not try to compile it so there might be errors):
case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
{
if (::GetFocus() != m_MainTable.m_hWnd)
{
pCD->clrTextBk = RGB(192, 192, 192); //Gray
*pResult = CDRF_NEWFONT;
}
else
{
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)==LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(167,205,240); //Selected color
*pResult = CDRF_NEWFONT;
}
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)!=LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(197, 206, 216); //Only focused color
*pResult = CDRF_NEWFONT;
}
}
break;
}Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
-
You are a MASTER!!!! you solved me the problem THANKS THANKS!!!! :thumbsup::thumbsup::thumbsup:
:laugh: :laugh: :laugh: You are welcome. It is a pretty basic solution and you might end up expanding on it to handle certain cases, but if your requirements are as simple as you have described, it should work just fine. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty