CDialog background color

Hello,

How can change the background colour of a dialog programmatically?



Best regards


0
ma1 (15)
11/26/2004 10:18:04 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1492 Views

Similar Articles

[PageSpeed] 15

>How can change the background colour of a dialog programmatically?

Handle the WM_CTLCOLORDLG message (OnCtlColor CTLCOLOR_DLG  in MFC)
and return a brush of the colour you want.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
11/26/2004 10:55:24 PM
Thanks but it didn't work!
here is the code that I wrote:

HBRUSH CDialogAppCon::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

 // TODO: Change any attributes of the DC here

 // TODO: Return a different brush if the default is not desired
 if(nCtlColor==CTLCOLOR_DLG)
 {
  CBrush NewBrush;
  NewBrush.CreateSolidBrush(0xFF);
  return NewBrush;
 }
 return hbr;

}

Any suggestion?

Best regards




"David Lowndes" <davidl@example.invalid> wrote in message
news:7ucfq0tstgvoaj8hjnhfl0cosd4b6n7eoh@4ax.com...
> >How can change the background colour of a dialog programmatically?
>
> Handle the WM_CTLCOLORDLG message (OnCtlColor CTLCOLOR_DLG  in MFC)
> and return a brush of the colour you want.
>
> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq


0
Not8778 (2)
11/27/2004 12:58:59 AM
"MA" <Not@Known.com> wrote in message
news:eZ$YJxB1EHA.1296@TK2MSFTNGP10.phx.gbl...
> Thanks but it didn't work!
> here is the code that I wrote:
>
> HBRUSH CDialogAppCon::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
> {
>  HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
>
>  // TODO: Change any attributes of the DC here
>
>  // TODO: Return a different brush if the default is not desired
>  if(nCtlColor==CTLCOLOR_DLG)
>  {
>   CBrush NewBrush;
>   NewBrush.CreateSolidBrush(0xFF);
>   return NewBrush;
>  }
>  return hbr;
>
> }

Try making your CBrush a member of the CDialog class. As it is now, its dtor
executes -- destroying the HBRUSH, as soon as your handler returns. Also,
you might consider using the RGB macro.
-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
11/27/2004 3:41:36 AM
MA

you can not do it that way - the HBRUSH object that you *returned* was
destroyed when the function returned - the CBrush destructor will call
::DeleteObject on the underlying HBRUSH.

Move the CBrush NewBrush to the class definition.  Move the
NewBrush.CreateSolidBrush to the class constructor.

Then you have something like this:
/* ****************************** */
class CDialogAppCon: public CDialog
{
....
private:
 COLORREF clrBackColor;
 CBrush brMyColor;
....
};

/* ****************************** */
CDialogAppCon::CDialogAppCon(CWnd* pParent /*=NULL*/)
 : CDialog(CDialogAppCon::IDD, pParent)
{
 clrBackColor = RGB(128,255,255);
 brMyColor.CreateSolidBrush(clrBackColor);
}


/* ****************************** */
HBRUSH CDialogAppCon::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
 if(nCtlColor == CTLCOLOR_DLG) return brMyColor;
 else return hbr;
}

regards
roy fine


0
rlfine8815 (162)
11/27/2004 4:12:43 AM
Reply:

Similar Artilces:

MSChart Background Color
I am looking to set the background color of a MSChart to white. I see VB examples on the internet but have not been able to do the same in VC++. It seems as if I need to use the backdrop but when I call m_chtProfile.get_Backdrop(); I get a return of a LPDispatch and I am not sure what to do next. Any help would be appreciated. Michael Fox ...

Changing an MFC CDialog to a control inside another CDialog
Hi everyone, In my MFC application i have a CDialog window which is shown (modal) when clicking on a specific button. After some changes in my application, I decided that I need the controls on that secondary CDialog to be shown always inside the main window. Is there a way to change the secondary CDialog derived window to a control (like CStatic, etc) inside my main window, and not a child window? Maybe changing the devired class (CDialog to CStatic)? or changing some properties in the CDialog and calling its Create method with a specific parameters? Thanks. Menny wrote: > Hi everyone,...

