Add sciter from separate repo
This commit is contained in:
115
packages/sciter/src/main.zig
Normal file
115
packages/sciter/src/main.zig
Normal file
@@ -0,0 +1,115 @@
|
||||
const sciter = @import("sciter.zig");
|
||||
const std = @import("std");
|
||||
const wam = @import("win32").ui.windows_and_messaging;
|
||||
const win32 = @import("win32").foundation;
|
||||
|
||||
const L = std.unicode.utf8ToUtf16LeStringLiteral;
|
||||
const WINAPI = @import("std").builtin.CallingConvention.winapi;
|
||||
|
||||
const html = @embedFile("index.html");
|
||||
|
||||
const min_track_size: win32.POINT = .{ .x = 640, .y = 480 };
|
||||
|
||||
var sciter_api: *sciter.API = undefined;
|
||||
|
||||
pub fn wWinMain(
|
||||
hInstance: std.os.windows.HINSTANCE,
|
||||
hPrevInstance: ?std.os.windows.HINSTANCE,
|
||||
lpCmdLine: [*:0]u16,
|
||||
nCmdShow: i32,
|
||||
) i32 {
|
||||
_ = hPrevInstance;
|
||||
_ = lpCmdLine;
|
||||
|
||||
const sciter_module = std.os.windows.LoadLibraryW(L("sciter.dll")) catch |err| {
|
||||
_ = wam.MessageBoxW(
|
||||
null,
|
||||
switch (err) {
|
||||
error.FileNotFound => L("Couldn't find sciter.dll."),
|
||||
else => L("An unknown error occured while trying to load sciter.dll."),
|
||||
},
|
||||
L("Critical error"),
|
||||
wam.MB_ICONHAND,
|
||||
);
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
const sciter_api_fn: *const fn () ?*sciter.API = @ptrCast(std.os.windows.kernel32.GetProcAddress(sciter_module, "SciterAPI") orelse {
|
||||
_ = wam.MessageBoxW(null, L("Couldn't load Sciter API."), L("Critical error"), wam.MB_ICONHAND);
|
||||
std.posix.exit(1);
|
||||
});
|
||||
|
||||
sciter_api = sciter_api_fn() orelse {
|
||||
_ = wam.MessageBoxW(null, L("Couldn't load Sciter API."), L("Critical error"), wam.MB_ICONHAND);
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
std.debug.print("Sciter API version is: 0x{X:0>8}\n", .{sciter_api.version});
|
||||
|
||||
const wc = std.mem.zeroInit(wam.WNDCLASSEXW, .{
|
||||
.cbSize = @sizeOf(wam.WNDCLASSEXW),
|
||||
.lpfnWndProc = &WindowProc,
|
||||
.hInstance = hInstance,
|
||||
.hIcon = wam.LoadIconW(null, wam.IDI_APPLICATION),
|
||||
.hCursor = wam.LoadCursorW(null, wam.IDC_ARROW),
|
||||
.lpszClassName = L("SCITER_WINDOW"),
|
||||
});
|
||||
|
||||
const atom = wam.RegisterClassExW(&wc);
|
||||
std.debug.assert(atom != 0);
|
||||
|
||||
const hwnd = wam.CreateWindowExW(
|
||||
wam.WS_EX_APPWINDOW,
|
||||
wc.lpszClassName,
|
||||
L("Sciter Demo"),
|
||||
wam.WS_OVERLAPPEDWINDOW,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
null,
|
||||
null,
|
||||
wc.hInstance,
|
||||
null,
|
||||
) orelse {
|
||||
_ = wam.MessageBoxW(null, L("Couldn't create window."), L("Critical error"), wam.MB_ICONHAND);
|
||||
std.posix.exit(1);
|
||||
};
|
||||
|
||||
_ = sciter_api.SciterLoadHtml(hwnd, html, html.len, L("/"));
|
||||
_ = wam.ShowWindow(hwnd, @bitCast(nCmdShow));
|
||||
|
||||
var msg = std.mem.zeroes(wam.MSG);
|
||||
while (wam.GetMessageW(&msg, null, 0, 0) > 0) {
|
||||
_ = wam.TranslateMessage(&msg);
|
||||
_ = wam.DispatchMessageW(&msg);
|
||||
}
|
||||
|
||||
return @bitCast(@as(u32, @truncate(msg.wParam)));
|
||||
}
|
||||
|
||||
fn WindowProc(
|
||||
hwnd: win32.HWND,
|
||||
uMsg: u32,
|
||||
wParam: win32.WPARAM,
|
||||
lParam: win32.LPARAM,
|
||||
) callconv(WINAPI) win32.LRESULT {
|
||||
switch (uMsg) {
|
||||
wam.WM_DESTROY => {
|
||||
wam.PostQuitMessage(0);
|
||||
},
|
||||
wam.WM_GETMINMAXINFO => {
|
||||
const mmi: *wam.MINMAXINFO = @ptrFromInt(@as(usize, @bitCast(lParam)));
|
||||
mmi.ptMinTrackSize = min_track_size;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
var handled: sciter.Bool = .FALSE;
|
||||
const result = sciter_api.SciterProcND(hwnd, uMsg, wParam, lParam, &handled);
|
||||
if (handled != .FALSE) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return wam.DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
Reference in New Issue
Block a user