You typically use the GetDC function to provide instant feedback to some action by the user, such as drawing a line as the user moves the cursor (pointer) through the window. The function returns a display-context handle that you can use in any GDI output function.
The following example shows how to use the GetDC function to retrieve a display-context handle and write the string Hello Windows! in the client area:
hDC = GetDC(hWnd);
TextOut(hDC, 10,10, “Hello Windows!”, 14);
ReleaseDC(hWnd, hDC);
In this example, the GetDC function returns the display context for the window identified by the hWnd parameter, and the TextOut function writes the string at the point (10, 10) in the window's client area. The ReleaseDC function releases the display context.
Anything you draw in the client area will be erased the next time the window function receives a WM_PAINT message that affects that part of the client area. The reason is that Windows sends a WM_ERASEBKGND message to the window function while processing the WM_PAINT message. If you pass WM_ERASEBKGND on to the DefWindowProc function, DefWindowProc fills the affected area by using the class background brush, erasing any output you may have previously drawn there.