PolyPolyline関数は、複数のPolyline関数を実行したものです。

設定した描画単位で線を描画します。

 

〇PolyPolyline関数の宣言は

BOOL PolyPolyline(
  [in] HDC         hdc,
  [in] const POINT *apt,
  [in] const DWORD *asz,
  [in] DWORD       csz
);

パラメータについて

1.  [in] const POINT *apt

描画するPOINTの配列です。

2.  [in] const POINT *apt

各描画のPOINT数を指定する配列へのポインターです。

3.  [in] DWORD       csz

描画する数(描画単位)です。

 

〇プログラム例

 

  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.     COLORREF color;
  9.     LONG R, G, B;
  10.     POINT pt;
  11.     POINT pt1[] = {
  12.         /* 三角形 */
  13.         {50,10},{100,100},{10,100},{10,10},
  14.         /* 四角形 */
  15.         {150,10},{250,10},{250,100},{150,100},{150,10} };
  16.     DWORD dwPolyPoints[] = { 4, 5 };
  17.  
  18.     switch (uMsg)
  19.     {
  20.     case WM_DESTROY:
  21.         PostQuitMessage(0);
  22.         break;
  23.  
  24.     case WM_CREATE:
  25.         ShowWindow(hWnd, SW_SHOW);
  26.         break;
  27.  
  28.     case WM_LBUTTONDOWN: //マウスの左ボタンが押された
  29.         InvalidateRect(hWnd, NULL, TRUE); //クライアント領域を無効化する
  30.         break;
  31.  
  32.     case WM_PAINT:
  33.         hdc = BeginPaint(hWnd, &ps);
  34.         PolyPolyline(hdc, pt1, dwPolyPoints, 2);
  35.         color = GetPixel(hdc, 50, 10);
  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. }

 

〇実行結果

二つのPolylineが描画されます。

終点は、LineToと同様に、描画されません。