opening window
This commit is contained in:
parent
213e530d88
commit
be53e6f134
|
@ -1,18 +1,86 @@
|
|||
#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[]) {
|
||||
struct sw_window *win;
|
||||
struct sw_renderer2d *ren;
|
||||
WNDCLASSEXW wndclass = {0};
|
||||
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);
|
||||
ren = sw_renderer2d_create();
|
||||
sw_window_add_renderer(win, ren->renderer, render);
|
||||
sw_window_run(win);
|
||||
RegisterClassExW(&wndclass);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue