web-view icon indicating copy to clipboard operation
web-view copied to clipboard

Suggestion: Ability to add a top left/tab icon

Open eedahl opened this issue 7 years ago • 3 comments

Following your suggestion I've added an icon to my exe file. It would be nice to also be able to add a top left/tab icon, but at least the naive approach of adding <link rel="icon" src="app-icon.png"> doesn't work. (In fact I can't seem to use local/folder paths at all).

eedahl avatar May 08 '18 19:05 eedahl

You mean the icon that appears in the title bar and task bar?

Doesn't it use the exe icon for that?

Boscop avatar May 08 '18 21:05 Boscop

It uses the exe icon for the task bar, but not for the upper left hand side corner.

https://gyazo.com/5e00afd945c9d862d6734cb23686555e https://gyazo.com/ae15922cb6247b2ff3240ddcf1750796

eedahl avatar May 08 '18 21:05 eedahl

For anyone trying to get this working, this was the change I made to pass the icon from the app to the window:

//webview_edge.cpp

   browser_window(msg_cb_t cb, const char* title, int width, int height, bool resizable)
        : m_cb(cb)
    {
        HINSTANCE hInstance = GetModuleHandle(nullptr);

        HWND currentWindow = GetActiveWindow();

        // "1" is the default icon resource name used by winres 
        HICON parentIcon = (HICON)LoadImage(
            hInstance, 
            MAKEINTRESOURCE(1), 
            IMAGE_ICON, 
            0, 
            0,
            LR_DEFAULTSIZE
        );

        WNDCLASSEX wc;
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.hInstance = hInstance;
        wc.lpfnWndProc = WebviewWndProc;
        wc.lpszClassName = L"webview";
        wc.hIcon = parentIcon; // add the icon here
        RegisterClassEx(&wc);

This is my rust build script:

\\build.rs
use winres;

fn main() {
    let mut res = winres::WindowsResource::new();
    res.set_icon("Micro.ico");
    res.compile().unwrap();
}

I can't think of an easy way to locate the icon used by the taskbar (and so have had to refer to the icon resource by name).

One possibility would be to agree upon a default resource name to be used for the window icon (rather than just 1!). winres supports setting the resource id so this wouldn't cause issues for Rust users.

Jonesey13 avatar Jan 05 '20 16:01 Jonesey13