1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 | #include <windows.h>
struct RenderStruct {
HWND Window;
HDC DC;
HBRUSH Brush;
BITMAPINFO BMPInfo;
void* Memory;
__int64 Style;
__int64 Width;
__int64 Height;
}; RenderStruct Renderer;
struct V3 {
__int64 x;
__int64 y;
__int64 z;
}; V3 Color = {255, 255, 0};
void MakeBrush(BYTE R, BYTE G, BYTE B) {
Renderer.Brush = CreateSolidBrush(RGB(R, G, B));
SelectObject(Renderer.DC, Renderer.Brush);
}
LRESULT CALLBACK TestWinProc(HWND Window, UINT Msg, WPARAM W, LPARAM L) {
LRESULT Result = 0;
static __int64 RepeatedInput = 0;
switch (Msg) {{
} case (WM_KEYDOWN): {
switch (W) {{
} case (VK_ESCAPE): {
ExitProcess(0);
} case (VK_RETURN): {
if (!Renderer.Style) {
SetWindowLong(Window, GWL_STYLE, 282001408); // WS_OVERLAPPEDWINDOW | WS_VISIBLE
PostMessageA(Window, WM_SIZE, W, L);
Renderer.Style = 282001408;
} else {
SetWindowLong(Window, GWL_STYLE, 0);
PostMessageA(Window, WM_SIZE, W, L);
Renderer.Style = 0;
} break;
} case (VK_LEFT): {
if (!RepeatedInput) {
int temp = Color.z;
Color.z = Color.x;
Color.x = temp;
} if (L == 21692417) {
RepeatedInput++;
} else {
RepeatedInput = 0;
} break;
}
} break;
} case (WM_KEYUP): {
RepeatedInput = 0;
break;
} case (WM_SIZE): {
if (Renderer.Memory) {
VirtualFree(Renderer.Memory, 0, MEM_RELEASE);
Renderer.Memory = 0;
} RECT CR; GetClientRect(Window, &CR);
Renderer.BMPInfo = {sizeof(BITMAPINFO), (LONG)(Renderer.Width = CR.right), (LONG)(Renderer.Height = CR.bottom), 1, 32, BI_RGB,};
Renderer.Memory = VirtualAlloc(0, Renderer.Width*Renderer.Height*4, MEM_COMMIT, PAGE_READWRITE);
break;
} case (WM_PAINT): {
if (!Renderer.Brush) MakeBrush(122, 122, 122);
PAINTSTRUCT P;
BeginPaint(Window, &P);
PatBlt(Renderer.DC, 0, 0, P.rcPaint.right, P.rcPaint.bottom, PATCOPY);
EndPaint(Window, &P);
break;
} default: {
Result = DefWindowProc(Window, Msg, W, L);
break;
}
} return Result;
}
void DrawRectangle() {
int* Pixel = (int*)Renderer.Memory + (int)0.4*Renderer.Width + (int)0.4*Renderer.Width*Renderer.Height;
for (int i = 0; i < Renderer.Width * 10; i++) {
*Pixel++ = RGB(Color.x, Color.y, Color.z);
}
}
int CALLBACK WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmndLine, int ShowCmnd) {
WNDCLASS WindowClass = {};
WindowClass.lpszClassName = L"window class";
WindowClass.lpfnWndProc = TestWinProc;
WindowClass.hInstance = Instance;
ATOM A = RegisterClass(&WindowClass);
int CWD = CW_USEDEFAULT;
Renderer.Window = CreateWindow(WindowClass.lpszClassName, L"Test", 0, CWD, CWD, CWD, CWD, 0, 0, Instance, 0);
Renderer.DC = GetDC(Renderer.Window);
SetWindowLong(Renderer.Window, GWL_STYLE, 0);
PostMessageA(Renderer.Window, WM_SIZE, 0, 0);
ShowWindow(Renderer.Window, SW_NORMAL);
for (;;) {
MSG Msg;
PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE);
TranslateMessage(&Msg);
DispatchMessage(&Msg);
DrawRectangle();
StretchDIBits(Renderer.DC, 0, 0, Renderer.Width, Renderer.Height,
0, 0, Renderer.Width, Renderer.Height,
Renderer.Memory, &Renderer.BMPInfo, DIB_RGB_COLORS, SRCCOPY
);
}
}
|