Bar chart fill color selection from reference to cell data
Is there a way to create a bar chart and have the colors be selected from data adjacent to the plotted data? Or is there a macro that can select cells which can change the color of the fill/texture? Darryl - You can set up formulas that split your data into columns based on the value in a reference column, then plot different series, each formatted to differentiate them from each other. I have a couple of conditional charting examples linked to this page: http://www.geocities.com/jonpeltier/Excel/Charts/format.html My examples use the values as the reference that splits the data ...

XP-Theme won't fill the whole background in my app
I try to use WinXP Visual styles in my app. I did what the instruction tells in this link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwxp/html/xptheming.asp It went well except for one thing: The background was not colored in the bottom. On the bottom, the background color was white. It should have been light gray. Does anyone have a solution for this problem? Thanks in advance :) Kjetil Salomonsen wrote: > I try to use WinXP Visual styles in my app. I did what the instruction > tells in this link: > > http://msdn.microsoft.com/library/default.asp?...

Changing the color of a cell
Is there any way to program it so a cell changes color based on the value in the cell, ie the value is <10 the cell is blue the value <20 its red etc thanks Hi Nigel, Try using Format/Conditional Formatting/ you can then input your conditions and the color you want the cell to change to based on the user input. Copy the formatting down throughout the entire range you want impacted. HTH >-----Original Message----- >Is there any way to program it so a cell changes color >based on the value in the cell, > >ie the value is <10 the cell is blue >the value <...

Auto change color for numbers choosen
I was wondering if there is a way or formula for when I pick a certain number it automatically changes color to red from black when I enter data. Take a look at Conditional Formatting in XL Help. In article <a92f2b78.0408300729.57517fdf@posting.google.com>, vile5@comcast.net (Vile) wrote: > I was wondering if there is a way or formula for when I pick a certain > number it automatically changes color to red from black when I enter > data. ...

Black Background
I'm creating a pdf from Excel (2003) and I keep getting a black background, so I can't see the text. There are email links in the file (it's a contact list) and they show up as blue which I can live with. The cells have no colouring or background applied. It's all white and the text is black. Any thoughts? Excel 2003, Acrobat 6 and Windows XP Pro. Thanks in advance. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.722 / Virus Database: 478 - Release Date: 7/18/2004 ...

Dialog Background Color not Refreshing
Hello all... hope you can help -- burned through like 5 hours and no progress.... VC++ 6.0: I am changing a dialog background to red when another dialog in my program is open. Then when the popup window has closed, the background of the base dialog goes back to its original gray color. Well, my solution almost works except 1/2 of the base dialog will not change to red or back to it's original color unless you wipe over it with a dialog somewhere else on the desktop... this seems to invalidate the rest of the region and it repaints that part of the dialog correctly. I have tried...

Excel color pull down does not have some stanard color
Hi All One of my excel file in Excel 95 , then save to Excel 2003. Today I found that some standard color missing in pull donw color box. Such as Orange. For new create file have 40 standard color. Some color when mouse move up shown "color scheme" Do you know how to restore those missing color ? My Excel file have Module and Class. moonhk Tools>Options>Color>Reset HTH Bob "moonhkt" <moonhkt@gmail.com> wrote in message news:fafe8fd3-6b9e-43f6-b1c0-13f1c17679b9@l12g2000prg.googlegroups.com... > Hi All > > One of my ...

Creating a CDialog derived class for a Dialog??
I am trying to convert a project from Win32 to MFC. I created a new dialog resource, but when I try to do the right-click add class thing from the dialog editor, it doesn't do anything. I am using VS.NET 2003 Pro. In the dialog that pops up to create the new class, I change it to derive from CDialog, it already has the ID for my dialogbox resource selected, and I enter a new class name, and it generates the .h and .cpp names. I click Finish and NOTHING happens. I try it again from the main menu, but this time it pops an error box saying "Object Required". I am stumpe...

CEdit Background
When I make CEdit class Read Only, the background turns grey. How can I make it Read Only and have a white background? (Much like the compilation output window in VS Studio). Thanks. Jess You need to handle WM_CTLCOLORSTATIC for a readonly edit control. ----- Ajay Kalra ajaykalra@yahoo.com maybe WM_CTLCOLOREDIT "Ajay Kalra" <ajaykalra@yahoo.com> ??????:1142196362.062801.264450@j33g2000cwa.googlegroups.com... > You need to handle WM_CTLCOLORSTATIC for a readonly edit control. > > ----- > Ajay Kalra > ajaykalra@yahoo.com > WM_CTLCOLOREDIT does not w...

CDialog
hi i want to create an open dialog box to select a folder When i used CFileDialog i could open only a file. CFileDialog cfdOpen(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL,NULL); priya Hi priya To select a folder don't use CFileDialog use SHBrowseForFolder shell API. here is just an example BROWSEINFO bi; LPITEMIDLIST pidl; bi.hwndOwner = m_hWnd; bi.pidlRoot = NULL; bi.pszDisplayName = dir; bi.lpszTitle = dlgTitle; bi.ulFlags = BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = 0; pidl = SHBrowseForFolder(&a...

How to DoModal a CDialog initially invisible
Hi all, Under specific circunstances, I need to start my dialog-based app invisible. Unfortunately, as expected, when I call DoModal, the window is always visible, whatever I do (uncheck the visible box on dialog properties in the resources, ModifyStyle in OnInitDialog, ...) Is there a clean way to do that ? If not, what could be the cleanest dirty way ? ;) Thanks. -- Dansk Just don't call DoModal(). Place the code that you need to execute into a separate function in the same dialog class and call that function. class MyDialog : public CDialog { public: MyDialog() : CDia...

