Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Form Color

Posted on 1999-01-12
18
Medium Priority
?
237 Views
Last Modified: 2012-05-04
How do I change the background color and text color of one form?
0
Comment
Question by:bradsoblesky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 120 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
 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

721 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