菜单、画笔、画刷的使用

  • 设置菜单项为选中状态
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);

你可能感兴趣的:(MFC)