mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-20 19:09:29 +08:00
[windows] Support translucent windows
This commit is contained in:
parent
62fc489001
commit
b0c522a59a
@ -20,7 +20,7 @@ import (
|
|||||||
#cgo darwin LDFLAGS: -framework WebKit -lobjc
|
#cgo darwin LDFLAGS: -framework WebKit -lobjc
|
||||||
|
|
||||||
#cgo windows CXXFLAGS: -std=c++11
|
#cgo windows CXXFLAGS: -std=c++11
|
||||||
#cgo windows,amd64 LDFLAGS: -L./windows/x64 -lWebView2Loader -lgdi32 -lole32 -lShlwapi -luser32 -loleaut32
|
#cgo windows,amd64 LDFLAGS: -L./windows/x64 -lWebView2Loader -lgdi32 -lole32 -lShlwapi -luser32 -loleaut32 -ldwmapi
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "ffenestri.h"
|
#include "ffenestri.h"
|
||||||
|
@ -9,12 +9,15 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include "windows/WebView2.h"
|
#include "windows/WebView2.h"
|
||||||
|
#include <winuser.h>
|
||||||
#include "effectstructs_windows.h"
|
#include "effectstructs_windows.h"
|
||||||
#include <Shlobj.h>
|
#include <Shlobj.h>
|
||||||
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
DWORD mainThread;
|
DWORD mainThread;
|
||||||
|
|
||||||
|
#define WS_EX_NOREDIRECTIONBITMAP 0x00200000L
|
||||||
|
|
||||||
// --- Assets
|
// --- Assets
|
||||||
extern const unsigned char runtime;
|
extern const unsigned char runtime;
|
||||||
extern const unsigned char *defaultDialogIcons[];
|
extern const unsigned char *defaultDialogIcons[];
|
||||||
@ -67,10 +70,10 @@ struct Application *NewApplication(const char *title, int width, int height, int
|
|||||||
result->maxHeight = 0;
|
result->maxHeight = 0;
|
||||||
|
|
||||||
// Default colour
|
// Default colour
|
||||||
// result->backgroundColour.R = 255;
|
result->backgroundColour.R = 255;
|
||||||
// result->backgroundColour.G = 255;
|
result->backgroundColour.G = 255;
|
||||||
// result->backgroundColour.B = 255;
|
result->backgroundColour.B = 255;
|
||||||
// result->backgroundColour.A = 255;
|
result->backgroundColour.A = 255;
|
||||||
|
|
||||||
// Have a frame by default
|
// Have a frame by default
|
||||||
result->frame = 1;
|
result->frame = 1;
|
||||||
@ -360,24 +363,30 @@ void initialCallback(std::string message) {
|
|||||||
|
|
||||||
void Run(struct Application* app, int argc, char **argv) {
|
void Run(struct Application* app, int argc, char **argv) {
|
||||||
|
|
||||||
WNDCLASSEX wc;
|
// Register the window class.
|
||||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
const wchar_t CLASS_NAME[] = L"Ffenestri";
|
||||||
ZeroMemory(&wc, sizeof(WNDCLASSEX));
|
|
||||||
|
WNDCLASSEX wc = { };
|
||||||
|
|
||||||
wc.cbSize = sizeof(WNDCLASSEX);
|
wc.cbSize = sizeof(WNDCLASSEX);
|
||||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
||||||
wc.hInstance = hInstance;
|
|
||||||
wc.lpszClassName = (LPCWSTR)"ffenestri";
|
|
||||||
wc.lpfnWndProc = WndProc;
|
wc.lpfnWndProc = WndProc;
|
||||||
|
wc.hInstance = GetModuleHandle(NULL);
|
||||||
|
wc.lpszClassName = CLASS_NAME;
|
||||||
|
|
||||||
// TODO: Make option to disable icon
|
// TODO: Make configurable
|
||||||
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(100));
|
wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(100));
|
||||||
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(100));
|
wc.hIconSm = LoadIcon(wc.hInstance, MAKEINTRESOURCE(100));
|
||||||
|
|
||||||
// TODO: Menu
|
// Configure translucency
|
||||||
// wc.lpszMenuName = nullptr;
|
DWORD dwExStyle = 0;
|
||||||
|
if ( app->windowBackgroundIsTranslucent ) {
|
||||||
|
dwExStyle = WS_EX_NOREDIRECTIONBITMAP;
|
||||||
|
wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterClassEx(&wc);
|
||||||
|
|
||||||
// Process window resizable
|
// Process window style
|
||||||
DWORD windowStyle = WS_OVERLAPPEDWINDOW;
|
DWORD windowStyle = WS_OVERLAPPEDWINDOW;
|
||||||
if (app->resizable == 0) {
|
if (app->resizable == 0) {
|
||||||
windowStyle &= ~WS_MAXIMIZEBOX;
|
windowStyle &= ~WS_MAXIMIZEBOX;
|
||||||
@ -387,13 +396,38 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
windowStyle = WS_POPUP;
|
windowStyle = WS_POPUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterClassEx(&wc);
|
// Create the window.
|
||||||
app->window = CreateWindow((LPCWSTR)"ffenestri", (LPCWSTR)"", windowStyle, CW_USEDEFAULT,
|
app->window = CreateWindowEx(
|
||||||
CW_USEDEFAULT, app->width, app->height, NULL, NULL,
|
dwExStyle, // Optional window styles.
|
||||||
hInstance, NULL);
|
CLASS_NAME, // Window class
|
||||||
|
L"", // Window text
|
||||||
|
windowStyle, // Window style
|
||||||
|
|
||||||
|
// Size and position
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
|
||||||
|
|
||||||
|
NULL, // Parent window
|
||||||
|
NULL, // Menu
|
||||||
|
wc.hInstance, // Instance handle
|
||||||
|
NULL // Additional application data
|
||||||
|
);
|
||||||
|
|
||||||
|
if (app->window == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( app->windowBackgroundIsTranslucent ) {
|
||||||
|
|
||||||
|
// Enable the translucent background effect
|
||||||
|
enableTranslucentBackground(app);
|
||||||
|
|
||||||
|
// Setup transparency of main window. This allows the blur to show through.
|
||||||
|
SetLayeredWindowAttributes(app->window,RGB(255,255,255),0,LWA_COLORKEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Private setTitle as we're on the main thread
|
// Private setTitle as we're on the main thread
|
||||||
// TODO: Make sure we check for blank title
|
|
||||||
setTitle(app, app->title);
|
setTitle(app, app->title);
|
||||||
|
|
||||||
// Store application pointer in window handle
|
// Store application pointer in window handle
|
||||||
@ -405,13 +439,10 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
startVisibility = SW_HIDE;
|
startVisibility = SW_HIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( app->windowBackgroundIsTranslucent ) {
|
|
||||||
enableTranslucentBackground(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
// private center() as we are on main thread
|
// private center() as we are on main thread
|
||||||
center(app);
|
center(app);
|
||||||
|
|
||||||
|
// SetLayeredWindowAttributes(app->window,RGB(255,255,255),0,LWA_COLORKEY);
|
||||||
ShowWindow(app->window, startVisibility);
|
ShowWindow(app->window, startVisibility);
|
||||||
UpdateWindow(app->window);
|
UpdateWindow(app->window);
|
||||||
SetFocus(app->window);
|
SetFocus(app->window);
|
||||||
@ -426,10 +457,13 @@ void Run(struct Application* app, int argc, char **argv) {
|
|||||||
app->webviewController->QueryInterface(IID_ICoreWebView2Controller2, (void**)&wc2);
|
app->webviewController->QueryInterface(IID_ICoreWebView2Controller2, (void**)&wc2);
|
||||||
|
|
||||||
COREWEBVIEW2_COLOR wvColor;
|
COREWEBVIEW2_COLOR wvColor;
|
||||||
wvColor.R = 0;
|
wvColor.R = app->backgroundColour.R;
|
||||||
wvColor.G = 0;
|
wvColor.G = app->backgroundColour.G;
|
||||||
wvColor.B = 0;
|
wvColor.B = app->backgroundColour.B;
|
||||||
|
wvColor.A = app->backgroundColour.A == 0 ? 0 : 255;
|
||||||
|
if( app->windowBackgroundIsTranslucent ) {
|
||||||
wvColor.A = 0;
|
wvColor.A = 0;
|
||||||
|
}
|
||||||
HRESULT result = wc2->put_DefaultBackgroundColor(wvColor);
|
HRESULT result = wc2->put_DefaultBackgroundColor(wvColor);
|
||||||
if (!SUCCEEDED(result))
|
if (!SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
@ -630,7 +664,10 @@ void ToggleMinimise(struct Application* app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetColour(struct Application* app, int red, int green, int blue, int alpha) {
|
void SetColour(struct Application* app, int red, int green, int blue, int alpha) {
|
||||||
// TBD
|
app->backgroundColour.R = red;
|
||||||
|
app->backgroundColour.G = green;
|
||||||
|
app->backgroundColour.B = blue;
|
||||||
|
app->backgroundColour.A = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSize(struct Application* app, int width, int height) {
|
void SetSize(struct Application* app, int width, int height) {
|
||||||
|
@ -5,7 +5,7 @@ import "C"
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
#cgo windows CXXFLAGS: -std=c++11
|
#cgo windows CXXFLAGS: -std=c++11
|
||||||
#cgo windows,amd64 LDFLAGS: -lgdi32 -lole32 -lShlwapi -luser32 -loleaut32
|
#cgo windows,amd64 LDFLAGS: -lgdi32 -lole32 -lShlwapi -luser32 -loleaut32 -ldwmapi
|
||||||
|
|
||||||
#include "ffenestri.h"
|
#include "ffenestri.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user