#include "window.h"
#include "Windows.h"
#include "../common/object.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static HINSTANCE hInstance;
static const char *mainWindowClass =
"UiMainWindow";
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {
switch(uMsg) {
case WM_DESTROY:
PostQuitMessage(
0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
void ui_window_init(
void) {
hInstance = GetModuleHandle(
NULL);
WNDCLASSEX wc = {
sizeof(
WNDCLASSEX) };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = mainWindowClass;
wc.hCursor = LoadCursor(
NULL,
IDC_ARROW);
wc.hbrBackground = (
HBRUSH)(
COLOR_WINDOW +
1);
if(!RegisterClassExA(&wc)) {
MessageBox(
NULL,
"RegisterClassEx failed",
"Error",
MB_ICONERROR);
exit(
-1);
}
}
static UiObject* create_window(
const char *title,
void *window_data, bool simple) {
UiObject *obj = uic_object_new_toplevel();
obj->window = window_data;
HWND hwnd = CreateWindowExA(
0,
"UiMainWindow",
title,
WS_OVERLAPPEDWINDOW |
WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,
SW_SHOWNORMAL);
UpdateWindow(hwnd);
return obj;
}
UiObject *ui_window(
const char *title,
void *window_data) {
return create_window(title, window_data,
FALSE);
}