webview
webview copied to clipboard
Customize window icon
Currently, if a developer wants a custom application icon he can put .icns file into the app bundle on MacOS, or use custom resource file on Windows.
This still uses the default application icon on Windows in the window bar, and it uses the default icon on Linux.
It may be possible to add a special icon parameter to the webview structure that would be pixmap data and it would be used as a window icon in Gtk and WINAPI. I don't consider loading icons from files, because I assume most of the webview apps would embed all the resources into a standalone executable, and I don't want to force developers distribute more than one executable file for their apps.
On linux the following API can be used: https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-icon
On windows it's likely to be something like, except that icon should be read from memory buffer:
HANDLE icon = LoadImage(fgDisplay.Instance, "c:\\icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
SendMessage(instance, (UINT)WM_SETICON, ICON_BIG, (LPARAM)icon);
I'm not familiar with this at all, but aren't icons also specified externally in Linux? Something to do with desktop entries? 😕
Set the custom window icon and write an example, because I didn't find the answer on the issue.
Test successed by:
view_windows.go
// +build windows
package cli
/*
#include <windows.h>
void set_window_icon(const void *ptr) {
HWND hwnd = ((const HWND *)ptr)[5]; // x64 offset
SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(3))); // resource id = 3
SendMessageW(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(3)));
}
*/
import "C"
import (
"reflect"
"unsafe"
"github.com/zserge/webview"
)
func setWindowIcon(w webview.WebView) {
ptr := reflect.ValueOf(w).Elem().FieldByName("w").Pointer()
C.set_window_icon(unsafe.Pointer(ptr))
}
Does anyone know how to can set this icon WITHOUT using a resource?
By the way, it seems that Webview2 is planning to add an API for getting favicon, It could be a great idea if favicon in HTML can be the window icon.
Since the last discussion post about this issue dates back a year, I'm curious if there are any plans to implement a C++ function like setIcon() in the near future. Right now, my application only displays an icon in the taskbar due to VS's IDI_ICON1 resource option and a default blue application icon in the top far left of the window bar. Adding an option to set the window icon would greatly improve the user experience.