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

希望能为“最大化”按钮的功能单独封装一下 #56

Open
Xiaokang2022 opened this issue Jan 10, 2025 · 18 comments
Open

希望能为“最大化”按钮的功能单独封装一下 #56

Xiaokang2022 opened this issue Jan 10, 2025 · 18 comments
Labels
✨ enhancement New feature or request

Comments

@Xiaokang2022
Copy link
Collaborator

此项目的“最大化”按钮在鼠标移至上面悬停时,可以触发 Windows11 的一个与分屏有关的功能,希望能为其单独封装,便于第三方调用。:)

@littlewhitecloud
Copy link
Owner

不是,我刚刚才把这两个函数合并
说实话,我并不喜欢现在这种方法(尤其是通过检查在最大化按钮上悬停)来唤出snaplayout
本质上就是通过调用了api模拟了按下 win + z
我可能会找个时间来把这个函数再分离一下的(最近有点忙,初三寒假要准备高中冬令营选拔

@Xiaokang2022
Copy link
Collaborator Author

有空我研究一下,到时候我会提个 PR,你有空看看我有没有提 PR 就行,到时候审查一下。

主要是这个功能对于完全自定义标题栏十分重要,用户不一定想要此项目自定义的标题栏,因为他们可能不是用 tkinter 开发,可能是 QT 或者别的,那么单独分离该功能将成为该项目的亮点之一。

@littlewhitecloud
Copy link
Owner

littlewhitecloud commented Jan 10, 2025

实际上,我想改良这个方法
我查过了相关的资料,发现其实应该处理WM_NCHITTEST事件并且判断相应的位置给出实际上鼠标碰到的标志(在标题栏还是在最大化按钮)
其中最大化按钮这个事件能够帮我触发snaplayout
但是实际上我在处理这个事件的时候出现很多问题

  • 无法获取坐标位置
  • 返回结果没有效果
  • 导致缩放崩溃
  • ...

这实际上也是我#54想做的(github copliot给的人机代码,运行都运行不了,脑子一热写上去了)

@Xiaokang2022
Copy link
Collaborator Author

如果可以,你可以在该 Issue 下提供一些可能有用资料的链接,我有空也可以尝试改良一下。:)

@littlewhitecloud
Copy link
Owner

littlewhitecloud commented Jan 10, 2025

其实就这个函数:

from ctypes import windll

def call_snaplayout() -> None:
        # 模拟按下 win + z
        windll.user32.keybd_event(91, 0, 0, 0)
        windll.user32.keybd_event(90, 0, 0, 0)
        # 松开
        windll.user32.keybd_event(91, 0, 2, 0)
        windll.user32.keybd_event(90, 0, 2, 0)

这个方法也有弊端,输入法会被静止,窗口也会失去焦点,实际上正常方式调用的就不会有这个问题。

@Xiaokang2022
Copy link
Collaborator Author

之前看到了这个地方,说实话我也觉得这个方法不太好,只能凑合用

@littlewhitecloud
Copy link
Owner

之前看到了这个地方,说实话我也觉得这个方法不太好,只能凑合用

说实话,我并不喜欢现在这种方法(尤其是通过检查在最大化按钮上悬停)来唤出snaplayout

是这样的,我也是这么想的 🤣

@Xiaokang2022
Copy link
Collaborator Author

另外,说个题外话,关于你的 win32material 包,还希望能尽快更新一下版本,我的项目 Actions 测试需要,1.0.6 存在之前指出的问题,导致我项目的测试覆盖率会缺一部分。

你可以看一下你的包被我的 Actions 下载了多少遍(因为测试失败重新安装环境导致的😂):https://pepy.tech/projects/win32material?timeRange=threeMonths&category=version&includeCIDownloads=true&granularity=daily&viewType=chart&versions=1.0.6%2C1.0.5%2C1.0.4

真的非常感谢!!!

@littlewhitecloud
Copy link
Owner

这样做还有好处就是当你鼠标在标题栏上时,系统还会处理相关的事件
image
image
(但是貌似封装就不太可能了)

@littlewhitecloud
Copy link
Owner

另外,说个题外话,关于你的 win32material 包,还希望能尽快更新一下版本,我的项目 Actions 测试需要,1.0.6 存在之前指出的问题,导致我项目的测试覆盖率会缺一部分。

你可以看一下你的包被我的 Actions 下载了多少遍(因为测试失败重新安装环境导致的😂):https://pepy.tech/projects/win32material?timeRange=threeMonths&category=version&includeCIDownloads=true&granularity=daily&viewType=chart&versions=1.0.6%2C1.0.5%2C1.0.4

真的非常感谢!!!

好的,也就是说我再去把版本更新上传到pypi上就可以了对吧

@Xiaokang2022
Copy link
Collaborator Author

好的,也就是说我再去把版本更新上传到pypi上就可以了对吧

对的,非常感谢!

@littlewhitecloud
Copy link
Owner

littlewhitecloud commented Jan 10, 2025

image
image
上传好了,不知道现在有没有问题了

@littlewhitecloud littlewhitecloud added the ✨ enhancement New feature or request label Jan 10, 2025
@Xiaokang2022
Copy link
Collaborator Author

上传好了,不知道现在有没有问题了

上传了就没问题了,其它不用管

@littlewhitecloud
Copy link
Owner

记录一下,不知道怎么卡出来的
image

        def WndProc(hwnd: Any, msg: Any, wp: Any, lp: Any) -> Any:
            """Handle the messages"""
            if msg == WM_NCCALCSIZE and wp:
                lpncsp = NCCALCSIZE_PARAMS.from_address(lp)
                lpncsp.rgrc[0].top += TITLEBAR_REDUCE
                lpncsp.rgrc[0].left += 8
                lpncsp.rgrc[0].right -= 8
                lpncsp.rgrc[0].bottom -= (0 if self.fullscreen else 8)
                return 0
            if msg == WM_NCHITTEST:
                return 9

@littlewhitecloud
Copy link
Owner

记录一下,不知道怎么卡出来的 image

        def WndProc(hwnd: Any, msg: Any, wp: Any, lp: Any) -> Any:
            """Handle the messages"""
            if msg == WM_NCCALCSIZE and wp:
                lpncsp = NCCALCSIZE_PARAMS.from_address(lp)
                lpncsp.rgrc[0].top += TITLEBAR_REDUCE
                lpncsp.rgrc[0].left += 8
                lpncsp.rgrc[0].right -= 8
                lpncsp.rgrc[0].bottom -= (0 if self.fullscreen else 8)
                return 0
            if msg == WM_NCHITTEST:
                return 9

貌似只能在边框处理这个信息
将客户端拓展到非客户端不是很行

@Xiaokang2022
Copy link
Collaborator Author

研究了一下,确实没有比较好的办法

@littlewhitecloud
Copy link
Owner

研究了一下,确实没有比较好的办法

也并不是没有吧,可能处理一下这个事件会比手动触发的要好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants