Kaynağa Gözat

Add Windows compatibility

Add WNDCLASS parameter to create window method.
master
TheoryOfNekomata 1 yıl önce
ebeveyn
işleme
733488b9de
2 değiştirilmiş dosya ile 37 ekleme ve 8 silme
  1. +36
    -8
      src/main.c
  2. +1
    -0
      src/main.h

+ 36
- 8
src/main.c Dosyayı Görüntüle

@@ -6,11 +6,26 @@

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR pCmdLine, int nCmdShow) {
LPCWSTR windowName = L"Window";
MSG msg;
void* CBR_CreateWindow(CBR_CreateWindowParams params) {
HWND hwnd;
WNDCLASSW wc = *(WNDCLASSW*)params.params;
RegisterClassW(params.params);
LPWSTR title;
MultiByteToWideChar(CP_UTF8, 0, params.title, -1, title, 0);
hwnd = CreateWindowW(
wc.lpszClassName,
title, // TODO fix
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
params.rect.x, params.rect.y, params.rect.width, params.rect.height,
NULL, NULL,
wc.hInstance,
NULL
);

return hwnd;
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
WNDCLASSW wc = {
.style = CS_HREDRAW | CS_VREDRAW,
.cbClsExtra = 0,
@@ -24,14 +39,27 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
.hIcon = LoadIcon(NULL, IDI_APPLICATION),
};

RegisterClassW(&wc);
hwnd = CreateWindowW(wc.lpszClassName, windowName,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);
HWND hwnd = CBR_CreateWindow((CBR_CreateWindowParams){
.rect = (CBR_Rect){
WINDOW_X,
WINDOW_Y,
WINDOW_WIDTH,
WINDOW_HEIGHT
},
.style_flags =
CBR_WINDOW_STYLE_FLAG_TITLED
| CBR_WINDOW_STYLE_FLAG_CLOSABLE
| CBR_WINDOW_STYLE_FLAG_MINIATURIZABLE
| CBR_WINDOW_STYLE_FLAG_RESIZABLE,
.title = "Window Title",
.params = &wc
});

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

MSG msg;

while (GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}


+ 1
- 0
src/main.h Dosyayı Görüntüle

@@ -26,6 +26,7 @@ typedef struct {
CBR_Rect rect;
CBR_WindowStyleFlag style_flags;
const char* title;
void* params;
} CBR_CreateWindowParams;

void* CBR_CreateWindow(CBR_CreateWindowParams);


Yükleniyor…
İptal
Kaydet