概要
windows10でewdk、やってみた。
premakeで.slnと.vcxprojを作って、ewdkのclとmsbuildでcppをビルドする。
サンプル見つけたので、やってみた。
参考にしたページ
写真
premake5コード
workspace "Test2d"
configurations { "Debug", "Release" }
platforms { "x64" }
location "bin"
project "Test2d"
kind "WindowedApp"
language "C++"
architecture "x64"
targetdir "bin/%{cfg.buildcfg}"
files { "src/**.cpp" }
filter "configurations:Debug"
symbols "On"
filter "configurations:Release"
optimize "On"
symbols "On"
サンプルコード
#include <windows.h>
//#include <math.h>
#define _USE_MATH_DEFINES
#include <cmath>
#define WIDTH 800
#define HEIGHT 600
float theta = 0.0f;
float length = 100.0f;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static HDC hdc;
static PAINTSTRUCT ps;
static RECT rect;
switch (msg)
{
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
float cx = rect.right / 2.0f;
float cy = rect.bottom / 2.0f;
float x = length;
float y = 0.0f;
float x_rot = x * cos(theta) - y * sin(theta);
float y_rot = x * sin(theta) + y * cos(theta);
MoveToEx(hdc, (int)cx, (int)cy, NULL);
LineTo(hdc, (int)(cx + x_rot), (int)(cy + y_rot));
EndPaint(hwnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
const char CLASS_NAME[] = "RotateMatrixClass";
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = TEXT("RotateMatrixClass");
RegisterClass(&wc);
HWND hwnd = CreateWindowExA(0, CLASS_NAME, "2D Rotation (Matrix Version)", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WIDTH, HEIGHT, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
theta += 0.02f;
if (theta > 2 * M_PI)
theta -= 2 * M_PI;
InvalidateRect(hwnd, NULL, TRUE);
Sleep(16);
}
}
return 0;
}
以上。
