Client Area
Total area of a window is divided in two parts client area and non-client area. Client area of a window is the square area of window below title bar where user can place child widgets.
Non-Client Area
Not client area is the area of a window where operating system constructs borders, title bar, menu bar, minimize/maximize button and exit button etc. Non client area is generally under control of operating system and depending on the themes selected by user it changes its appearance.
GetDC () API returns the device context of the client area of the window. Where as GetWindowDC () returns the total area of the window including non-client area. To draw only in client area we should use device context returned by GetDC(). To draw in client or non-client area we should use device context returned by GetWindowDC(). GetDC() and GetWindowDC() function reference has been listed below for your reference.
GetDC()
GetDC() function retrieves a handle to a display device context for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the device context.
GetDC() Client Area drawing
This is an example using API GetDC(). We need to open winver app in Windows which display an about box. Here we find the handle of the window using FindWindow(). We have used GetDC to get the device contect of the client area and we are drawing a rectangle around the edges of this area.
Client Area drawing output
GetWindowDC()
GetWindowDC() function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area. GetWindowDC assigns default attributes to the window device context each time it retrieves the device context. Previous attributes are lost.
GetWindowDC() non client Area drawing
This is an example using API GetWindowDC() and Window event WE_NCPAINT. We have used GetWindowDC to get the device contect of the non client area and we are drawing a rectangle around the edges of this area.
Client Area drawing output
You may also like to know : #WinMain #WNDCLASS #RegisterClass #CreateWindow #Window Proc #GetMessage & DispatchMessage #WPARAM & LPARAM #DefWindowProc #Device Context #PEN #BRUSH #WM_PAINT #SaveDC RestoreDC #GetDC ReleaseDC #Mouse Events
About our authors: Team EQA
Further readings
Where is WinMain() function in MFC application ?
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
What is the utility of CWinApp class?
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Basic steps in Win32 GUI Application with source code.
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
What is a Window CallBack procedure and what is its utility?
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
What are LPARAM and WPARAM in window proc function?
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
What are the basic steps of a typical MFC based application?
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average