Stacking up GUIS

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Stacking up GUIS

22 Jan 2019, 15:31

I have a dream of making a GUI show image of pictures on a folder. That one is easy, I know

But how do I make it get stacked. Let's say, there is 1 .jpg on a folder then shows 1 GUI, it moves to another folder on X seconds. If I add 3 more .jpgs on folder, shows a GUI with those 3 .jpgs. and cycle repeats.

Is there a way of doing this?

I'll tackle at this at night after work but if you guys have any tips. I am all "eyes"
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Stacking up GUIS

22 Jan 2019, 16:29

I'm not sure if I understood your request...

Here's an example that will open PNG images in a folder:

Code: Select all

#SingleInstance, Force
#Persistent

ListImages := ""

SetTimer, Timer1, 1000
GoSub, Timer1
return

Timer1:
	Loop, Files, C:\Users\User\Downloads\Photos\*.png, F
	{
		ListImages .= A_LoopFileLongPath "`n"
	}
	
	Sort, ListImages, U
	
	StrReplace(ListImages, "`n", "`n", LineCount)
	
	Loop, Parse, ListImages, `n
	{
		If (A_Index > LineCount) {
			Break
		}
		
		ShowGUI(A_LoopField)
	}
return


ShowGUI(ImagePath) {
	If WinExist("AutoHotkey-" ImagePath " ahk_class AutoHotkeyGUI") {
		return
	}

	Gui, New
	Gui, Margin, 0, 0
	Gui, Add, Picture, w400 h400, % ImagePath
	Gui, Show, w400 h400, % "AutoHotkey-" ImagePath
}
fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Re: Stacking up GUIS

22 Jan 2019, 23:18

TheDewd wrote:
22 Jan 2019, 16:29
I'm not sure if I understood your request...

Here's an example that will open PNG images in a folder:

Code: Select all

#SingleInstance, Force
#Persistent

ListImages := ""

SetTimer, Timer1, 1000
GoSub, Timer1
return

Timer1:
	Loop, Files, C:\Users\User\Downloads\Photos\*.png, F
	{
		ListImages .= A_LoopFileLongPath "`n"
	}
	
	Sort, ListImages, U
	
	StrReplace(ListImages, "`n", "`n", LineCount)
	
	Loop, Parse, ListImages, `n
	{
		If (A_Index > LineCount) {
			Break
		}
		
		ShowGUI(A_LoopField)
	}
return


ShowGUI(ImagePath) {
	If WinExist("AutoHotkey-" ImagePath " ahk_class AutoHotkeyGUI") {
		return
	}

	Gui, New
	Gui, Margin, 0, 0
	Gui, Add, Picture, w400 h400, % ImagePath
	Gui, Show, w400 h400, % "AutoHotkey-" ImagePath
}
Thank you for your idea. it works as expected. I think the idea was too ambigious. I have a script that prints images as they are uploaded into a folder. At the moment I only have a little notification on the bottom right corner that tells what is printing and a progress bar. but my greediness wanted more. I wanted to show the picture as it was printing. But then I realized that would take me a sht lot of time to work on it. So I am giving up on it until I have time.

This is the script if you are interested.

Code: Select all

#Persistent
#SingleInstance, force

;CREDITS TO /u/trashdigger

;MsgBox, % ComObjCreate("Scripting.FileSystemObject").GetFolder(A_MyDocuments).Files.Count ;counts only files exc. folders
;MsgBox, % ComObjCreate("Shell.Application").NameSpace(A_MyDocuments).Items.Count ;counts all items inc. folders

;variables

root = %A_ScriptDir%\
printpath = Print
printedpath = Printed
lobbypath = Lobby
errorpath = Error
iconpath = %A_ScriptDir%\printer.png
tray_trigger = Up to date

Menu, Tray, NoStandard
Menu, Tray, Icon, %iconpath%
Menu, Tray, Add, Printed Folder, PrintedF
Menu, Tray, Add, Print Folder, PrintF
Menu, Tray, Add, Lobby Folder, LobbyF
Menu, Tray, Add
Menu, Tray, Add, Printer Settings, PrinterS
Menu, Tray, Add, Toggle Pause, tpause
Menu, Tray, Add
Menu, Tray, Add, Edit, Edit
Menu, Tray, Add, Exit, Exit

Gui, pb:+AlwaysOnTop +ToolWindow -caption +LastFound +border ;sysmenu = min,max,close and icon ;+Border ;caption = the border and titlebar ; toolwindow = taskbar button & alt-tab; 
Gui, pb:Color, Red
Gui, pb:font, bold
Gui, pb:Add, Text, x26 y10, IMPRIMIENDO...
Gui, pb:Add, Progress, x6 y28 w130 h25 vProg Range0-1000
Gui, pb:Add, Button, x25 y60 w100 h30 gCancelar, X

SetTimer, WatchMove, 200
SetTimer, WatchPrint, 1000

PleasantNotify("AUTO PRINTER", "EMPEZANDO A DETECTAR FOTOS...", 190, 100, "b r", "3")

Return

Edit:
    Edit
    return

PrintF:
    Run, % root printpath
    return

PrintedF:
    Run, % root printedpath
    return

LobbyF:
    Run, % root lobbypath
    return

PrinterS:
    Run, control printers
    return

tpause:
    Pause, toggle
    return

Exit:
    ExitApp
    return

Cancelar:
    Gui, pb:Cancel
    FileMove, %root%%printpath%, %root%%errorpath%, 1
    Sleep, 2000
    ExitApp
    return

showpb:
	Gui, pb:Show, NoActivate w150 h94, pb
	WinGetPos X, Y, Width, Height, pb
	MaxX := A_ScreenWidth - Width -40 ; This will put the Gui to the right
	MaxY := A_ScreenHeight - Height -150 ; This will put the Gui above the taskbar, you just need to adjust the "30" value as you want
	WinMove pb, ,%MaxX%, %MaxY%
	MyProgress(3000)   ;5000 is 5 seconds
	return

WatchMove:
    IfExist %root%%lobbypath%\*.jpg
    {
        Loop, %root%%lobbypath%\*.jpg
        {
            FileLongName = %A_LoopFileLongPath%
            FileName = %A_LoopFileName%
            FileMove, %A_LoopFileLongPath%, %root%%printpath%, 1
        }
    }
Return

WatchPrint:
    ;~ files_in_folder := ComObjCreate("Scripting.FileSystemObject").GetFolder(root printpath).Files.Count ;will compare if holder is same as this var. if same it will reset script and move all files to ERROR folder.
        ;~ If files_in_folder_holder = files_in_folder
            ;~ {
                ;~ FileMove, %root%%printpath%, %root%%errorpath%, 1
                ;~ Sleep 2000 ;just to make sure all files moved.
            ;~ }
    IfExist %root%%printpath%\*.jpg ; will only proceed if there is any picture inside folder.
    {
        FileCount = 0
        Loop, %root%%printpath%\*.jpg ;loops the folder
        {
            FileCount +=1
            FileLongName%FileCount% = %A_LoopFileLongPath%
            FileName%FileCount% = %A_LoopFileName%
        }
        PleasantNotify("AUTO PRINTER", "Esperando 15 Segundos Para Ver Si Hay Mas Fotos Para Imprimir", 190, 120, "b r", "16")
        pn_mod_msg("Esperando 15 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000        
        pn_mod_msg("Esperando 14 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 13 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 12 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 11 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 10 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 9 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 8 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 7 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 6 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 5 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 4 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 3 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 2 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        Sleep, 1000
        pn_mod_msg("Esperando 1 Segundos Para Ver Si Hay Mas Fotos Para Imprimir")
        
        syncstate := GetInfoFromTrayIcon("dropbox.exe").ToolTip
        
        Sleep, 2000
        
        FileCount = 0
        Loop, %root%%printpath%\*.jpg ;loops the folder
        {
            FileCount +=1
            FileLongName%FileCount% = %A_LoopFileLongPath%
            FileName%FileCount% = %A_LoopFileName%
        }
        
        syncstate := GetInfoFromTrayIcon("dropbox.exe").ToolTip
    } else {
        return
    }
    if syncstate contains %tray_trigger%
        {
        SetTimer, WatchMove, Off ;turn off moving while printing commences.
        If FileCount = 1
            {
                FileTrueName = %FileLongName1%
                FileName = %FileName1%
                
                ;~ files_in_folder := ComObjCreate("Scripting.FileSystemObject").GetFolder(root printpath).Files.Count
                ;~ files_in_folder_holder := files_in_folder
                
                PleasantNotify("AUTO PRINTER", "Imprimiendo 1 Sola Foto" FileName,200,100, "b r", "5")
                
                RunWait, "C:\Program Files\IrfanView\i_view64.exe" "%FileTrueName%" /bf /print,,hide         ; /c = close /k = kiosk mode to show errors            
				
				gosub, showpb
				Sleep, 3000
                Gui, pb:Cancel
                FileMove, %FileTrueName%, %root%%printedpath%, 1
                Sleep, 2000 ;ADDED WAIT TIMES TO ENSURE THE FILE MOVES
                SetTimer, WatchMove, On ;turn watchmove back on after printing is dealt with.
                return
            } else { ;if Filecount was not 1
            Loop %FileCount% ;if there is more than 1 file to print
                {
                FileTrueName := FileLongName%A_Index%
                FileName := FileName%A_Index%
                If A_Index = 1 
                    {
                    TipCount = 0
                    PrintList := "C:\Program Files\IrfanView\i_view64.exe /print /panorama=(1," Chr(34) FileTrueName Chr(34)
                    PrintListTip%TipCount% := FileName
                    } else {
                    If (OddOrEven(A_Index)) = "Odd"
                        {
                        If A_Index = % FileCount
                            {
                            TipCount += 1
                            PrintList := PrintList Chr(34) "`nC:\Program Files\IrfanView\i_view64.exe " Chr(34) FileTrueName Chr(34) " /print"
                            PrintListTip%TipCount% = %FileName%
                            break
                            }
                        TipCount += 1
                        PrintList := PrintList "`nC:\Program Files\IrfanView\i_view64.exe /bf /print /panorama=(1," Chr(34) FileTrueName Chr(34)
                        PrintListTip%TipCount% = %FileName%
                        } else {
                        PrintList := PrintList "," Chr(34) FileTrueName Chr(34) ")"
                        PrintListTip := PrintListTip%TipCount%
                        PrintListTip%TipCount% = %PrintListTip% and %FileName%
                        }
                    }
                }
            }
        TipCount = 0
        Loop, parse, PrintList, `n
            {
            ToolTipVar := PrintListTip%TipCount%
            PleasantNotify("AUTO PRINTER", "Imprimiendo 2 o Más Fotos",190,100, "b r", "5")
            RunWait, %A_LoopField%,,hide
			gosub, showpb
            sleep 3000
            TipCount += 1
            }
        Gui, pb:Cancel
        FileMove, %root%%printpath%\*.jpg, %root%%printedpath%, 1
        SetTimer, WatchMove, On ;turn watchmove back on after printing is dealt with.
        Return
        } else {
        goto WatchPrint
        }

return


;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////
;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////
;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////
;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////
;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////
;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////
;//////////////////////////////////////////888888888888*****************8888888888888888888888888888888888888///////////////////////////////


OddOrEven(num)
{
return ((Num & 1) != 0) ? "Odd" : "Even"
}

PleasantNotify(title, message, pnW=700, pnH=300, position="b r", time=10) {
    global pn_title, pn_msg, PN_hwnd, w, h
	Notify_Destroy()
	Gui, Notify: +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound
	PN_hwnd := WinExist()
	WinSet, ExStyle, +0x20
	WinSet, Transparent, 0
	Gui, Notify: Color, #202020 ;0xF2F2F0 ;BG COLOR
	Gui, Notify: Font, c0x07D82F s12 wBold, Segoe UI ;c0x07D82F ;TITLE COLOR
	Gui, Notify: Add, Text, % " x" 20 " y" 12 " w" pnW-20 " vpn_title", % title
	Gui, Notify: Font, c0xF2F2F0 s10 wRegular ;TEXT COLOR
	Gui, Notify: Add, Text, % " x" 20 " y" 56 " w" pnW-20 " h" pnH-56 " vpn_msg", % message
	RealW := pnW + 30
	RealH := pnH + 40
	Gui, Notify: Show, W%RealW% H%RealH% NoActivate
	WinMove(PN_hwnd, position)
	if A_ScreenDPI = 96
		WinSet, Region,0-0 w%pnW% h%pnH% R40-40,%A_ScriptName%
	/* For Screen text size 125%
	if A_ScreenDPI = 120
		WinSet, Region, 0-0 w800 h230 R40-40, %A_ScriptName%
	*/
	winfade("ahk_id " PN_hwnd,210,5)
	if (time <> "P")
	{
		Closetick := time*1000
		SetTimer, ByeNotify, % Closetick
	}
}

Notify_Destroy() {
	global PN_hwnd
	ByeNotify:
	SetTimer, ByeNotify, Off
    winfade("ahk_id " PN_hwnd,0,5)
    Gui, Notify: Destroy
	return
}

pn_mod_title(title) {
	global pn_title
	GuiControl, Notify: Text,pn_title, % title
}

pn_mod_msg(message) {
	global pn_msg
	GuiControl, Notify: Text,pn_msg, % message
}

WinMove(hwnd,position) {
   SysGet, Mon, MonitorWorkArea
   WinGetPos,ix,iy,w,h, ahk_id %hwnd%
   x := InStr(position,"l") ? MonLeft : InStr(position,"hc") ?  (MonRight-w)/2 : InStr(position,"r") ? MonRight - w : ix
   y := InStr(position,"t") ? MonTop : InStr(position,"vc") ?  (MonBottom-h)/2 : InStr(position,"b") ? MonBottom - h : iy
   WinMove, ahk_id %hwnd%,,x,y
}

winfade(w:="",t:=128,i:=1,d:=10) {
    w:=(w="")?("ahk_id " WinActive("A")):w
    t:=(t>255)?255:(t<0)?0:t
    WinGet,s,Transparent,%w%
    s:=(s="")?255:s ;prevent trans unset bug
    WinSet,Transparent,%s%,%w%
    i:=(s<t)?abs(i):-1*abs(i)
    while(k:=(i<0)?(s>t):(s<t)&&WinExist(w)) {
        WinGet,s,Transparent,%w%
        s+=i
        WinSet,Transparent,%s%,%w%
        sleep %d%
    }
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

/*
MsgBox, % "PID = "         info.PID
      . "`nProcessName = " info.ProcessName
      . "`nProcessPath = " info.ProcessPath
      . "`nTooltip = "     info.Tooltip
      . "`nhWnd = "        info.hWnd
      . "`nID = "          info.IconID
      . "`nMsg = "         info.Msg
      . "`nhIcon = "       info.hIcon
