Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys
I am new to MFC programming or may be i cannot find the right answer over internet my bad luck my bad search.
Question: I need to draw a red border around any control displayed on mfc dialog it can be either combobox or spin control or anything else. so what i thought to create a new class derived from CStatic class and implements it OnNcPaint message for drawing border around it.

C++
void CMystatic::OnNcPaint()
{
	if(m_bDrawBorder)
	{
		CDC* pDC = GetWindowDC( );
		//work out the coordinates of the window rectangle,
		CRect rect;
		GetWindowRect( &rect);
		rect.OffsetRect( -rect.left, -rect.top);
		
		//Draw a single line around the outside
		CBrush brush( RGB( 255, 0, 0));
		pDC->FrameRect( &rect, &brush);
		ReleaseDC( pDC);	
			
	}
	else
	{
		CStatic::OnNcPaint();
	}
}


CMyStatic is derived from CStatic class and m_DrawBorder is a member variable of this class for drawing border. which can set through any class which uses CMyStatic class object.For example while clicking button1 i am setting to draw border and while clicking button2 i am again resetting to original behavior of static control.
Issues
1. If a static text control property BORDER is true the i run the application.Then i see some border which is like some frame in Z order it looks like some 3d or some depth order border which i do not need. On the other hand i require some 2-d border only like it shows when you do border property TRUE and look at the control at design time not at run time.

2. i don't want Z-order depth i just need 2-D border any buddy can help me and post code here. i have implemented other ways to but not help full.The code below is not helpful.

m_Mystatic.ModifyStyleEx(dwStyle,0,SWP_NOSIZE|SWP_FRAMECHANGED);
m_Mystatic.ModifyStyleEx(dwStyle,0,SWP_FRAMECHANGED);
m_Mystatic.ModifyStyleEx(0,WS_EX_CLIENTEDGE,SWP_FRAMECHANGED);
m_Mystatic.ModifyStyleEx(0,WS_EX_CLIENTEDGE,SWP_FRAMECHANGED);


NOTE: i just need to toggle between border and no border but no other sunken or other Z order border just plain static text

(i don't know how to add image otherwise i could upload it.)

Plzzzzzzzzzzzzzzzz reply
Posted
Updated 30-Jul-12 22:37pm
v2

1 solution

A bordeless child window could paint its background by its own color
and notify the parent window (styled by |WS_CLIPCHILDREN) about the focus,
whereby the parent could check the focused child and just paint a red rectangle
into the inflated area of the child...

...of course the last marked area must be accumulated by parent,
to be invalidated at the gone-focus notification as well :)
 
Share this answer
 

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