多角形を描画するには、Polygon関数を使います。

内部はブラシで塗りつぶされます。

 

BOOL Polygon(
  [in] HDC         hdc,
  [in] const POINT *apt,
  [in] int         cpt
);

1.  [in] const POINT *apt,

頂点の配列へのポインターです。

2.  [in] int         cpt

頂点の数です。

 

〇プログラム例

 

  1. #include <windows.h>
  2.  
  3. static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.     HDC hdc;
  6.     PAINTSTRUCT ps;
  7.     LPCWSTR lpString = TEXT("日本、こんにちは!");
  8.     static HBRUSH hBrush[2];
  9.     int i;
  10.     COLORREF color;
  11.     LONG R, G, B;
  12.     POINT pt1[] = { {120,50 }, { 10,200 }, { 320,150 }, };
  13.  
  14.     switch (uMsg)
  15.     {
  16.     case WM_DESTROY:
  17.         for (i = 0; i < 1; i++)
  18.             DeleteObject(hBrush[i]);
  19.         PostQuitMessage(0);
  20.         break;
  21.  
  22.     case WM_CREATE:
  23.         ShowWindow(hWnd, SW_SHOW);
  24.         hBrush[0] = CreateSolidBrush(RGB(0xFF, 0, 0xFF));
  25.         break;
  26.  
  27.     case WM_LBUTTONDOWN: //マウスの左ボタンが押された
  28.         InvalidateRect(hWnd, NULL, TRUE); //クライアント領域を無効化する
  29.         break;
  30.  
  31.     case WM_PAINT:
  32.         hdc = BeginPaint(hWnd, &ps);
  33.         SelectObject(hdc, hBrush[0]);
  34.         Polygon(hdc, pt1, 3);
  35.         color = GetPixel(hdc, 150, 150);
  36.         R = GetRValue(color);
  37.         G = GetGValue(color);
  38.         B = GetBValue(color);
  39.         EndPaint(hWnd, &ps);
  40.         break;
  41.  
  42.     default:
  43.         return DefWindowProc(hWnd, uMsg, wParam, lParam);
  44.     }
  45.     return 0L;
  46. }
  47.  
  48. int APIENTRY wWinMain(
  49.     _In_ HINSTANCE hInstance,
  50.     _In_opt_ HINSTANCE hPrevInstance,
  51.     _In_ LPWSTR ipCmdLine,
  52.     _In_ int nCmdShow
  53. ) {
  54.  
  55.     WNDCLASSEXW wcex;
  56.  
  57.     wcex.cbSize = sizeof(WNDCLASSEX);
  58.  
  59.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  60.     wcex.lpfnWndProc = WndProc;
  61.     wcex.cbClsExtra = 0;
  62.     wcex.cbWndExtra = 0;
  63.     wcex.hInstance = hInstance;
  64.     wcex.hIcon = NULL;
  65.     wcex.hCursor = NULL;
  66.     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  67.     wcex.lpszMenuName = NULL;
  68.     wcex.lpszClassName = TEXT("TestWindow");
  69.     wcex.hIconSm = NULL;
  70.  
  71.     RegisterClassExW(&wcex);
  72.  
  73.     HWND hWnd = CreateWindowEx(0UL, TEXT("TestWindow"), TEXT("日本"), WS_OVERLAPPEDWINDOW,
  74.         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  75.  
  76.     if (!hWnd)
  77.     {
  78.         return FALSE;
  79.     }
  80.  
  81.     MSG msg;
  82.  
  83.     while (GetMessage(&msg, NULL, 0, 0))
  84.     {
  85.         DispatchMessage(&msg);
  86.     }
  87.  
  88.     return (int)msg.wParam;
  89. }

 

〇実行結果

三角形を描画しています。内部は色(0xFF,0,0xFF)で塗りつぶされています。