*/

GetInfoFromTrayIcon( IndexOrProcessName
                   , TrayOrOverflow := "tray" )  ; "tray" or "NotifyIconOverflowWindow" if IndexOrProcessName is an icon index
{
   static WM_USER := 0x400, TB_BUTTONCOUNT := WM_USER + 24, PtrSize := A_Is64bitOS ? 8 : 4, szTRAYDATA := 16 + PtrSize*2

   DHW_Prev := A_DetectHiddenWindows
   DetectHiddenWindows, On
   WinGet, PID, PID, ahk_class Shell_TrayWnd

   if !IsObject(RemoteBuff := New RemoteBuffer(PID, szTRAYDATA)) {
      DetectHiddenWindows, %DHW_Prev%
      Return, 0, DllCall("MessageBox", Ptr, 0, Str, "Could not create remote buffer`nError " A_LastError, Str, "", UInt, 0)
   }

   ControlGet, hOverflowWindow, hwnd,, ToolbarWindow321, ahk_class NotifyIconOverflowWindow
   for k, v in ["TrayNotifyWnd", "SysPager", "ToolbarWindow32"]
      hTray := DllCall("FindWindowEx", Ptr, k = 1 ? WinExist("ahk_class Shell_TrayWnd") : hTray, Ptr, 0, Str, v, UInt, 0, Ptr)

   if IndexOrProcessName is Integer
      info := GetInfoFromTrayIconIndex(IndexOrProcessName, RemoteBuff, IndexOrProcessName = "Tray" ? hTray : hOverflowWindow)
   else  {
      Loop 2  {
         SendMessage, TB_BUTTONCOUNT,,,, % "ahk_id" hWnd := (A_Index = 1 ? hTray : hOverflowWindow)
         Loop % ErrorLevel  {
            info := GetInfoFromTrayIconIndex(A_Index, RemoteBuff, hWnd)
            if (info.ProcessName = IndexOrProcessName && found := true)
               break 2
         }
      }
      if !found  {
         info := ""
         MsgBox, Icon of %IndexOrProcessName% is not found
      }
   }
   DetectHiddenWindows, %DHW_Prev%
   Return info
}

