Ask for Help: how to quick show a Gui that contains a lot of pictures?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AAHKUser
Posts: 21
Joined: 19 Jun 2020, 04:31

Ask for Help: how to quick show a Gui that contains a lot of pictures?

Post by AAHKUser » 24 Jan 2022, 03:47

hi, everyone, Im making a gui that show different button in different app, it requires quick sponse, but mine is slow and i have no idea, so Im here ask for help, thank you!

some code from quickquick https://www.reddit.com/r/powerpoint/comments/nlcdjq/quickquick_powerpoint_super_tools_office_hotkeys/

Code: Select all

BNormal := A_ScreenWidth//40    ; 主监视器的宽度和高度, 单位为像素(例如 1024 和 768).
BN = %BNormal%
BSmall := BN/2    ; 小按钮,如关闭,置顶
B2 := BN*2


~MButton::
{        
    if (WinExist("ahk_id" MyGui)){
        GUI %MyGui% : Hide
        return
    }if (WinActive("ahk_exe Code.exe")) {
        gosub, Deafalut_Gui
        gosub, VSC_Gui
        gosub, Show_Gui
        return
    }else if (WinActive("ahk_exe chrome.exe")) {
        gosub, Deafalut_Gui
        gosub, Chrome_Gui
        gosub, Show_Gui
        return
    }else if (WinActive("ahk_class PPTFrameClass")) {
        gosub, Deafalut_Gui
        gosub, PPT_Gui
        gosub, Show_Gui
        return
    } else{
        gosub, Deafalut_Gui
        gosub, Show_Gui
        return
    }
    return
}

Deafalut_Gui:
{

    Gui, MyGui: New, +HwndMyGui
    Gui, MyGui: Default

    Gui, +LastFound  +ToolWindow +Owner -Caption +DPIScale -Theme +AlwaysOnTop   ; +ToolWindow 避免显示任务栏按钮和 alt-tab 菜单项.-Caption.移除背景透明的窗口的边框和标题栏
    Gui, Margin,0,0    ; 整个窗口的边距,不是按钮之间的边距

    ; 第一行,第一个格子分成四个,放置顶和关闭等
    Gui, add, Picture, w%BSmall% H%BSmall% x0 y0, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp x%BSmall% y0 gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp x0 y%BSmall% gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp x%BSmall% y%BSmall% gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))

    Gui, add, Picture, w%BNormal% h%BNormal% x%BNormal% y0, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    ; 第二行
    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*"  ObjectTest := (LoadPicture("res\img\test.png"))
    Return
}

VSC_Gui:
{
    Gui, add, Picture, w%BNormal% h%BNormal% x0 y%B2% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    
    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))

    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
}

Chrome_Gui:
{
    Gui, add, Picture, w%BNormal% h%BNormal% x0 y%B2% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    
    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Return
}

PPT_Gui:
{
    Gui, add, Picture, w%BNormal% h%BNormal% x0 y%B2% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    
    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    
    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    
    Gui, add, Picture, wp hp x0 yp+%BNormal% gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Gui, add, Picture, wp hp xp+%BNormal% yp gTestFunc, % "HBITMAP:*" ObjectTest := (LoadPicture("res\img\test.png"))
    Return
}



Show_Gui:
{
    Gui, MyGui : Default

    CoordMode Mouse, Screen
    MouseGetPos, XPos, YPos

    XPos_gui :=  XPos - BN*2      ; gui左上角的位置信息
    YPos_gui := YPos - BN*3

    ; 下面这个两个if控制Gui不要超出目前激活窗口的边缘,下边缘不完美
    if (XPos_gui < 0){
        XPos_gui := 0
    } else if (XPos_gui > (A_ScreenWidth - BN*5)){            
        XPos_gui := A_ScreenWidth - BN*5
    }
    
    if (YPos_gui < 0){
        YPos_gui := 0
    } else if (YPos_gui > (A_ScreenHeight - BN*5)){            
        YPos_gui := A_ScreenHeight - BN*5
    }

    Gui, MyGui : Show , x%XPos_gui% y%YPos_gui%     
    return
}

TestFunc:
  msgbox, 111
Return
the gui looks likes this:
image.png
image.png (4.58 KiB) Viewed 396 times
it will be beautiful by adding customized pictures :)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Ask for Help: how to quick show a Gui that contains a lot of pictures?

Post by swagfag » 24 Jan 2022, 05:31

ure constantly creating new guis. create the 3 guis upfront, then only show/hide them accordingly. dont create new guis

AAHKUser
Posts: 21
Joined: 19 Jun 2020, 04:31

Re: Ask for Help: how to quick show a Gui that contains a lot of pictures?

Post by AAHKUser » 24 Jan 2022, 05:47

swagfag wrote:
24 Jan 2022, 05:31
ure constantly creating new guis. create the 3 guis upfront, then only show/hide them accordingly. dont create new guis
thank you for your quick response, may you tell me any clue or code about the show/hide gosub? I have tried to gosub in the begining before, but i dont know how to make them show later

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Ask for Help: how to quick show a Gui that contains a lot of pictures?

Post by swagfag » 24 Jan 2022, 06:27

Code: Select all

Gui New, +HwndhRed
Gui Color, Red
Gui Show, w200 h200 Hide

Gui New, +HwndhGreen
Gui Color, Green
Gui Show, w200 h200 Hide

Gui New, +HwndhBlue
Gui Color, Blue
Gui Show, w200 h200 Hide

1::
	Gui %hRed%: Show
	Gui %hGreen%: Hide
	Gui %hBlue%: Hide
return

2::
	Gui %hRed%: Hide
	Gui %hGreen%: Show
	Gui %hBlue%: Hide
return

3::
	Gui %hRed%: Hide
	Gui %hGreen%: Hide
	Gui %hBlue%: Show
return

AAHKUser
Posts: 21
Joined: 19 Jun 2020, 04:31

Re: Ask for Help: how to quick show a Gui that contains a lot of pictures?

Post by AAHKUser » 24 Jan 2022, 07:43

swagfag wrote:
24 Jan 2022, 06:27

Code: Select all

Gui New, +HwndhRed
Gui Color, Red
Gui Show, w200 h200 Hide

Gui New, +HwndhGreen
Gui Color, Green
Gui Show, w200 h200 Hide

Gui New, +HwndhBlue
Gui Color, Blue
Gui Show, w200 h200 Hide

1::
	Gui %hRed%: Show
	Gui %hGreen%: Hide
	Gui %hBlue%: Hide
return

2::
	Gui %hRed%: Hide
	Gui %hGreen%: Show
	Gui %hBlue%: Hide
return

3::
	Gui %hRed%: Hide
	Gui %hGreen%: Hide
	Gui %hBlue%: Show
return
thank you! i also found some old topics do the same thing, and i am trying it, it works, but make new issues, im working on it:)

Post Reply

Return to “Ask for Help (v1)”