调整纵横比以适应窗口大小?

调整纵横比以适应窗口大小?

我使用 ImageGlass 作为主要应用程序来浏览和查看我的照片。

我想创建一个功能,当有人尝试调整窗口大小并显示照片时,它会遵循预定义的纵横比。

这里有两个例子:

例如 1-这是一个 V1 脚本,在 GUI 窗口上执行功能:

#NoEnv
#SingleInstance, Ignore
ClientWidth  := 735 ; you only can set the size of the client area
ClientHeight := 245 ; you only can set the size of the client area
Gui, +AlwaysOnTop +Resize -MaximizeBox +ToolWindow +LastFound  ; added +LastFound for WinGetPos
Gui, Show, w%ClientWidth% h%ClientHeight% NoActivate, Test GUI ; removed unnecessary xCenter and yCenter
WinGetPos, , , GuiWidth, GuiHeight                             ; get the real window size
OnMessage(WM_SIZING := 0x0214, "GuiSizing")                    ; handle WM_SIZING messages
Return
GuiClose:
ExitApp
GuiSizing(WP, LP) {
   ; http://msdn.microsoft.com/en-us/library/ms632647(v=vs.85).aspx
   ; WP : The edge of the window that is being sized.
   ; LP : A pointer to a RECT structure with the screen coordinates of the drag rectangle.
   Global GuiWidth, GuiHeight
   ; The following values passed in WP will keep the ratio
   Static KeepsRatio := {4: "TopLeft", 5: "TopRight", 7: "BottomLeft", 8: "BottomRight"}
   ; The following values passed in WP will resize horizontally
   Static Horizontal := {1: "Left", 2: "Right"}
   ; The following values passed in WP will resize vertically
   Static Vertical   := {3: "Top",  6: "Bottom"}
   Critical
   ; If the ratio will be kept, do nothing
   If !KeepsRatio.HasKey(WP) {
      ; Get the new window rectangle
      X := NumGet(LP + 0,  0, "Int")
      Y := NumGet(LP + 0,  4, "Int")
      W := NumGet(LP + 0,  8, "Int") - X
      H := NumGet(LP + 0, 12, "Int") - Y
      ; If the window will be resized horizontally, adjust the height
      If Horizontal.HasKey(WP)
         NumPut(Y + (W / GuiWidth * GuiHeight), LP + 0, 12, "Int")
      ; Otherwise it will be resized vertically, so adjust the width
      Else
         NumPut(X + (H / GuiHeight * GuiWidth), LP + 0,  8, "Int")
   }
}

例如 2- 与多媒体软件播放器“PotPlayer”中的功能完全相同,如下图所示: 在此处输入图片描述

笔记 :

  • 我从这里找到了作为示例提到的 GUI 脚本:

调整大小时如何保持窗口的纵横比?

  • 我使用 AHK V2 请提供任何帮助!

相关内容