Drawing in the non-client area

I'm learning MFC and I use VC++ 6. I came across this code which draws in the non-client area of the window, but its not working. The rectangle is painted in the window but it gets partially covered by the caption bar which I don't want. Here's the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<afxwin.h>
#include<windows.h>
class myframe : public CFrameWnd
{
public:
	myframe()
	{
		CRect winrc(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
		Create(0,"Hello",WS_OVERLAPPED|WS_SYSMENU,winrc);
	}
	void OnPaint()
	{
		CFrameWnd::OnPaint();
		CWindowDC d(this);
		CPen mypen(PS_SOLID,2,RGB(255,0,0));
		CBrush mybrush(RGB(0,255,0));
		d.SelectObject(mypen);
		d.SelectObject(mybrush);
		d.SetTextColor(RGB(0,0,255));
		d.TextOut(1,1,"Painting in non Client Area",strlen("Painting in non Client Area"));
		d.Rectangle(0,0,200,500);
	}
	DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
	ON_WM_PAINT()
END_MESSAGE_MAP()

class myapp: public CWinApp
{
public:
	int InitInstance()
	{
		myframe *p;
		p = new myframe;
		p->ShowWindow(1);
		m_pMainWnd=p;
		return 1;
	}
};
myapp a;
Last edited on
Somebody please help
I'm not entirely sure what you are wanting to do.

Your best bet is to go to MSDN and read up on the WM_NC???? family of messages, such as WM_NCPAINT.
closed account (jwkNwA7f)
The answer was eventually gotten to here: http://www.cplusplus.com/forum/windows/108581/
If my memory serves me right, something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class myframe : public CFrameWnd
{
public:
	myframe()
	{
		CRect winrc(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
		Create(0,"Hello",WS_OVERLAPPED|WS_SYSMENU,winrc);
	}

	// void OnPaint()
        void OnNcPaint() ;
	{
		//CFrameWnd::OnPaint();
                Default() ; // or: CFrameWnd::OnNcPaint() ;

		CWindowDC d(this);
		CPen mypen(PS_SOLID,2,RGB(255,0,0));
		CBrush mybrush(RGB(0,255,0));
		d.SelectObject(mypen);
		d.SelectObject(mybrush);
		d.SetTextColor(RGB(0,0,255));
		d.TextOut(1,1,"Painting in non Client Area",strlen("Painting in non Client Area"));
		d.Rectangle(0,0,200,500);
	}

	DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
	// ON_WM_PAINT()
        ON_WM_NCPAINT()
END_MESSAGE_MAP()
Topic archived. No new replies allowed.