Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i've one dialog based application, where in i have one 'group box/static'control. i want to fill that 'group box/static'control with color. to do that, i should get the rectangle coordinates of 'group box/static' control.i've tried with GetWindowRect().but i could not get the coordinates.how can i move with this?please help me.
Thanks in advance..
Posted
Comments
Niklas L 7-Jun-11 9:16am    
After calling GetWindowRect(), you should call ScreenToClient() to translate from screen coordinates to client coordinates of the parent (i.e. the dialog)

 
Share this answer
 
Comments
Jijesh Balakrishnan 7-Jun-11 0:54am    
this will be helpful for text boxex.i want to get the coordinates of static control and group box.
LaxmikantYadav 7-Jun-11 1:38am    
Just pass the static control id instead of textbox :)
Jijesh Balakrishnan 7-Jun-11 1:46am    
i've tried with that,but its showing warnninglike the 'rect'(LPRECT rect)is used without initializhing.and also getting debug error.
to colour the items of your dialog like static control, group box etc you dont need its rectangle coordinates. you can get it done in your OnCtlColor() function of your dialog. There you just need to check the control item id and assign text and background colour like this
if( IDC_GROUP1 == pWnd->GetDlgCtrlID())
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(0,0,255));
}
where IDC_GROUP1 is the id of your group box.
but in this way you will not be able to colour the frame of your group box.
for this create a your own class derived from CStatic, say CMyStatic.
then you need to create a control member variable of your gruop box item. its class type should be CMyStatic.
and within CMyStatic OnPaint() you need to do all things to draw a group box frame using FrameRect() call.
also you need to write the code to draw group box text.you can modify the below code accordingly to get what you need.

void CMyStatic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect WndRect;
	CBrush GreenBrush;
	GreenBrush.CreateSolidBrush(RGB(0,255,0));
	dc.GetWindow()->GetClientRect( WndRect );
	dc.FrameRect( WndRect, &GreenBrush );
	dc.SetTextColor(RGB(0,255,0));
	dc.SetBkColor(RGB(255,0,0));
	dc.TextOut(WndRect.left + 5,WndRect.top - 10,"Title" );
	// Do not call CStatic::OnPaint() for painting messages
}
 
Share this answer
 
Comments
Jijesh Balakrishnan 7-Jun-11 1:25am    
i think the below code will work.i do not want to assign color to text in static control. but i want fill the entire rectangle(static control's)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900