Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Form Color

How do I change the background color and text color of one form?
0
bradsoblesky
Asked:
bradsoblesky
  • 8
  • 8
  • 2
1 Solution
 
bradsobleskyAuthor Commented:
Could you also tell me how to change the size of individual text?
You can tell I just started the language. :)
0
 
nietodCommented:
In what contect?  What do you mean by "form"?

In a windows DC you can use SetBkColor() and SetTextColor().  Does that help?
In a window procedure you can respond to the WM_CTLCOLORxxxx messages.  (There is a whole bunch of messages hence the xxxx) to change the color and text of child controls.
0
 
nietodCommented:
Note that this is a C++ topic area.  There are topic areas for particular OSs.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
bradsobleskyAuthor Commented:
This is visual C++ 6.0 for win 98 by form I mean an individual dialog box.  For example just the About form. They use form in Visual Basic for the "window" of the program. I need how to do it and were to put it.
0
 
nietodCommented:
Outside of VB, the term "window" is used for a window.

There is no way "built-in" way to change the background color of a dialog box.  What you can do is handle the WM_PAINT or WM_ERASEBKGND messages for the dialog and "manually" draw in the background you want.

The text color should not matter as the dialog does not have text, it has child windows that have text.  You will need to change the background and text colors of those as well.  To do that, the dialog should process the WM_CTLCOLORxxxx messages.

Note that these sort of techniques tend to have only limited success.  Windows makes it hard to do this sort of thing, mostly because its not a really good idea to do so.   So you might want to consider whehtor or not you really want to do this.  
0
 
The_BrainCommented:
How do you then change the background of a form once you added the WM_CTLCOLOR message?

(I just want to change the background color when I press a button.)
Sorry Brad, hope you don't mind me asking a similar question in here.
0
 
nietodCommented:
Those messages can be used to change the color of child windows (i.e. controls on the window that handles the message).  The window just changes the background color of the DC specified in the message and that DC is then used to paint the control's client area.   The problem is that not all types of controls are good about using this feature, so it doesn't always work.
0
 
The_BrainCommented:
But now is there really a way, if so how do you do it. (code) I hopefully speak on behalf of Brad and myself.
0
 
bradsobleskyAuthor Commented:
You know change the color of just the about dialog box not your main program dialog box.
0
 
nietodCommented:
The about dialog box must have its own (dialog) window procedure that is seperate from the main window procedure.  Just do this in the about dialog's window procedure, not the main window procedure.
0
 
bradsobleskyAuthor Commented:
This is for a game and I want the window to be all black but not the other dialog boxes or windows in the program. Is what you are saying is that there is no way to do it in Visual C++ 6. It is a click of a button in Visual Basic 6.
0
 
nietodCommented:
>> what you are saying is that there is no way to do it in Visual C++ 6
No.  I expained how to do it above.  You must manually paint the window's background.  If the window has child controls, you must handle the WM_CTLCOLORxxxx messages from those or they won't "blend in".  Unfortunately, not all types of controls are good about this.  If you are using one that doesn't handle the WM_CTLCOLORxxxx message well, the results might not look great.  Then you have to give up, or sub-class the control or write your own control.
0
 
bradsobleskyAuthor Commented:
>>WM_CTLCOLORxxxx   ???????????????
I don't know how or were to use it. I'm a complete moron :(
0
 
nietodCommented:
Look it up in the help.  The information is quite extensive.  More than I can type here.
0
 
bradsobleskyAuthor Commented:
Guess what I did that first; And It was so extensive that I didn't know what the hell to do.  I just want one damn example of how to do it and some one to tell me where to put it. Not a hole bunch of C jargon that I don't understand because I have no clue what I am doing, I have no background in C/C++. Someone out there has to know an easy way to do it.
0
 
bradsobleskyAuthor Commented:
For example check this answer from "Answer 2000" it says exactly where to put it and how to do it.Only one problem with this it changes all of the backgrounds and not just one:


 MFC program - background dialog color - stick in InitInstance
SetDialogBkColor( RGB(0,0,0), RGB(255,255,255) ) ; // background to black, text to white (black on black is not to readable :-))
0
 
nietodCommented:
There is no easy way to do it.  It will take a good understanding of windows programming and a decent amount of trial and error.

At the very least, you must be familiar with:
Window procedures and handling window messages.
Windows Device contexts and graphics procedures.
The WM_CTLCOLORxxx messages.

if you are not, you will have to do some reading and learning.  You will HAVE to learn about these things if you plan to program in windows in C++.  But you don't have to do the research now.  This sounds like a feature that could wait until you are more familiar with the windows API.  If you are ready to learn about them.  I recomend you buy 2 or 3 good books on windows programming. (1 is not enough) and read them each twice.  (Seriously,  they tend not to make much sense in the beginning, read it anyways.  On the second time through things make much more sense and you pick up on lots that you miss the first timek, that is also a reason to read several instead of one.)
0
 
bradsobleskyAuthor Commented:
O.K. I'll take that advice, Thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now