Solved

GrayString in CDialog

Posted on 1997-04-01
6
494 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
unable to delete all specified values regedit 38 270
Window placement 17 73
How to convert MFC::CString to UTF8 wchar_t* 10 137
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

937 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

10 Experts available now in Live!

Get 1:1 Help Now