GetInfoFromTrayIconIndex(idx, RemoteBuff, hTray)  {
   static WM_USER := 0x400, TB_GETBUTTON := WM_USER + 23, PtrSize := A_Is64bitOS ? 8 : 4
        , szTBBUTTON := 8 + PtrSize*3, szTRAYDATA := 16 + PtrSize*2, szString := 256

   SendMessage, TB_GETBUTTON, idx - 1, RemoteBuff.ptr,, ahk_id %hTray%
   pTBBUTTON := RemoteBuff.Read(szTBBUTTON)
   offsetTD  := NumGet(pTBBUTTON + 8 + PtrSize)   - RemoteBuff.ptr
   offsetStr := NumGet(pTBBUTTON + 8 + PtrSize*2) - RemoteBuff.ptr

   pTRAYDATA := RemoteBuff.Read(szTRAYDATA, offsetTD)
   hWnd      := WinExist("ahk_id" NumGet(pTRAYDATA+0))
   uID       := NumGet(pTRAYDATA + PtrSize, "UInt")
   nMsg      := NumGet(pTRAYDATA + PtrSize + 4, "UInt")
   hIcon     := NumGet(pTRAYDATA + PtrSize + 16, PtrSize = 4 ? "UInt" : "UInt64")

   pString   := RemoteBuff.Read(szString, offsetStr)
   Tooltip   := StrGet(pString, "UTF-16")

   WinGet, ProcessPath, ProcessPath
   WinGet, Name, ProcessName
   WinGet, PID, PID

   Return { ProcessName: Name, PID: PID, ProcessPath: ProcessPath, hWnd: Format("{:#x}", hWnd)
          , Tooltip: Tooltip, IconID: Format("{:#x}", uID), Msg: Format("{:#x}", nMsg), hIcon: Format("{:#x}", hIcon) }
}

