May 01, 2024, 02:49:34 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Forecolors for windows or static control?

Started by Shannara, December 24, 2006, 05:02:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Shannara

December 24, 2006, 05:02:28 PM Last Edit: December 24, 2006, 05:08:15 PM by Sync
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 :)
Love is staying up all night with a sick child, or a healthy adult.

Bruce Peaslee

Try this:


pStatic = GetControl(theControl);
pStatic->SetColor(RGB(0,0,255),RGB(255,0,0));
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

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.

Ionic Wind Support Team

Shannara

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.
Love is staying up all night with a sick child, or a healthy adult.

Bruce Peaslee

It works here and Paul is right.

Maybe some code to look at?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

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();
}
Ionic Wind Support Team

Shannara

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.
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

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.
Ionic Wind Support Team

Shannara

December 24, 2006, 09:05:52 PM #8 Last Edit: December 24, 2006, 10:01:43 PM by Sync
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.
Love is staying up all night with a sick child, or a healthy adult.