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.
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() 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() 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
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
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.
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.
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
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 ...
Learn on Youtube