BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to make: TPageControl->Color = 0x00E8EBEC ??

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Oren Halvani
Guest





PostPosted: Tue Jun 29, 2004 1:31 pm    Post subject: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote



hi dear builders,

i would like to keep my Forms in my Programm in the same
color = 0x00E8EBEC (light grey)

But on some of the forms i've placed some TPageControls..
they don't have a color property..so now my question is there a
way to add a color-property (without creating a new component..)
or maybe to erase their background via: WM_ERASEBKGND...?

i'm using BCB 3...



Oren


Back to top
Guest






PostPosted: Tue Jun 29, 2004 2:42 pm    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote



Try the following, I hope it helps,

Cheers,

============================
class TMyForm : public TForm
{
...
public:
void __fastcall WMDrawItem(TMessage &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DRAWITEM, TMessage, WMDrawItem)
END_MESSAGE_MAP(TForm)
};

=============================
__fastcall TMyForm::TfrmPreferences(TComponent* Owner)
: TForm(Owner)
{
DWORD dwStyle = GetWindowLong(PageControl1->Handle, GWL_STYLE);
SetWindowLong(PageControl1->Handle, GWL_STYLE,
dwStyle | TCS_OWNERDRAWFIXED);
}
//--------------------------------------------------------------------------
-

// This is the function that the WM_DRAWITEM
// message maps to. The LParam member is in the
// form of a DRAWITEMSTRUCT structure. This is
// where you change the color of the Tabs
void __fastcall TMyForm::WMDrawItem(TMessage &Msg)
{
LPDRAWITEMSTRUCT lpdis = (DRAWITEMSTRUCT *)Msg.LParam;

// the WM_DRAWITEM may be shared so handle
// the drawing only if the message corresponds
// the target TabControl
if (lpdis->hwndItem != PageControl1->Handle)
{
TForm::Dispatch(&Msg);
return;
}

// index of tab being drawn
const int Index = lpdis->itemID;

// device context to draw on
const HDC HTabDC = lpdis->hDC;

// bounding rectangle of current tab
/*const */RECT TabRect = lpdis->rcItem;

const HFONT HPrevFont = SelectObject(HTabDC,
PageControl1->Font->Handle);

// fill the rectangle with the Form's brush (color)
::FillRect(HTabDC, &TabRect, Brush->Handle);


const int PrevMode = SetBkMode(HTabDC, TRANSPARENT);

DrawText(HTabDC,
PageControl1->Pages[Index]->Caption.c_str(),
PageControl1->Pages[Index]->Caption.Length(),
&TabRect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);

SetBkMode(HTabDC, PrevMode);
SelectObject(HTabDC, HPrevFont);
Msg.Result = true;

}

=============================

"Oren Halvani" <NoSpam (AT) fdtd (DOT) com> wrote

Quote:
hi dear builders,

i would like to keep my Forms in my Programm in the same
color = 0x00E8EBEC (light grey)




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Jun 29, 2004 5:28 pm    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote




<Zwenska Trowalsky> wrote


Quote:
class TMyForm : public TForm
{
...
public:
void __fastcall WMDrawItem(TMessage &Msg);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DRAWITEM, TMessage, WMDrawItem)
END_MESSAGE_MAP(TForm)
};

You are catching WM_DRAWITEM at the form level when you should be catching
it inside the TPageControl itself instead. Subclass the TPageControl's
WindowProc property instead of using a MESSAGE_MAP in the form.


Gambit



Back to top
Oren Halvani
Guest





PostPosted: Tue Jun 29, 2004 9:47 pm    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote

"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com>
schrieb im Newsbeitrag news:40e1a6a0$1 (AT) newsgroups (DOT) borland.com...

Quote:
You are catching WM_DRAWITEM at the form level when you should be catching
it inside the TPageControl itself instead. Subclass the TPageControl's
WindowProc property instead of using a MESSAGE_MAP in the form.

Gambit


how should WindowProc(...) look like Remy..? do you have a sample for that..?
isn't it possible to send a simple SendMessage(...) to erase the background..?


Oren




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Jun 29, 2004 10:23 pm    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote

"Oren Halvani" <NoSpam (AT) fdtd (DOT) com> wrote


Quote:
how should WindowProc(...) look like Remy..? do you have a sample for
that..?


TWndMethod OldWndProc = NULL;

__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
OldWndProc = PageControl1->WindowProc;
PageControl1->WindowProc = PageControlWndProc;

