Compare commits

...

1 Commits

Author SHA1 Message Date
DaniTheSkunk be53e6f134 opening window 2023-04-18 04:32:33 +00:00
1 changed files with 76 additions and 8 deletions

View File

@ -1,18 +1,86 @@
#include <skunkworks.h> #include <skunkworks.h>
void render() { #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
LRESULT wndproc(HWND hwnd, u32 msg, WPARAM wparam, LPARAM lparam);
wchar_t *sw_str_to_wstr(char *str) {
i32 size;
wchar_t *out;
size = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0);
out = malloc(size);
MultiByteToWideChar(CP_UTF8, 0, str, -1, out, size);
return out;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct sw_window *win; WNDCLASSEXW wndclass = {0};
struct sw_renderer2d *ren; HWND hwnd;
sw_init(argc, argv); wndclass.cbSize = sizeof(wndclass);
wndclass.style = 0;
wndclass.lpfnWndProc = wndproc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = 0;
wndclass.hIcon = 0;
wndclass.hCursor = 0;
wndclass.hbrBackground = 0;
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = L"Skunkworks";
wndclass.hIconSm = 0;
win = sw_window_create(sw_vec2i(1280, 720), "example", 0); RegisterClassExW(&wndclass);
ren = sw_renderer2d_create();
sw_window_add_renderer(win, ren->renderer, render);
sw_window_run(win);
hwnd = CreateWindowExW(
0,
L"Skunkworks",
L"Skunkworks test",
WS_POPUPWINDOW | WS_VISIBLE,
(1920 - 1280) / 2,
(1080 - 720) / 2,
1280,
720,
0,
0,
0,
0
);
ShowWindow(hwnd, SW_SHOW);
while (true) {
MSG msg;
while (PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
return 0; return 0;
} }
LRESULT wndproc(HWND hwnd, u32 msg, WPARAM wparam, LPARAM lparam) {
switch (msg) {
case WM_CLOSE:
case WM_KEYDOWN:
exit(0);
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
break;
}
}
return DefWindowProcW(hwnd, msg, wparam, lparam);
}