Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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;
	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 22-May-13 5:18am
Edited 22-May-13 5:23am
v2
Rate this: bad
good
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"
  Permalink  
Rate this: bad
good
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;
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) ;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<big></big>
[]
  Permalink  
Comments
Krupakar Kuramala at 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
0 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 24 Jun 2013
Copyright © CodeProject, 1999-2014
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