DWORD dwStyle = GetWindowLong(PageControl1->Handle, GWL_STYLE);
SetWindowLong(PageControl1->Handle, GWL_STYLE, dwStyle |
TCS_OWNERDRAWFIXED);
}

void __fastcall TForm1::PageControlWndProc(TMessage &Message)
{
switch( Message.Msg )
{
case WM_DRAWITEM:
// do something...
break;

case WM_PAINT:
// do something...
break;

default:
OldWndProc(Message);
break;
}

Quote:
isn't it possible to send a simple SendMessage(...) to erase the
background..?


Sure, but that does not accomplish what you were asking for. That tells the
window to erase and redraw its background, but the window will still draw
the background using its default drawings. You were asking to change the
color of the background instead. Very different thing.


Gambit



Back to top
Oren Halvani
Guest





PostPosted: Tue Jun 29, 2004 11:14 pm    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote

Remy..OK i'm use now this:

/**************************************************/
TWndMethod OldWndProc = NULL;

__fastcall TfrmMainUnit::TfrmMainUnit(TComponent* Owner) : TForm(Owner)
{
OldWndProc = PageControl1->WindowProc;
PageControl1->WindowProc = PageControlWndProc;

DWORD dwStyle = GetWindowLong(PageControl1->Handle, GWL_STYLE);
SetWindowLong(PageControl1->Handle, GWL_STYLE, dwStyle | TCS_OWNERDRAWFIXED);
}

void __fastcall TfrmMainUnit::PageControlWndProc(TMessage &Message)
{
switch(Message.Msg)
{
case WM_DRAWITEM: break;
case WM_PAINT: break;
default: OldWndProc(Message); break;
}
}
/**************************************************/

but now that PageControl and the Tabs on it are totale invisible..
why..? I only see the controls (Labels, Memo's..) on the tabs
but not the tabs or the pagecontrol at all..

is there maybe a bug in the code..?

Oren


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Jun 29, 2004 11:28 pm    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote


"Oren Halvani" <NoSpam (AT) fdtd (DOT) com> wrote


Quote:
but now that PageControl and the Tabs on it are totale invisible..

That is because you completely disabled all of the PageControl's native
drawing altogether. You were supposed to put actual drawing code into the
WndProc to make the PageControl look like you wanted it to look.


Gambit



Back to top
Oren Halvani
Guest





PostPosted: Wed Jun 30, 2004 6:15 am    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote

"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com>
schrieb im Newsbeitrag news:40e1fb20$1 (AT) newsgroups (DOT) borland.com...

Quote:
That is because you completely disabled all of the PageControl's native
drawing altogether. You were supposed to put actual drawing code into the
WndProc to make the PageControl look like you wanted it to look.

Well OK I understand you, but what have to be draw now to get the
PageControll and his Tabs visible like normaly they are..? i just wanted
their color to be set to: "0x00E8EBEC" or just use the color of the
parent form..thats all...

what do i need to draw in:

case WM_DRAWITEM:
or...
case WM_PAINT:

just to get them visible again...?


Oren



Back to top
Hans Galema
Guest





PostPosted: Wed Jun 30, 2004 8:51 am    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote

Oren Halvani wrote:

Quote:
what do i need to draw in:

case WM_DRAWITEM:
or...
case WM_PAINT:

Until now you did not react to Zwenska. Does the provided code
work for you ? If yes then use that code on the suggested places.

Hans.

Back to top
Oren Halvani
Guest





PostPosted: Wed Jun 30, 2004 10:10 am    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote


"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> schrieb im Newsbeitrag
news:40e27ecb (AT) newsgroups (DOT) borland.com...

Quote:
Until now you did not react to Zwenska. Does the provided code
work for you ? If yes then use that code on the suggested places.

Hans.

It works fine, but Remy says to subclass the TPageControl's
WindowProc property instead of using a MESSAGE_MAP in the form..

so isn't it OK to use Zwenska code..?



Oren



Back to top
Hans Galema
Guest





PostPosted: Wed Jun 30, 2004 11:25 am    Post subject: Re: How to make: TPageControl->Color = 0x00E8EBEC ?? Reply with quote

Oren Halvani wrote:

Quote:
"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> schrieb
If yes then use that code on the suggested places.

It works fine,

Nice to -finally- know.

Quote:
but Remy says to subclass the TPageControl's
WindowProc property instead of using a MESSAGE_MAP in the form..

Wel you did that. But did you already use Zwenska's code there ?

Quote:
so isn't it OK to use Zwenska code..?

What makes you think so ?
I just said to use it 'on the suggested places.'

Hans.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.