Solved

GrayString in CDialog

Posted on 1997-04-01
6
498 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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