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.
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.
GetDC() GetWindowDC() drawing
This is an example using API GetDC() and GetWindowDC() APIs 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. We are using left button mouse click to draw in client area. We are using GetDC() to get the device context of the client area. We are drawing rectangle in blue color in non client area and green color in client area.
GetDC GetWindowDC 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