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. CTreeCtrl get individual item font ?

CTreeCtrl get individual item font ?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
6 Posts 3 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.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    I'm setting a CTreeCtrl item item font to Italic by handling the NM_CUSTOMDRAW message and setting the font with SelectObject. This is working.

    void MyTree::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
    {
    NMTVCUSTOMDRAW *itemToDraw = reinterpret_cast<NMTVCUSTOMDRAW*>>(pNMHDR);

    switch (itemToDraw->nmcd.dwDrawStage)
    {
    case CDDS\_PREPAINT:
    	\*pResult = CDRF\_NOTIFYITEMDRAW;
    	return;
    case CDDS\_ITEMPREPAINT:
    {
    	HTREEITEM item = reinterpret\_cast<HTREEITEM>(itemToDraw->nmcd.dwItemSpec);
    
    	if (!m\_IsItalicFontCreated) //Create once the italic font
    	{
    		CFont\* currentFont = GetFont();
    		LOGFONT logfont;
    		currentFont->GetLogFont(&logfont);
    		logfont.lfItalic = TRUE;
    		m\_ItalicFont.CreateFontIndirect(&logfont);
    		m\_IsItalicFontCreated = true;
    	}
    
    	if (m\_IsItalicFontCreated)
    	{
    		::SelectObject(itemToDraw->nmcd.hdc, m\_ItalicFont);
    		\*pResult = CDRF\_NEWFONT;
    	}
    }
    return;
    }
    
    \*pResult = 0;
    

    }

    But at some point I need to check an item current font; to see if a tree item is in italic. The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item. Is it possible to do it ? I can't see in the documentation anything I can use. There is a lItemlParam in the NMCUSTOMDRAW struct, I'm not certain if I could use this to some some simple data ? or even if it is persistent. Any suggestions ? Thanks.

    I'd rather be phishing!

    V M 3 Replies Last reply
    0
    • M Maximilien

      I'm setting a CTreeCtrl item item font to Italic by handling the NM_CUSTOMDRAW message and setting the font with SelectObject. This is working.

      void MyTree::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
      {
      NMTVCUSTOMDRAW *itemToDraw = reinterpret_cast<NMTVCUSTOMDRAW*>>(pNMHDR);

      switch (itemToDraw->nmcd.dwDrawStage)
      {
      case CDDS\_PREPAINT:
      	\*pResult = CDRF\_NOTIFYITEMDRAW;
      	return;
      case CDDS\_ITEMPREPAINT:
      {
      	HTREEITEM item = reinterpret\_cast<HTREEITEM>(itemToDraw->nmcd.dwItemSpec);
      
      	if (!m\_IsItalicFontCreated) //Create once the italic font
      	{
      		CFont\* currentFont = GetFont();
      		LOGFONT logfont;
      		currentFont->GetLogFont(&logfont);
      		logfont.lfItalic = TRUE;
      		m\_ItalicFont.CreateFontIndirect(&logfont);
      		m\_IsItalicFontCreated = true;
      	}
      
      	if (m\_IsItalicFontCreated)
      	{
      		::SelectObject(itemToDraw->nmcd.hdc, m\_ItalicFont);
      		\*pResult = CDRF\_NEWFONT;
      	}
      }
      return;
      }
      
      \*pResult = 0;
      

      }

      But at some point I need to check an item current font; to see if a tree item is in italic. The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item. Is it possible to do it ? I can't see in the documentation anything I can use. There is a lItemlParam in the NMCUSTOMDRAW struct, I'm not certain if I could use this to some some simple data ? or even if it is persistent. Any suggestions ? Thanks.

      I'd rather be phishing!

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      You could implement the method in your MyTree class that would return true if italic font was created. Something like

      bool MyTree::IsItalicFontCreated()
      {
      return m_IsItalicFontCreated;
      }

      M 1 Reply Last reply
      0
      • M Maximilien

        I'm setting a CTreeCtrl item item font to Italic by handling the NM_CUSTOMDRAW message and setting the font with SelectObject. This is working.

        void MyTree::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
        {
        NMTVCUSTOMDRAW *itemToDraw = reinterpret_cast<NMTVCUSTOMDRAW*>>(pNMHDR);

        switch (itemToDraw->nmcd.dwDrawStage)
        {
        case CDDS\_PREPAINT:
        	\*pResult = CDRF\_NOTIFYITEMDRAW;
        	return;
        case CDDS\_ITEMPREPAINT:
        {
        	HTREEITEM item = reinterpret\_cast<HTREEITEM>(itemToDraw->nmcd.dwItemSpec);
        
        	if (!m\_IsItalicFontCreated) //Create once the italic font
        	{
        		CFont\* currentFont = GetFont();
        		LOGFONT logfont;
        		currentFont->GetLogFont(&logfont);
        		logfont.lfItalic = TRUE;
        		m\_ItalicFont.CreateFontIndirect(&logfont);
        		m\_IsItalicFontCreated = true;
        	}
        
        	if (m\_IsItalicFontCreated)
        	{
        		::SelectObject(itemToDraw->nmcd.hdc, m\_ItalicFont);
        		\*pResult = CDRF\_NEWFONT;
        	}
        }
        return;
        }
        
        \*pResult = 0;
        

        }

        But at some point I need to check an item current font; to see if a tree item is in italic. The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item. Is it possible to do it ? I can't see in the documentation anything I can use. There is a lItemlParam in the NMCUSTOMDRAW struct, I'm not certain if I could use this to some some simple data ? or even if it is persistent. Any suggestions ? Thanks.

        I'd rather be phishing!

        M Offline
        M Offline
        Member_14555070
        wrote on last edited by
        #3

        Hello, I also have the same issues, I need to set CTreeCtrl item. ______________________[

        Gmail Klantenservice

        ](https://www.klantenservicebelgies.com/gmail-contact/)

        1 Reply Last reply
        0
        • M Maximilien

          I'm setting a CTreeCtrl item item font to Italic by handling the NM_CUSTOMDRAW message and setting the font with SelectObject. This is working.

          void MyTree::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
          {
          NMTVCUSTOMDRAW *itemToDraw = reinterpret_cast<NMTVCUSTOMDRAW*>>(pNMHDR);

          switch (itemToDraw->nmcd.dwDrawStage)
          {
          case CDDS\_PREPAINT:
          	\*pResult = CDRF\_NOTIFYITEMDRAW;
          	return;
          case CDDS\_ITEMPREPAINT:
          {
          	HTREEITEM item = reinterpret\_cast<HTREEITEM>(itemToDraw->nmcd.dwItemSpec);
          
          	if (!m\_IsItalicFontCreated) //Create once the italic font
          	{
          		CFont\* currentFont = GetFont();
          		LOGFONT logfont;
          		currentFont->GetLogFont(&logfont);
          		logfont.lfItalic = TRUE;
          		m\_ItalicFont.CreateFontIndirect(&logfont);
          		m\_IsItalicFontCreated = true;
          	}
          
          	if (m\_IsItalicFontCreated)
          	{
          		::SelectObject(itemToDraw->nmcd.hdc, m\_ItalicFont);
          		\*pResult = CDRF\_NEWFONT;
          	}
          }
          return;
          }
          
          \*pResult = 0;
          

          }

          But at some point I need to check an item current font; to see if a tree item is in italic. The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item. Is it possible to do it ? I can't see in the documentation anything I can use. There is a lItemlParam in the NMCUSTOMDRAW struct, I'm not certain if I could use this to some some simple data ? or even if it is persistent. Any suggestions ? Thanks.

          I'd rather be phishing!

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Maximilien wrote:

          The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item.

          You could extend your data adding the font type (create a struct containing all the necessary data and set the pointer to the struct instance as an ItemData)

          M 1 Reply Last reply
          0
          • V Victor Nijegorodov

            You could implement the method in your MyTree class that would return true if italic font was created. Something like

            bool MyTree::IsItalicFontCreated()
            {
            return m_IsItalicFontCreated;
            }

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            That only tells me the font is created, but not if it was set to one particular tree item.

            I'd rather be phishing!

            1 Reply Last reply
            0
            • V Victor Nijegorodov

              Maximilien wrote:

              The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item.

              You could extend your data adding the font type (create a struct containing all the necessary data and set the pointer to the struct instance as an ItemData)

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              Yes, I'm looking into that. Thanks. :thumbsup:

              I'd rather be phishing!

              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