【问题标题】:How to create a gutter net overlay as GUI?如何创建一个排水沟网覆盖作为 GUI?
【发布时间】:2019-07-05 02:58:07
【问题描述】:

我想要一个带有 96x96 像素的排水沟网和一个小排水沟边框(可能是一个像素)的全屏 GUI。 GUI 应该是一个透明的覆盖层(应该只显示排水沟网)。

为什么?我经常使用精灵表图像(创建、调整大小或重新排列它们)。我没有支持装订线作为帮助视图的软件。快速准确的调整会很棒。

我使用全屏 GUI 作为$WS_POPUP(无边界)窗口。装订线是具有特定背景颜色的标签。我必须手动创建这些,所以希望您有更好的主意。

到目前为止我的代码:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$iGuiW = @DesktopWidth
$iGuiH = @DesktopHeight
$iGuiGutterSize = 96
$hColor = 0x00FF00

$hGui = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
; From left to right.
GUICtrlCreateLabel("", 0, 0, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)

GUICtrlCreateLabel("", 0, $iGuiGutterSize, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)

GUICtrlCreateLabel("", 0, $iGuiGutterSize * 2, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)

GUICtrlCreateLabel("", 0, $iGuiGutterSize * 3, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)

; From top to bottom.
GUICtrlCreateLabel("", 0, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)

GUICtrlCreateLabel("", $iGuiGutterSize, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)

GUICtrlCreateLabel("", $iGuiGutterSize * 2, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)

GUICtrlCreateLabel("", $iGuiGutterSize * 3, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)

GUISetState( @SW_SHOW, $hGui )

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGui)
            Exit
    EndSwitch
WEnd
  1. 如何让 GUI 除了装订线之外都是透明的?
  2. 如何在不为每一行(行和列)手动设置 label by label 的情况下做到这一点?

是的,它就像一个网格设计,但只是边框作为线条。

【问题讨论】:

    标签: user-interface autoit sprite-sheet


    【解决方案1】:

    注意:

    有点不清楚我的建议是否符合您的想象,但我猜您的意思是类似于网格设计。正如您所提到的,GUI 就像一个覆盖(透明),只有网格线是可见的。

    解决方案在_createGridStructure() 函数中,它使用一些WinAPI 函数来提供这样的网格(矩形设计)。我在分离函数_disposeAndExit() 中提取了您的GUIDelete($hGui)Exit。我还提取了一个函数中的 GUI 创建部分,使其更加灵活。

    方法:

    #include-once
    #include <GuiConstantsEx.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    
    Global $iGuiWidth   = @DesktopWidth
    Global $iGuiHeight  = @DesktopHeight
    Global $iGridSize   = 96       ; change the size if you want
    Global $vGridColor  = 0x00FF00 ; change the grid line color if you want
    Global $hMainGui
    
    Func _createGui()
        $hMainGui = GUICreate( '', $iGuiWidth, $iGuiHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST )
        GUISetBkColor( $vGridColor )
        GUISetState( @SW_SHOW, $hMainGui )
    EndFunc
    
    Func _createGridStructure()
        Local $iGridLinesX = Floor( $iGuiWidth / $iGridSize )
        Local $iGridLinesY = Floor( $iGuiHeight / $iGridSize )
        Local $hMainRegion = _WinAPI_CreateRectRgn( 0, 0, 0, 0 )
    
        For $i = 0 To $iGridLinesX Step 1
            $hRegion = _WinAPI_CreateRectRgn( $i * $iGridSize, 0, ( $i * $iGridSize ) + 1, $iGuiHeight )
            _WinAPI_CombineRgn( $hMainRegion, $hRegion, $hMainRegion, 2 )
            _WinAPI_DeleteObject( $hRegion )
        Next
    
        For $i = 0 To $iGridLinesY Step 1
            $hRegion = _WinAPI_CreateRectRgn( 0, $i * $iGridSize, $iGuiWidth, ( $i * $iGridSize ) + 1 )
            _WinAPI_CombineRgn( $hMainRegion, $hRegion, $hMainRegion, 2 )
            _WinAPI_DeleteObject( $hRegion )
        Next
    
        _WinAPI_SetWindowRgn( $hMainGui, $hMainRegion )
    EndFunc
    
    Func _disposeAndExit()
        GUIDelete( $hMainGui )
        Exit
    EndFunc
    
    _createGui()
    _createGridStructure()
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _disposeAndExit()
        EndSwitch
    WEnd
    

    现在,如果您切换显示器分辨率,您不必手动调整网格线。

    【讨论】:

    • 不要在你的答案中添加“我希望这会帮助你”,因为这在 Stack Overflow 上被认为是“噪音”。而且当然不要将其格式化为块引用,因为它不是引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 2014-10-30
    • 2013-06-02
    • 2012-10-10
    • 2020-09-21
    • 1970-01-01
    • 2014-10-08
    相关资源
    最近更新 更多