Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have started new SDI MFC application (CScroolView). I want to change the color of mainframe, I got one solution for that by doing
1. Added ON_WN_NCPAINT in message handler
2. Added “afx_msg void OnNcPaint( );” in MainFrm.h
3. I overtraded the function in MainFrm.cpp as follows

C++
CDC* pWinDC = GetWindowDC();
	CRect rect;
	GetWindowRect(&rect);
	ScreenToClient(&rect);
	CRect rectClient;
	GetClientRect(&rectClient);
	rectClient.OffsetRect(-rect.left, -rect.top);
	rect.OffsetRect(-rect.left, -rect.top);
	pWinDC->ExcludeClipRect(&rectClient);
	// do stuff here...
	CBrush backBrush(RGB(255,255,255));
	CBrush* pOldBrush = pWinDC->SelectObject(&backBrush);
	pWinDC->SelectObject(pOldBrush);
	// ................
	pWinDC->SelectClipRgn(NULL);
    	ReleaseDC(pWinDC);

So it changed the main frame color.

But after this I got the problem............

1) If I want to change the color of main frame to any other color by changing RGB values in the above code it’s not happening...........???????????
2) Even if I comment all code also no change.....(Previously colored frame is coming)

If I comment ON_WN_NCPAINT then it’s giving default mainframe (Microsoft providing)

So what is happening I am not getting at all ………………………………….

Because we will write ON_WN_NCPAINT in message handler to execute OnNcPaint( ) function even though I haven’t written any code inside this how it’s coming as previously painted mainframe is coming...........

Please help me what is happening inside this.........

Thanks for having patience in reading my problem if possible please give me suggestion to solve/ understand the problem.....................
Posted
Updated 22-May-13 4:23am
v2

Hey! I noticed you always speak of an "ON_WN_NCPAINT function. Of course it's ought to be "ON_WM_NCPAINT", with 'M' mind you. Does this solve anything or was that just a typo?

One other problem I could think of is that this ON_WM_NCPAINT message doesn't get fired in the first place. So you got to do it yourself by calling "SetWindowPos with the SWP_DRAWFRAME flag"
 
Share this answer
 
Hi Krupakar,
the above code has come problem..same code i used and i got same problem ...then i wrote down code and the problem solved.
1.You have to write same code in OnNcPaint().
2.Then u have to call OnNcPaint()function in side OnNcActivate()...

CRect rect;
GetClientRect(rect);
CDC* dc;
int x,y;
CRect rc1,rc2;
dc = GetWindowDC( );
GetWindowRect((LPRECT)&rc2 );

// Compute the caption bar's origin. This window has a system box
// a minimize box, a maximize box, and has a resizeable frame

x = GetSystemMetrics( SM_CXSIZE ) +
GetSystemMetrics( SM_CXBORDER ) +
GetSystemMetrics( SM_CXFRAME );
y = GetSystemMetrics( SM_CYFRAME );
rc1.left = 0;
rc1.top = y;

// 2*x gives twice the bitmap+border+frame size. Since there are
// only two bitmaps, two borders, and one frame at the end of the
// caption bar, subtract a frame to account for this.

rc1.right = rc2.right - GetSystemMetrics( SM_CXFRAME );
rc1.bottom = GetSystemMetrics( SM_CYSIZE )+5;

CRect recta;
GetClientRect(recta);

CPen myPen;
myPen.CreatePen(PS_SOLID, 1,STYLE_BLACK);
CPen *oldPen = dc->SelectObject(&myPen) ;

int lowerEnd = recta.bottom+30;
int lower_border=recta.bottom+30;
int left_border=15;
int right_border=recta.bottom+30;

CRect rctest;
GetWindowRect(&rctest);
ScreenToClient(&rctest);
// draw top border [title bar]
for(int i = rc1.top-8 ; i <= rc1.bottom+5;i++)
{
dc->MoveTo(0, i);
dc->LineTo(rctest.right + right_border, i);
dc->SelectObject (&myPen);
}
// draw left border
for(int i = rc1.bottom ; i <= lowerEnd;i++)
{
dc->MoveTo(0, i);
dc->LineTo(left_border, i);
dc->SelectObject (&myPen);
}
// draw right border
for(int i = rc1.bottom ; i <= lowerEnd;i++)
{
dc->MoveTo(recta.right+2, i);
dc->LineTo(recta.right+2+right_border, i);
dc->SelectObject (&myPen);
}


for(int i = lowerEnd-2 ; i <= lowerEnd + lower_border; i++)
{
dc->MoveTo(0, i);
dc->LineTo(recta.right+2+right_border, i);
dc->SelectObject (&myPen);
}
dc->SelectObject(oldPen) ;
 
Share this answer
 
C++
<big></big>
[]
 
Share this answer
 
Comments
Krupakar Kuramala 24-May-13 3:02am    
Can you please elaborate.....How can i make use of those tags....

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