[win] Initial window working

This commit is contained in:
Lea Anthony 2021-04-24 20:59:00 +10:00
commit 97592fad5c
7 changed files with 105 additions and 7 deletions

View file

@ -97,7 +97,8 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) {
"darwin/universal",
//"linux/amd64",
//"linux/arm-7",
//"windows/amd64",
"windows",
"windows/amd64",
})
if !validPlatformArch.Contains(platform) {
return fmt.Errorf("platform %s is not supported", platform)

View file

@ -10,7 +10,7 @@ require (
github.com/imdario/mergo v0.3.11
github.com/jackmordaunt/icns v1.0.0
github.com/leaanthony/clir v1.0.4
github.com/leaanthony/debme v1.1.1
github.com/leaanthony/debme v1.1.2
github.com/leaanthony/go-ansi-parser v1.0.1
github.com/leaanthony/gosod v1.0.1
github.com/leaanthony/slicer v1.5.0

View file

@ -41,8 +41,9 @@ github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eT
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/leaanthony/clir v1.0.4 h1:Dov2y9zWJmZr7CjaCe86lKa4b5CSxskGAt2yBkoDyiU=
github.com/leaanthony/clir v1.0.4/go.mod h1:k/RBkdkFl18xkkACMCLt09bhiZnrGORoxmomeMvDpE0=
github.com/leaanthony/debme v1.1.1 h1:2CQjJkfrjr4b2VgpDmkq2aghem5R2bNbg1Yg5cKQGBQ=
github.com/leaanthony/debme v1.1.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
github.com/leaanthony/debme v1.1.2 h1:dGeQuj0+xPIlDQzGIjmAU52+yRg85u5pWaaqrdLBjD0=
github.com/leaanthony/debme v1.1.2/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
github.com/leaanthony/go-ansi-parser v1.0.1 h1:97v6c5kYppVsbScf4r/VZdXyQ21KQIfeQOk2DgKxGG4=
github.com/leaanthony/go-ansi-parser v1.0.1/go.mod h1:7arTzgVI47srICYhvgUV4CGd063sGEeoSlych5yeSPM=
github.com/leaanthony/gosod v1.0.1 h1:F+4c3DmEBfigi7oAswCV2RpQ+k4DcNbhuCZUGdBHacQ=

View file

@ -1,5 +1,11 @@
# 3rd Party Licenses
## Webview
Whilst not using the library directly, there is certainly some code that is inspired by or used from the webview library.
Homepage: https://github.com/webview/webview
License: https://github.com/webview/webview/blob/master/LICENSE
## vec
Homepage: https://github.com/rxi/vec
License: https://github.com/rxi/vec/blob/master/LICENSE

View file

@ -1,14 +1,100 @@
// Some code may be inspired by or directly used from Webview.
#include "ffenestri_windows.h"
typedef struct {
} Application;
struct Application{
// Window specific
HWND window;
const char *title;
int width;
int height;
int resizable;
int devtools;
int fullscreen;
int startHidden;
int logLevel;
int hideWindowOnClose;
int minWidth;
int minHeight;
int maxWidth;
int maxHeight;
};
struct Application *NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden, int logLevel, int hideWindowOnClose) {
// Create application
struct Application *result = malloc(sizeof(struct Application));
result->title = title;
result->width = width;
result->height = height;
result->resizable = resizable;
result->devtools = devtools;
result->fullscreen = fullscreen;
result->startHidden = startHidden;
result->logLevel = logLevel;
result->hideWindowOnClose = hideWindowOnClose;
return result;
}
void SetMinWindowSize(struct Application* app, int minWidth, int minHeight) {
app->minWidth = minWidth;
app->minHeight = minHeight;
}
void SetMaxWindowSize(struct Application* app, int maxWidth, int maxHeight) {
app->maxWidth = maxWidth;
app->maxHeight = maxHeight;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
void Run(struct Application* app, int argc, char **argv) {
WNDCLASSEX wc;
HINSTANCE hInstance = GetModuleHandle(NULL);
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.hInstance = hInstance;
wc.lpszClassName = "ffenestri";
wc.lpfnWndProc = WndProc;
// TODO: Trim title to 256 chars
// https://stackoverflow.com/a/20458904
wchar_t wchTitle[256];
MultiByteToWideChar(CP_ACP, 0, app->title, -1, wchTitle, 256);
RegisterClassEx(&wc);
app->window = CreateWindow("ffenestri", wchTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, app->width, app->height, NULL, NULL,
GetModuleHandle(NULL), NULL);
MSG msg;
ShowWindow(app->window, SW_SHOWNORMAL);
UpdateWindow(app->window);
BOOL res;
while ((res = GetMessage(&msg, NULL, 0, 0)) != -1) {
if (msg.hwnd) {
TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
if (msg.message == WM_APP) {
} else if (msg.message == WM_QUIT) {
return;
}
}
}
void DestroyApplication(struct Application* app) {
}

View file

@ -2,6 +2,8 @@ package ffenestri
/*
#cgo windows,amd64 LDFLAGS: -L./windows/x64 -lwebview -lWebView2Loader
#include "ffenestri.h"
#include "ffenestri_windows.h"

View file

@ -1,5 +1,7 @@
#ifndef _FFENESTRI_WINDOWS_
#define _FFENESTRI_WINDOWS_
#ifndef _FFENESTRI_WINDOWS_H
#define _FFENESTRI_WINDOWS_H
#include <windows.h>
#endif