Solved

GrayString in CDialog

Posted on 1997-04-01
6
491 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
mixString challenge 36 98
pre4 challenge 19 88
Execute multiple curl cmds with sleep and send output to file 10 80
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now