Solved

Form Color

Posted on 1999-01-12
18
228 Views
Last Modified: 2012-05-04
How do I change the background color and text color of one form?
0
Comment
Question by:bradsoblesky
  • 8
  • 8
  • 2
18 Comments
 

Author Comment

by:bradsoblesky
ID: 1181972
Could you also tell me how to change the size of individual text?
You can tell I just started the language. :)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1181973
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
 
LVL 22

Expert Comment

by:nietod
ID: 1181974
Note that this is a C++ topic area.  There are topic areas for particular OSs.
0
 

Author Comment

by:bradsoblesky
ID: 1181975
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
 
LVL 22

Accepted Solution

by:
nietod earned 40 total points
ID: 1181976
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
 
LVL 1

Expert Comment

by:The_Brain
ID: 1181977
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
 
LVL 22

Expert Comment

by:nietod
ID: 1181978
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
 
LVL 1

Expert Comment

by:The_Brain
ID: 1181979
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
 

Author Comment

by:bradsoblesky
ID: 1181980
You know change the color of just the about dialog box not your main program dialog box.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 22

Expert Comment

by:nietod
ID: 1181981
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
 

Author Comment

by:bradsoblesky
ID: 1181982
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
 
LVL 22

Expert Comment

by:nietod
ID: 1181983
>> 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
 

Author Comment

by:bradsoblesky
ID: 1181984
>>WM_CTLCOLORxxxx   ???????????????
I don't know how or were to use it. I'm a complete moron :(
0
 
LVL 22

Expert Comment

by:nietod
ID: 1181985
Look it up in the help.  The information is quite extensive.  More than I can type here.
0
 

Author Comment

by:bradsoblesky
ID: 1181986
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
 

Author Comment

by:bradsoblesky
ID: 1181987
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
 
LVL 22

Expert Comment

by:nietod
ID: 1181988
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
 

Author Comment

by:bradsoblesky
ID: 1181989
O.K. I'll take that advice, Thanks for your help.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

18 Experts available now in Live!

Get 1:1 Help Now