IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: Shannara on December 24, 2006, 05:02:28 PM

Title: Forecolors for windows or static control?
Post by: Shannara on December 24, 2006, 05:02:28 PM
When setting the color for the CStatic class, nothing changes. So I figured, id' try to use the Window.WriteText() to write the text, and find some way to set the window's forecolor ... hrm :) After searching in the docs, I have found the following options:


FrontPen(Color);

SetWindowColor(Color);


The 2nd one, only does the background color for the window but not foreground color. The 1st one states it will do the foreground color for text and such, but doesn't seem to work. Are there some tricks to get the static class have colors, or even have the window text (WriteText) have colors?

I only place these type of questions in the 101 since I couldnt find any answers in the docs and to help anybody else who have the same questions :)
Title: Re: Forecolors for windows or static control?
Post by: Bruce Peaslee on December 24, 2006, 05:12:38 PM
Try this:


pStatic = GetControl(theControl);
pStatic->SetColor(RGB(0,0,255),RGB(255,0,0));
Title: Re: Forecolors for windows or static control?
Post by: Ionic Wind Support Team on December 24, 2006, 05:18:31 PM
ForePen is only used for text drawn into the window with WriteText and the color of filled graphics elements like circles, rectangles and such drawn into that window.  It has nothing to do with a controls color that is specifically set with the SetColor method of CControl, and all control types are derived from CControl.

Title: Re: Forecolors for windows or static control?
Post by: Shannara on December 24, 2006, 05:22:10 PM
Paul:

Thats the problem, SetColor doesnt work on the static control, and ForePen doesnt work on the Window's WriteText :(

peaslee:

Thanks for the tip :) Unfortunately, that does not work on my computer either.

If it makes any difference, I am running WindowsXP on the Classic theme.
Title: Re: Forecolors for windows or static control?
Post by: Bruce Peaslee on December 24, 2006, 05:33:48 PM
It works here and Paul is right.

Maybe some code to look at?
Title: Re: Forecolors for windows or static control?
Post by: Ionic Wind Support Team on December 24, 2006, 05:43:12 PM
Either your using them in in the wrong place or incorrectly.  See the example file "weatherman.src" included with the installation for an example on setting a static controls color.  Specifically the OnCreate handler for the window.

See the "simplepaint.src" for a general example on colored graphic elements.  And here is a basic WriteText example, using two Christmas colors.


//CTextWindow definition
class CTextWindow : CWindow
{
declare CTextWindow();
declare _CTextWindow();
declare virtual OnClose(),int;
}

//CTextWindow Implementation
CTextWindow::CTextWindow()
{
}

CTextWindow::_CTextWindow()
{
}

CTextWindow::OnClose(),int
{
Destroy();
return 0;
}

sub main
{
CTextWindow w;
w.Create(0,0,200,200,AWS_AUTODRAW|AWS_VISIBLE|AWS_CAPTION|AWS_SYSMENU|AWS_CENTERED,0,"Window Test",NULL);
w.FrontPen(RGB(255,0,0));
w.BackPen(RGB(0,255,0));
w.WriteText(0,10,"Merry Christmas");
do{ wait(); } until !w.IsValid();
}
Title: Re: Forecolors for windows or static control?
Post by: Shannara on December 24, 2006, 05:47:43 PM
I didnt mean to say Paul was wrong. I meant to say that the functions do not work on my computer :( The following is some code.


class mWindow : CWindow
{
   declare virtual OnCreate(),int;
   declare virtual OnClose(), int;
   
   CStatic csTest;
}

mWindow :: OnCreate()
{
csTest.Create(10, 10, 100, 20, 0, 1, "Static Test", this);
SetWindowColor(RGB(0, 0, 0));
FrontPen(RGB(255, 255, 255));
WriteText(10, 40, "Win Text Test");

return 0;
}

mWindow :: OnClose()
{
Destroy();
return 0;
}

/* Main routine */
global sub main()
{
// Create our test window
mWindow myWindow;
myWindow.Create(0, 0, 500, 500, AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW|AWS_SIZE, 0, "Test", null);

do
{
wait();
} until !myWindow.isValid();

return 0;
}



I hope this helps.
Title: Re: Forecolors for windows or static control?
Post by: Ionic Wind Support Team on December 24, 2006, 06:00:52 PM
Follow my examples and it will work.  OnCreate is called before the window is shown and initialized.  Setting a windows text color there won't do you any good.  Make this change to see what I mean.


/* Main routine */
global sub main()
{
   // Create our test window
   mWindow myWindow;
   myWindow.Create(0, 0, 500, 500, AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW|AWS_SIZE, 0, "Test", null);
   myWindow.FrontPen(RGB(255, 255, 255));
   myWindow.WriteText(10, 40, "Win Text Test");
   do
   {
      wait();
   } until !myWindow.isValid();

return 0;
}


Or if you prefer API style window painting don't use the AWS_AUTODRAW style and do all of your coloring in response to the OnPaint handler. 

OnCreate can be used to add and initialize controls as illustrated in the weatherman.src example.  Just keep in mind that at the time OnCreate is called the CWindow::Create method hasn't returned yet. 

Paul.
Title: Re: Forecolors for windows or static control?
Post by: Shannara on December 24, 2006, 09:05:52 PM
Ah ha! That works out perfectly :) Thank you for explaining that. It works great with windows, using the WriteText method after the window have finished creating. Also a little note for myself and whoever else is reading this. AWS_VISIBLE is really useful on window controls, or else they are created invisibly.