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
描画する数(描画単位)です。
〇プログラム例
#include <windows.h>
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
LPCWSTR lpString = TEXT("日本、こんにちは!");
COLORREF color;
LONG R, G, B;
POINT pt;
POINT pt1[] = {
/* 三角形 */
{50,10},{100,100},{10,100},{10,10},
/* 四角形 */
{150,10},{250,10},{250,100},{150,100},{150,10} };
DWORD dwPolyPoints[] = { 4, 5 };
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
ShowWindow(hWnd, SW_SHOW);
break;
case WM_LBUTTONDOWN: //マウスの左ボタンが押された
InvalidateRect(hWnd, NULL, TRUE); //クライアント領域を無効化する
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
PolyPolyline(hdc, pt1, dwPolyPoints, 2);
color = GetPixel(hdc, 50, 10);
R = GetRValue(color);
G = GetGValue(color);
B = GetBValue(color);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0L;
}
int APIENTRY wWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR ipCmdLine,
_In_ int nCmdShow
) {
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("TestWindow");
wcex.hIconSm = NULL;
RegisterClassExW(&wcex);
HWND hWnd = CreateWindowEx(0UL, TEXT("TestWindow"), TEXT("日本"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
〇実行結果
二つのPolylineが描画されます。
終点は、LineToと同様に、描画されません。