Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How manage the lose focus from CListCtrl Control

How manage the lose focus from CListCtrl Control

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Drakesal
    wrote on last edited by
    #1

    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;
    }
    

    }

    S 1 Reply Last reply
    0
    • D Drakesal

      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;
      }
      

      }

      S Offline
      S Offline
      SoMad
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • S SoMad

        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

        D Offline
        D Offline
        Drakesal
        wrote on last edited by
        #3

        No i need to draw gray when i leave the row selected but i click on another control.

        S 1 Reply Last reply
        0
        • D Drakesal

          No i need to draw gray when i leave the row selected but i click on another control.

          S Offline
          S Offline
          SoMad
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • S SoMad

            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

            D Offline
            D Offline
            Drakesal
            wrote on last edited by
            #5

            You are a MASTER!!!! you solved me the problem THANKS THANKS!!!! :thumbsup::thumbsup::thumbsup:

            S 1 Reply Last reply
            0
            • D Drakesal

              You are a MASTER!!!! you solved me the problem THANKS THANKS!!!! :thumbsup::thumbsup::thumbsup:

              S Offline
              S Offline
              SoMad
              wrote on last edited by
              #6

              :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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups