1. 程式人生 > >《windows程序設計》文本輸出(02)

《windows程序設計》文本輸出(02)

proc back new end ESS family wm_paint 消息 hat

技術分享圖片

獲取設備環境句柄:

方法一:
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; }

《windows程序設計》文本輸出(02)