《windows程序设计》文本输出(02)

获取设备环境句柄:

方法一:
hdc  = BeginPaint(hwnd, &ps);
    //使用GDI函数
EndPaint(hwnd, &ps);

方法二:
hdc = GetDc(hwnd);
    //使用GDI函数
ReleaseDc(hwnd, hdc)

 消息循环代码如下:

 

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            TextOut(hdc,0,0,"hello world",11);
            EndPaint(hwnd, &ps);
            break;
        default:                      /* for messages that we don‘t deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}