Red text or background if control contains a certain value?
I have a datasheet form based on a query where one of the fields/controls is concatenated (in the source query), displaying the invoice numbers for an order and following each number, whether it has been paid or not. This can be a combination of values e.g. "7828 (Paid), 7844 (Not Paid)" If the control contains an instance of (Not Paid) I would like either the text or the background colour of the control (either would be fine) to be red. I have tried using Conditional Formatting but could not work out how to express if the field value "contains" (Not Paid) - i...

Background Internet Update does not work
In Money 2004 as soon as I started Money, it launched the background updates - program, quotes, bank balances. In Money 2007 no matter what setting I have (using Passport and daily updates), it does not happen, I manually have to click "Update now". This is anything but automatic background download - am I missing something? Thanks for any advice, Zoli Hi. I too have the same problem in Money 2006. I always have to press "Update Now" to update my accounts. It would be great if someone knows a way to fix this for both 2006 and 2007! "Zoli" <zolist@gm...

count colored rows
I have a large spreadsheet where certain rows are colored red. I would like to sort on one column, then total the number of red rows in that group as well as obtain a grand total of the number of red lines. How do I accomplish this? Thank you in advance for your help to an Excel novice. See http://www.xldynamic.com/source/xld.ColourCounter.html -- HTH RP (remove nothere from the email address if mailing direct) "NoviceLois" <NoviceLois@discussions.microsoft.com> wrote in message news:A6043B6B-67EC-496F-A319-C81498705058@microsoft.com... > I have a large spreadsh...

how do I create a transparent image in the background?
How do I create a transparent image in Publisher 2000 with text flowing over the image, allowing the image to be seen in the background? Thanks anna Make the Text Frame transparent by going Ctrl+T -- ...

CView VS CDialog
Hello, Can i create some CView on CDialog Object ?? How can i do it ?? thanks. "Ahryman40k" <gbaudin2@wanadoo.fr> wrote in message news:bmefmd$3sv$1@news-reader5.wanadoo.fr... > Hello, > > Can i create some CView on CDialog Object ?? > > How can i do it ?? > > thanks. I'm assuming you mean creating a view as a control on a dialog. It can be done with MFC 6.0, but Microsoft almost certainly doesn't support it and you may find it can't be done in a later version of MFC. Your view needs to override OnMouseActivate so that it doesn'...

