5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 06:09:56 +08:00

[windows] Support frameless

This commit is contained in:
Lea Anthony 2021-06-21 09:44:45 +10:00
parent 3644f4ae1e
commit ee6ad0bb27
2 changed files with 13 additions and 7 deletions

View File

@ -40,7 +40,6 @@ type Application struct {
// Logger // Logger
logger logger.CustomLogger logger logger.CustomLogger
} }
func (a *Application) saveMemoryReference(mem unsafe.Pointer) { func (a *Application) saveMemoryReference(mem unsafe.Pointer) {
@ -131,7 +130,6 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string, debug
// Set debug if needed // Set debug if needed
C.SetDebug(app, a.bool2Cint(debug)) C.SetDebug(app, a.bool2Cint(debug))
// TODO: Move frameless to Linux options
if a.config.Frameless { if a.config.Frameless {
C.DisableFrame(a.app) C.DisableFrame(a.app)
} }

View File

@ -144,6 +144,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
break; break;
} }
case WM_SIZE: { case WM_SIZE: {
if ( app == NULL ) {
return 0;
}
if( app->webviewController != nullptr) { if( app->webviewController != nullptr) {
RECT bounds; RECT bounds;
GetClientRect(app->window, &bounds); GetClientRect(app->window, &bounds);
@ -385,7 +388,7 @@ void Run(struct Application* app, int argc, char **argv) {
// Configure translucency // Configure translucency
DWORD dwExStyle = 0; DWORD dwExStyle = 0;
if ( app->windowBackgroundIsTranslucent ) { if ( app->windowBackgroundIsTranslucent) {
dwExStyle = WS_EX_NOREDIRECTIONBITMAP; dwExStyle = WS_EX_NOREDIRECTIONBITMAP;
wc.hbrBackground = CreateSolidBrush(RGB(255,255,255)); wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));
} }
@ -393,13 +396,16 @@ void Run(struct Application* app, int argc, char **argv) {
RegisterClassEx(&wc); RegisterClassEx(&wc);
// Process window style // Process window style
DWORD windowStyle = WS_OVERLAPPEDWINDOW; DWORD windowStyle = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
if (app->resizable == 0) { if (app->resizable == 0) {
windowStyle &= ~WS_MAXIMIZEBOX; windowStyle &= ~WS_MAXIMIZEBOX;
windowStyle &= ~WS_THICKFRAME; windowStyle &= ~WS_THICKFRAME;
} }
if ( app->frame == 0 ) { if ( app->frame == 0 ) {
windowStyle = WS_POPUP; windowStyle &= ~WS_OVERLAPPEDWINDOW;
windowStyle &= ~WS_CAPTION;
windowStyle |= WS_POPUP;
} }
// Create the window. // Create the window.
@ -424,7 +430,7 @@ void Run(struct Application* app, int argc, char **argv) {
} }
// Credit: https://stackoverflow.com/a/35482689 // Credit: https://stackoverflow.com/a/35482689
if( app->disableWindowIcon ) { if( app->disableWindowIcon && app->frame == 1 ) {
int extendedStyle = GetWindowLong(app->window, GWL_EXSTYLE); int extendedStyle = GetWindowLong(app->window, GWL_EXSTYLE);
SetWindowLong(app->window, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME); SetWindowLong(app->window, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
SetWindowPos(nullptr, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); SetWindowPos(nullptr, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
@ -441,7 +447,9 @@ void Run(struct Application* app, int argc, char **argv) {
// Private setTitle as we're on the main thread // Private setTitle as we're on the main thread
setTitle(app, app->title); if( app->frame == 1) {
setTitle(app, app->title);
}
// Store application pointer in window handle // Store application pointer in window handle
SetWindowLongPtr(app->window, GWLP_USERDATA, (LONG_PTR)app); SetWindowLongPtr(app->window, GWLP_USERDATA, (LONG_PTR)app);