Article View: comp.windows.ms.programmer
Article #485Re: MFC and Custom Controls / WM_NCPAINT
From: Steven Sinofsky
Date: Thu, 20 Aug 1992 20:21
Date: Thu, 20 Aug 1992 20:21
62 lines
2741 bytes
2741 bytes
In article <8304@ncratl.AtlantaGA.NCR.COM> kso@ncratl.AtlantaGA.NCR.COM (Khun So) writes:
>
>
> I have a couple of questions on Windows developement using C/C++ 7.0.
> Any insights on the subjects will be greatly appreciated.
>
>
> 1. How does one extend MFC to support custom controls
> and other window classes? Specifically I would like
> to derive a class from CWnd for the custom controls
> I had developed. Many of my controls use extra bytes
> per window instance (cbWndExtra!=0 in WNDCLASS data
> structure). The current AfxRegisterWndClass always
> sets cbWndExtra=cbClsExtra=0. Is there a simple way
> to do this without modifying MFC source?
Let's say you have a Window class called "MYCLASS", then all you
need to do to have a C++ class is the following:
class CMyClass : public CWnd
{
public:
BOOL Create(LPCSTR lpszWindowName, DWORD dwExtraStyles,
const RECT& rect, CWnd* pParentWnd)
{
static char BASED_CODE szMyClass[] = "MYCLASS";
return CWnd::Create(szMyClass, lpszWindowName,
dwStyles, rect, pParentWnd);
}
// add additional member functions to support custome WM_
// SendMessages here
DECLARE_MESSAGE_MAP() // use this to handle messages as
// you would expect
};
You don't even need to derive your own class if you don't plan
on customizing the Window at all, since CWnd::Create will
allow you to pass a Window class name. The window will still then be
part of the normal MFC message routing.
>
> 2. In processing WM_PAINT, BeginPaint() API is called
> and an invalidated region of the window is returned.
> What about WM_NCPAINT? Is there a way to detect only
> the invalidated area in the non-client area for
> painting? Or do I have to paint the entire non-client
> area everytime?
>
> Thanks in advance.
Painting in the non-client area of a Window is "not recommended" (from
page 475 of the Programmers Reference v2). If you must, then
you retrieve a DC via CWnd::GetWindowDC. In your code you should
paint everything.
--
Steven Sinofsky
stevesi@microsoft.com
Disclaimer: I don't speak for Microsoft, BillG does that.
Technical Details
Message-ID:
<1992Aug20.202109.18466@microsoft.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!microsoft!wingnut!stevesiReferences:
<8304@ncratl.AtlantaGA.NCR.COM>Show Full Headers
Complete Article Headers
Newsgroups: comp.windows.ms.programmer,comp.os.ms-windows.programmer.misc Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!wingnut!stevesi From: stevesi@microsoft.com (Steven Sinofsky) Subject: Re: MFC and Custom Controls / WM_NCPAINT Message-ID: <1992Aug20.202109.18466@microsoft.com> Date: 20 Aug 92 20:21:09 GMT Organization: Microsoft Corporation References: <8304@ncratl.AtlantaGA.NCR.COM> Keywords: Windows Development, Microsoft C/C++ Lines: 60