Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frameless window can not be minimized by clicking its taskbar button #1357

Closed
Aues6uen11Z opened this issue Apr 7, 2024 · 6 comments
Closed
Labels

Comments

@Aues6uen11Z
Copy link

Specification

  • pywebview version: 5.0.5
  • operating system: Win10
  • web renderer: Edge

Description

Hi, I found that on my Win10 computer, a frameless window cannot be minimized by clicking its taskbar icon, and this issue can be easily replicated as below.

import webview

webview.create_window('Hello world', 'https://pywebview.flowrl.com/', frameless=True)
webview.start()

I also noticed that Qt exhibit the same problem, with Qt already having a solution in place. Thus, I wonder if pywebview offer similar workarounds? After searching, I haven't come across anyone reporting this issue, so I'd appreciate any assistance on this matter. Many thanks in advance!

@Aues6uen11Z
Copy link
Author

Another problem related to frameless mode, window.maximize() abnormally behaves as full-screen (covering the Windows taskbar), while setting frameless=False is fine. Is there a way to resolve this?

from time import sleep

import webview

def maximize(window):

    sleep(5)
    print('Maximizing window')
    window.maximize()

if __name__ == '__main__':
    window = webview.create_window(
        'Maximize window example', frameless=True, html='<h1>window</h1>'
    )
    webview.start(maximize, window)

@Aues6uen11Z
Copy link
Author

I found that on my Win10 computer, a frameless window cannot be minimized by clicking its taskbar icon

For the first question, I found a solution in C# https://www.fluxbytes.com/csharp/minimize-a-form-without-border-using-the-taskbar/, and asked GPT how to use .NET in Python through pythonnet. Finally, I overwrote the CreateParams property in the BrowserForm class, but it didn’t work. Can someone help me?

# webview/platforms/winforms.py

class BroswerView:
    ...
    class BrowserForm(WinForms.Form):
    ...
    @property
    def CreateParams(self):
        cp = super().CreateParams
        WS_MINIMIZEBOX = 0x20000
        CS_DBLCLKS = 0x8
        cp.Style |= WS_MINIMIZEBOX
        cp.ClassStyle |= CS_DBLCLKS
        return cp

@r0x0r
Copy link
Owner

r0x0r commented Apr 18, 2024

I ran into a similar problem some time ago - form methods cannot be overridden for BrowserForm for some reason.

It can be done, though. See for example overridding WndProc here
I did some investigating on this, but could not arrive to a conclusion why it does not work for pywebview. Ideas welcome.

@Aues6uen11Z
Copy link
Author

WndProc is a method, while CreateParams is a property, and this difference may be causing the different results. I noticed that in C# when overriding CreateParams, there is a get and GPT’s explanation is

In C#, the get keyword is used to define the getter method of a property. The getter method is a special method that is called when you try to read the value of the property.

In your example, the get defines the getter method for the CreateParams property. When you try to read the value of CreateParams, the code block following the get is executed, and its result is returned.

This is a read-only property because it only defines the getter method and does not define a setter method. If you try to modify the value of this property, you will get a compilation error.

In Python, you can use the property decorator to define getter and setter methods. However, due to limitations in pythonnet, you may not be able to directly override C#'s read-only properties in Python. You may need to find other ways to achieve your goal.

After that, I tried different approaches, all of which ended in failure. This matter has exceeded my capabilities...

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 20, 2024
Copy link

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants