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. Clistbox greying

Clistbox greying

Scheduled Pinned Locked Moved C / C++ / MFC
5 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.
  • S Offline
    S Offline
    SVPG
    wrote on last edited by
    #1

    How do a grey a CListBox based on some option , say option A the ListBox should be enabled with Window color as bg for option B, the listbox should be disabled with btn face color and all list items also greyed..like a greyed edit box PS its CListBox not a CListCtrl

    S 1 Reply Last reply
    0
    • S SVPG

      How do a grey a CListBox based on some option , say option A the ListBox should be enabled with Window color as bg for option B, the listbox should be disabled with btn face color and all list items also greyed..like a greyed edit box PS its CListBox not a CListCtrl

      S Offline
      S Offline
      sps itsec46
      wrote on last edited by
      #2

      I don't know if I exactly understood what you want to do, but if you want to enable or disable the control you can use the EnableWindow() function, e.g.:

      void EnableMyListBox()
      {
      myListBox.EnableWindow(TRUE);
      }

      void DisableMyListBox()
      {
      myListBox.EnableWindow(FALSE);
      }

      When you disable the listbox it will be grayed out. Hope it'll help! Regards, mYkel

      S 1 Reply Last reply
      0
      • S sps itsec46

        I don't know if I exactly understood what you want to do, but if you want to enable or disable the control you can use the EnableWindow() function, e.g.:

        void EnableMyListBox()
        {
        myListBox.EnableWindow(TRUE);
        }

        void DisableMyListBox()
        {
        myListBox.EnableWindow(FALSE);
        }

        When you disable the listbox it will be grayed out. Hope it'll help! Regards, mYkel

        S Offline
        S Offline
        SVPG
        wrote on last edited by
        #3

        True, but I want the background to be greyed as well. If I do a fillrect with a brush (COLOR_BTNFACE), EnableWindow(FALSE) still causes it to have a white background even though the listbox is disabled.

        R S 2 Replies Last reply
        0
        • S SVPG

          True, but I want the background to be greyed as well. If I do a fillrect with a brush (COLOR_BTNFACE), EnableWindow(FALSE) still causes it to have a white background even though the listbox is disabled.

          R Offline
          R Offline
          Robert A T Kaldy
          wrote on last edited by
          #4

          See CWnd::OnCtlColor() documentation. I don't have experiences with it but, it could solve your problem. Robert-Antonio "CRAY is the only computer, which runs an endless loop in just 4 hours"

          1 Reply Last reply
          0
          • S SVPG

            True, but I want the background to be greyed as well. If I do a fillrect with a brush (COLOR_BTNFACE), EnableWindow(FALSE) still causes it to have a white background even though the listbox is disabled.

            S Offline
            S Offline
            sps itsec46
            wrote on last edited by
            #5

            As another poster said you can use the OnCtlColor() method for this. Assuming you have a button for changing between the grayed and not grayed state like this:

            void CListBoxGrayingTestDlg::OnButtonGray()
            {
            // TODO: Add your control notification handler code here

            if(m\_bGrayed)
            {
                m\_bGrayed = FALSE;
                m\_MyListBox.EnableWindow(TRUE);
            }
            else
            {
                m\_bGrayed = TRUE;
                m\_MyListBox.EnableWindow(FALSE);
            }
            

            }

            Adding a message handler for WM_CTLCOLOR you can now do something like this:

            HBRUSH CListBoxGrayingTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
            {
            HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
             
            // TODO: Change any attributes of the DC here
             
            // Set background transparent
            pDC->SetBkMode(TRANSPARENT);
             
            if (pWnd->GetDlgCtrlID() == IDC_MYLISTBOX)
            {
            if(m_bGrayed)
            return (HBRUSH)GetStockObject(GRAY_BRUSH);
            else
            return (HBRUSH)GetStockObject(WHITE_BRUSH);
            }
             
            // TODO: Return a different brush if the default is not desired
            return hbr;
            }

            Now the background will be grayed, when the control is disabled... ;) Regards, mYkel

            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