Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oh why can't it be like VB?

Status
Not open for further replies.

mmilan

Programmer
Jan 22, 2002
839
GB
I'm a Visual Basic coder at heart, and finding myself unemployed as of Friday, I have decided to put my unwanted new found free time toward learning Visual C++.

To this end, I have bought myself a copy of "Teach Yourself Visual C++ 6.0 in 21 Days", and charged blindly forth... It should also be noted that I have written in Turbo C++ for Dos, so the basic form of the language isn't a problem...

Anyway, I've set myself a little challenge... I'm going to write myself a program which takes the Computer Name, I.P. Address, and other such goodies, then slaps then on a dialog. Being a picky sort of chap though, I've decided that the dialog is going to have a bright green background, and the "Headings" for the information will be red.

Having played with the dialog using the resource editor though,I can't seem to achieve either... Can anyone suggest where I might be going wrong?

Martin
 
Someday soon, the distinction between C# and VB.net will be moot. Using either, you'll get the same underlying bytecode anyway (unless <gasp>, you use &quot;unmanaged&quot; code).

I'm a VC++ person, so welcome to the neighborhood, although I'm sorry to hear it's under these circumstances. Yes, it's much harder to do things like setting colors...

I'm tight on time right now, but hopefully someone can answer your question soon. If not, I'll try to get back to take a crack at it when I have a little more time.
 
Cheers - I could certainly use the assist...

Martin.
 
Add the following 2 variables to your dialog class; GreenBrush & RedBrush.
Within the class constructor add the following;
RedBrush.CreateSolidBrush(RGB(255,0,0));
GreenBrush.CreateSolidBrush(RGB(0,255,0));

Via ClassWizard override the function for handling the message WM_CTLCOLOR (i.e. highlight your dialog in ‘Object IDs', highlight WM_CTLCOLOR in ‘Messages’ then select ‘Add Function’ followed by ‘Edit Code’).

Alter the function to look like the following;

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

if(nCtlColor == CTLCOLOR_DLG)
return HBRUSH(GreenBrush);

if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(0,255,0));
return HBRUSH(GreenBrush);
}

return hbr;
}

This might not be exactly what you’re after, but you’ll get the idea.
 
Sorry, should have said that you add the variables to your class as;
CBrush RedBrush, GreenBrush;
 
Thanks Pencilbiter - I'll givwe that a try later on...

Martin.
 
Okay - I've declared the Red and Green brushes as private members of the dialog derived class, and entered the code on the message handler.

When I run the code, it just presents the same old &quot;Grays are us&quot; dialog...

It's a shame you can't use attachments here, or I would post a zipped archive of the project...

 
That looks great Vincent P...

The problem is though I'm trying to learn how to do things myself, not just using other people's classes (And a very impressive class it looked too!).

I don't NEED the program I am trying to write - indeed I should be spending my time on a Visual Basic project that a friend and I are undertaking, but I want to learn how to get Visual C++ ticking. I'm of the understanding that it's a much better language, and that although you often have to write a ton of seemingly pointless code to do anything, the power of the language means it's worth it...

A big thanks to all of you though who are trying to help... There's something I can click that gets you credit for helpful posts isn't there? How's that work?
 
Aha - I see how to mark messages as helpful now...

 
You can always get some inspiration from his code, to get a starting point. Though I admit it could be confusing to try to get out only the part of interest to you. (Changing the fonts is something I have a lot of trouble with myself.)

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top