Transparent Background on Radio Buttons
<second attempt to post> I have several radio buttons on my form that are within a table cell with a colored background. I went into Design Mode and looked the properties of my radio buttons. I set the BackStyle value to "0 - fmBackStyleTransparent" and while in Design Mode everything looks fine. When I click out of Design Mode, the white background around the radio buttons reappears! The form prints okay, but some users will fill out the form electronically. I don't want to leave the file in Design mode (in fact, I'd like to protect it) but I ne...

Ivy color scheme
Greetings Can anyone tell me the colors (hex values) used in the ivy color scheme in publisher? I do not have publisher. Thanks Albatross I don't have the hex values but I did do the work for the RGB numbers. (I'm kinda surprised I'd do this much work for something this strange.) If you don't have Publisher, how do you know about the Ivy scheme? If it was through an acquaintance, why not ask the friend? Main - black Accent 1: R-51, G-102, B-0 Accent 2: R-204, G-204, B-153 Accent 3: R-214, G-224, B-214 Accent 4: R-204, G-204, B-204 Hyperlink: R-51, G-153, B-0 Followed link:...

Driver for "Generic Color PS for Commercial Printing" in Publisher 2003 and Win 7, X64
Hello Listis, until last week I used with Publisher 2003 under WIN XP, X32 with the Postscript Printer as above mentioned. Now I have WIN 7, X64 installed but it isn't possible to install the Printer "Generic Color PS for Commercial Printing" with MSCOL11.INF. How can i install this printer or a similar printer? Thanks Josef ...

Independant Modeless CDialog
Hi, I am having some serious difficulty with a problem of multiple windows in the same application. I use a CDialog as my main window, which is created in the main app call with DoModal, from it however, I wish to create several dialogs that are modeless, each has a taskbar entry (somewhat like MSN messenger) - However, whenever I click on any of these windows the entire job lot pops up, including my origional window. I know in VB that everything was pretty independant, you could switch between windows at your chosing, and only toolbar windows would pop up, thats kind of what I am aft...

Adding JPG image to resource Changes its color
Hi, I have tried to add the JPG images to the resource script. but when I export this images back it gives image with less color. Why So? I need to have JPG images with the application, I do not wish to have relative path ? Please let me know the possible solution for this Thanks Anup The Visual Studio IDE doesn't display graphics correctly if they have more than 256 colors or the pallette is non-standard. You can still use them, you just can't modify them or display them in the IDE. You need to import the graphic items rather than using something like cut and paste to ad...

Trouble with CDialog DoModal()
I created a new dialog with two buttons and a richedit area. I used the wizard to create a new class and the code. Now, I got: ///////////////////////////////////////////////////////////////////////////// // CStatDialog dialog CStatDialog::CStatDialog(CWnd* pParent /*=NULL*/) : CDialog(CStatDialog::IDD, pParent) { //{{AFX_DATA_INIT(CStatDialog) m_StatisticText = _T(""); //}}AFX_DATA_INIT } void CStatDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStatDialog) DDX_Text(pDX, IDC_RICHEDIT1, m_StatisticText); //}}AFX_DATA_MAP } ...

Embed a CFrameWnd into a CDialog
I would like to embed a CFrameWnd into a CDialog. That is, when the CDialog is moved or minimized, the CFrameWnd will also be moved and minimized. I can use the OnMove and OnMinimize of CDialog, but is there any better way of doing so? Thanks. you can just create a Child Dialog inside another dialog. remember to set style of child dialog to Child(default is popup). And you may also want to set its border to none. "Leesei" <someone@microsoft.com> wrote in message news:uamo$RwjEHA.1800@TK2MSFTNGP15.phx.gbl... > I would like to embed a CFrameWnd into a CDialog. > That i...