Solved

GrayString in CDialog

Posted on 1997-04-01
6
500 Views
Last Modified: 2013-11-20
I have a CDialog class which contains a ListBox, scrollable,
and a Checkbutton. When the Checkbutton isn't checked
I want the ListBox to be Grayed. This shouldn't be so hard,
however the only function I can find is in the CDC class,
and can't? be implemented. However there are several solutions in the CDC class such as SetTextColor, and GrayString, eigther one will be to my fullest satisfaction!

The MyDialog is : public CDialog
and operating under .DoModal()

Good luck :)
0
Comment
Question by:CrypToniC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:MFCGuy
ID: 1300784
It sounds like you might just want the list box turned on/off by the check box.  If this is so, just use myCheckBox->EnableWindow(myCheckBox->GetCheck()==1) to turn it on or off in a handler for the CheckBox BN_CLICKED message through ClassWizard.

If what you really want is the CListBox to be disabled/grayed out, let me know and I'll do a search for some code...


0
 
LVL 1

Accepted Solution

by:
MFCGuy earned 50 total points
ID: 1300785
It sounds like you might just want the list box turned on/off by the check box.  If this is so, just use myCheckBox->EnableWindow(myCheckBox->GetCheck()==1) to turn it on or off in a handler for the CheckBox BN_CLICKED message through ClassWizard.

If what you really want is the CListBox to be disabled/grayed out, let me know and I'll do a search for some code...


0
 
LVL 1

Author Comment

by:CrypToniC
ID: 1300786
MFCGuy what I really wanted was the ListBox to be grayed out
but still readable & selectable ( but will follow now won't it )
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:MFCGuy
ID: 1300787
I'm sure there are a few ways to do this but here is one:

1. Create a new class derived from CListBox, perahps called
CGrayListBox.
2. Add a member variable like m_fReadOnly to the new class
to indicate whether or not to draw the list box gray.
2. Add a handler for the =WM_CTLCOLOR through ClassWizard
and set the colors you want, using the flag as decision maker:
HBRUSH CGrayListBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
      // TODO: Change any attributes of the DC here
      if(m_fReadOnly)
      {
            pDC->SetTextColor(RGB(128,128,128));
            pDC->SetBkMode(TRANSPARENT);
            return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
      }
      
      // TODO: Return a non-NULL brush if the parent's handler should not be called
      return NULL;
}
This will make the background of the listbox gray and the text gray with a clear background.
3. When the user checks/unchecks the checkbox that controls the graying of the new CGrayListBox class, set the m_fReadOnly flag
in CGrayListBox and cause a refresh, perhaps by using UpdateWindow():

In your dialog .cpp
-------------------
void OnClickMyCheckBox()
{
   m_GrayListBox->SetReadOnly(m_myCheckBox->GetCheck()==1);
}

In GrayListbox header:
----------------------
void SetReadOnly(BOOL flag){m_fReadOnly = flag;UpdateWindow();}

Hope that helps!
Let me know if you have any other questions.

Regards,
MFCGuy
0
 
LVL 1

Expert Comment

by:MFCGuy
ID: 1300788
>Yes, that will work. However the problem seem to be the
>CDC class, how can one access it?

I have no idea what you are talking about now...

You can always use GetDC() to get a CDC to a CFormView window,
if that is what you want.  What exactly are you trying to do,
access the CDC of a CListBox from your CFormView?  If so,
you do not want to do that, you should use a derived class
as I have outlined above.

Let me know,
MFCGuy  

0
 
LVL 1

Author Comment

by:CrypToniC
ID: 1300789
Hi,
well as it turns out the EnableWindow function almost
satisfies my problem, so I think I will stick with the current
solution. I didn't know that the EnableWindow function automatically "grayes" the text when disabled and I was so hung
up with the "gray" idea that I didn't even try the EnableWindow.
Thanks for all your help and sorry for wasting your time !
/CrypToniC
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question