- 設定菜單項為選中狀态
HMENU hMenu; hMenu = GetMenu(); CheckMenuItem(hMenu, ItemSelection, MF_UNCHECKED); ItemSelection = LOWORD(wParam); CheckMenuItem(hMenu, ItemSelection, MF_CHECKED);
- 設定菜單為(不)可用狀态
EnableMenuItem(hMenu, IDM_EDIT_UNDO, MF_GRAYED); EnableMenuItem(hMenu, IDM_EDIT_UNDO, MF_ENABLED);
- 處理paint消息時,取得裝置内容句柄
BeginPaint(); EndPaint();
- 處理非paint消息時,取得裝置内容句柄
HDC hdc; hdc = GetDC(hwnd); ReleaseDC(hwnd, hdc);
- 獲得現有畫筆句柄
HPEN hPen;
hPen = GetStockObject(WHITE_PEN);
SelectObject(hdc, hPen);
- 畫筆的建立、選擇、删除
hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));
SelectObject(hdc, hPen);
DeleteObject(hPen);
- 獲得現有畫刷句柄
HBRUSH hBrush;
hBrush = GetStockObject(NULL_PEN);
SelectObject(hdc, hPen);
- 建立邏輯畫刷
hBrush = CreateSolidBrush(RGB(0, 255, 0));
SelectObject(hdc, hBrush);
DeleteObject(hBrush);
- 重新整理視窗
RECT rect;
GetClientRect(&rect);
InvalidateRect(hwnd, &rect, true);
UpdateWindow(hwnd);