0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows10でewdk その10

0
Last updated at Posted at 2026-04-22

概要

windows10でewdk、やってみた。
premakeで.slnと.vcxprojを作って、ewdkのclとmsbuildでcppをビルドする。
サンプル見つけたので、やってみた。

参考にしたページ

写真

image.png

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;
}




以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?