This repository was archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatgptcode.c
More file actions
104 lines (82 loc) · 2.35 KB
/
chatgptcode.c
File metadata and controls
104 lines (82 loc) · 2.35 KB
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
/**
* Compile with:
*
* C:/Users/User/bin/llvm-mingw-20220323-ucrt-aarch64/llvm-mingw-20220323-ucrt-aarch64/bin/clang.exe -o wt.exe chatgptcode.c -luser32 -lgdi32
*/
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// window class initialization
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = TEXT("MyAppClass");
if (!RegisterClass(&wc))
return 1;
// window creation
HWND hwnd = CreateWindow(
TEXT("MyAppClass"),
TEXT("My Window"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if (!hwnd)
return 1;
// message loop
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
int width = 640;
int height = 480;
int bytesPerPixel = 3;
unsigned char* pixelData = (unsigned char*)malloc(width * height * bytesPerPixel);
for (int i = 0; i < width * height; i++) {
pixelData[i * 3] = i;
}
if (pixelData == NULL)
{
// handle error
}
// populate pixelData array here
BITMAPINFOHEADER psHeaderGlobal = {0};
psHeaderGlobal.biSize = sizeof(BITMAPINFOHEADER);
psHeaderGlobal.biWidth = width;
psHeaderGlobal.biHeight = height;
psHeaderGlobal.biPlanes = 1;
psHeaderGlobal.biBitCount = bytesPerPixel * 8;
BITMAPINFOHEADER* psHeader = &psHeaderGlobal;
void* pPixels = (void*)pixelData;
SetDIBitsToDevice(hdc, 0, 0, width, height, 0, 0, 0, height, pPixels, (BITMAPINFO*)psHeader, DIB_RGB_COLORS);
EndPaint(hwnd, &ps);
free(pixelData);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}