Click here to Skip to main content
13,046,045 members (45,815 online)
Rate this:
Please Sign up or sign in to vote.
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

CDC* pWinDC = GetWindowDC();
	CRect rect;
	CRect rectClient;
	// do stuff here...
	CBrush backBrush(RGB(255,255,255));
	CBrush* pOldBrush = pWinDC->SelectObject(&backBrush);
	// ................

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 22-May-13 4:18am
Updated 22-May-13 4:23am
Jochen Arndt189.7K
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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"
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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;
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; = 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;

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;
// draw top border [title bar]
for(int i = ; 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) ;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

<pre lang="c++"><big></big></pre> <a href=""></a><a href=""></a>[<a href="" target="_blank"></a>]
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 24 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100