class RemoteBuffer
{
   __New(PID, size)  {
      static PROCESS_VM_OPERATION := 0x8, PROCESS_VM_WRITE := 0x20
           , PROCESS_VM_READ := 0x10, MEM_COMMIT := 0x1000, PAGE_READWRITE := 0x4

      if !(this.hProc := DllCall("OpenProcess", UInt, PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE, Int, 0, UInt, PID, Ptr))
         Return

      if !(this.ptr := DllCall("VirtualAllocEx", Ptr, this.hProc, Ptr, 0, Ptr, size, UInt, MEM_COMMIT, UInt, PAGE_READWRITE, Ptr))
         Return, "", DllCall("CloseHandle", Ptr, this.hProc)

      this.hHeap := DllCall("GetProcessHeap", Ptr)
   }

   __Delete()  {
      DllCall("VirtualFreeEx", Ptr, this.hProc, Ptr, this.ptr, UInt, 0, UInt, MEM_RELEASE := 0x8000)
      DllCall("CloseHandle", Ptr, this.hProc)
      DllCall("HeapFree", Ptr, this.hHeap, UInt, 0, Ptr, this.pHeap)
   }

   Read(size, offset = 0)  {
      (this.pHeap && DllCall("HeapFree", Ptr, this.hHeap, UInt, 0, Ptr, this.pHeap))
      this.pHeap := DllCall("HeapAlloc", Ptr, this.hHeap, UInt, HEAP_ZERO_MEMORY := 0x8, Ptr, size, Ptr)
      if !DllCall("ReadProcessMemory", Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, this.pHeap, Ptr, size, Int, 0)
         Return, 0, DllCall("MessageBox", Ptr, 0, Str, "Failed to read data`nError " A_LastError, Str, "", UInt, 0)
      Return this.pHeap
   }

   Write(pLocalBuff, size, offset = 0)  {
      if !res := DllCall("WriteProcessMemory", Ptr, this.hProc, Ptr, this.ptr + offset, Ptr, pLocalBuff, Ptr, size, PtrP, writtenBytes)
         DllCall("MessageBox", Ptr, 0, Str, "Failed to write data`nError " A_LastError, Str, "", UInt, 0)
      Return writtenBytes
   }
}

MyProgress(seconds){

	global Prog
	static tick,sec,step
	tick:=A_TickCount,   sec:=seconds,   step:=1000/sec
	SetTimer,Update,10
	Return
	Update:
		If (sec<A_TickCount-tick)
			SetTimer,Update,Off
	GuiControl, pb:, Prog, % (A_TickCount-tick)*step
	Return
    
}
yes, it is very extensive. I think I can grab the variables while they are printing to show the GUI then kill it after the image/s get/s moved. But that would give me a lot of headache so I'm giving up on it for now. Until I have more free time :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Draken and 295 guests