Dynamic GUI numbers

Get help with using AutoHotkey and its commands and hotkeys
User avatar
coder_chick
Posts: 185
Joined: 05 Nov 2015, 10:43

Dynamic GUI numbers

20 Aug 2019, 21:20

I have a gui (#2) that has a button that takes the user to the ListFiles section below. However, the gui2 windows stays open, and a user can select a different partition letter and press the button again to create a new gui and generate a list of ost and pst files on that partition. However, I need the gui numbers to be dynamic so that it generates a unique gui each time the button is pressed. How do I do this?

Code: Select all

ListFiles:
Gui,2:Submit,nohide

FileAppend,Filename|Extension|Size|Modified|Accessed|Created|FullPath`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
Gui,3: Add, Text, x12 y9 w690 h90 vVar,%Var%
Gui,3: Show, w720 h133,%AppName%

Loop, C:\*.* ,0,1 ;0 means only files are retrieved and 1 means subfolders are recursed.
{
GuiControl,3:,Var,%A_LoopFileFullPath%
if A_LoopFileExt in pst,ost
{
FileAppend,%A_LoopFileName%|%A_LoopFileExt%|%A_LoopFileSize%|%A_LoopFileTimeModified%|%A_LoopFileTimeAccessed%|%A_LoopFileTimeAccessed%|%A_LoopFileFullPath%`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
}
}

3GuiClose:
FileAppend,[Directory Listing Exited Before Finishing!!]`n,%OutputFolder%\%FileListing%(%Partition%_Partition).txt
Gui,3: destroy
♥ ❤ ❥ coder_chick ♥ ❤ ❥
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

Re: Dynamic GUI numbers

20 Aug 2019, 22:28

I didn't look too much into it, but maybe it is what you need.

Globally Unique IDentifier (GUID) by jNizM
Image
User avatar
coder_chick
Posts: 185
Joined: 05 Nov 2015, 10:43

Re: Dynamic GUI numbers

20 Aug 2019, 23:18

Not sure that is what I am looking for.

Basically, I want it to make it GUI,3 the first button click, Gui,4 the next, and so on.
♥ ❤ ❥ coder_chick ♥ ❤ ❥
User avatar
coder_chick
Posts: 185
Joined: 05 Nov 2015, 10:43

Re: Dynamic GUI numbers

21 Aug 2019, 01:13

Omg this is driving me nuts. Someone must know how to address this. AHK gods --- where are you?!

One button - each time its pressed, it creates a gui window (i.e. the gui numbers will need to increment).
♥ ❤ ❥ coder_chick ♥ ❤ ❥
User avatar
coder_chick
Posts: 185
Joined: 05 Nov 2015, 10:43

Re: Dynamic GUI numbers

21 Aug 2019, 01:59

I think that might be it, but after reading and messing around, I am struggling to figure out how to implement that. Any ideas using the code I provided?
♥ ❤ ❥ coder_chick ♥ ❤ ❥
just me
Posts: 6511
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Dynamic GUI numbers

21 Aug 2019, 02:53

GUI Events, Threads, and Subroutines
Clicking on a control while its g-label is already running from a prior click will have no effect and the event is discarded.
Also, if you really want to run multiple file-loops simultaneously, they'd have to run in different threads.
User avatar
coder_chick
Posts: 185
Joined: 05 Nov 2015, 10:43

Re: Dynamic GUI numbers

22 Aug 2019, 02:21

Forgive me, I'm not super savvy of a coder. Can you all help me adjust my code to make it work? I'm much more of visual learner, so once I see it, I can usually know it for next time.

I have two issues I need help with:
1) I want it so that each time the Create File Listing button is selected, it spawns a new GUI and starts the listing for that selected partition. This means I could select the C drive and then select the D drive drive and have two guis creating a directory listing at once.
2) Can someone help me with the time format? I basically want all the timestamps for the the date fields in the directory listing to be in the following format: yyyy-MM-dd hh:mm:ss tt

Code: Select all

Gui, 2:Add, Text, x12 y9 w90 h20 , Source Partition:
Gui, 2:Add, DropDownList, x102 y9 w80 h500 vPartitionLetter, %list%
Gui, 2:Add, Button, x192 y9 w190 h20 gDiskManagement, Open Disk Management
Gui, 2:Add, Text, x12 y49 w190 h20 , Log Key File Extensions (one per line)
Gui, 2:Add, Edit, x12 y79 w380 h140 ,PST
Gui, 2:Add, Button, x12 y229 w120 h30 gListFiles, Create File Listing
Gui, 2:Add, Text, x422 y9 w110 h20 gIndexStatus, Check Indexing Status
Gui, 2:Add, Button, x532 y-1 w110 h30 gIndexStatus, Open
Gui, 2:Add, Text, x422 y39 w110 h20 , Screenshot (F11)
Gui, 2:Add, Button, x532 y29 w110 h30 gScreenshot , Screenshot
Gui, 2:Add, Text, x422 y69 w190 h20 , Log Comments:
Gui, 2:Add, Edit, x422 y89 w360 h130 vcomment ,
Gui, 2:Add, Button, x662 y219 w120 h30 gLogComment, Add Comment
; Generated using SmartGUI Creator 4.0
Gui, 2:Show, x477 y581 h289 w807,%AppName%
Return

2GuiClose:
ExitApp

DiskManagement:
Run, DiskMgmt.msc
return

Screenshot:
screenshot_timestamp = %A_Now%
Run,"nircmd.exe" savescreenshot "%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
sleep,1000
run,"%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
return

F11::
IfExist,%ScreenshotFolder%
{
	screenshot_timestamp = %A_Now%
Run,"nircmd.exe" savescreenshot "%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
sleep,1000
run,"%ScreenshotFolder%\screenshot(%screenshot_timestamp%).png"
}
return

LogComment:
Gui,2:Submit,nohide
FileAppend,COMMENT:%comment%`n,%OutputFolder%\%ProcessLog%.txt
Msgbox,Comment added to process log. You can add more.
GuiControl,2:,comment,
return


IndexStatus:
Run, control.exe srchadmin.dll
;Run, rundll32.exe shell32.dll,Control_RunDLL srchadmin.dll
;Run, control /name Microsoft.IndexingOptions
return

ListFiles:
Gui,2:Submit,nohide
FormatTime,TimeString,,yyyy-MM-dd hh:mm:ss tt
FileAppend,Filename|Extension|Size|Modified|Accessed|Created|FullPath`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
Gui,3: Add, Text, x12 y9 w690 h90 vVar,%Var%
Gui,3: Show, w720 h133,%AppName%
Loop, C:\*.* ,0,1 ;0 means only files are retrieved and 1 means subfolders are recursed.
{
GuiControl,3:,Var,%A_LoopFileFullPath%
if A_LoopFileExt in pst,ost
{
FileAppend,%A_LoopFileName%|%A_LoopFileExt%|%A_LoopFileSize%|%A_LoopFileTimeModified%|%A_LoopFileTimeAccessed%|%A_LoopFileTimeAccessed%|%A_LoopFileFullPath%`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
}
}
FileAppend,[DIRECTORY LISTING FINISHED]`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt


;========================METHODS================================================
checkavailabledriveletters()
{
global

List := ""
Alphabet = A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z  ; check all the possible drive letters
Loop, Parse, Alphabet, .
{

IfExist, %A_LoopField%:\
{
;msgbox, drive letter exists %A_LoopField%:\
List .= A_LoopField "|"
}
IfNotExist, %A_LoopField%:\
{
;msgbox, drive letter DOES NOT EXIST: %A_LoopField%:\
}
continue
}
}



♥ ❤ ❥ coder_chick ♥ ❤ ❥
ahk7
Posts: 209
Joined: 06 Nov 2013, 16:35

Re: Dynamic GUI numbers

22 Aug 2019, 13:11

You can replace checkavailabledriveletters() with https://www.autohotkey.com/docs/commands/DriveGet.htm :)

Just as a demo, there are probably more elegant ways to go about it - using a function here as it is easy to call, but you can just as easily make it a label and Gosub, NewGui if you prefer.

Code: Select all

NewGui()
Return

Esc::ExitApp

ClickMe:
MsgBox % A_Gui ; the Gui, New will automatically assign it a number as you can see here, you can use that number to get data from controls. 

Gui, %A_Gui%:Default ; this will ensure GuiControlGet below will work on the correct window
GuiControlGet, OutputVar, , Edit1
MsgBox %OutputVar%
; now create a new Gui :)
NewGui()
Return

NewGui()
	{
	 Gui, New
	 Gui, Add, Edit, HwndMyEditHwnd, 
	 Gui, Add, Button, gClickMe, ClickMe
	 Gui, Show
	}
User avatar
coder_chick
Posts: 185
Joined: 05 Nov 2015, 10:43

Re: Dynamic GUI numbers

22 Aug 2019, 14:00

I spent about 2 hrs trying to get this to work and couldn't. Can you just modify my code so I can see what the heck I need to do here? I'm lost. Thanks for helping a girl out!
♥ ❤ ❥ coder_chick ♥ ❤ ❥
ahk7
Posts: 209
Joined: 06 Nov 2013, 16:35

Re: Dynamic GUI numbers

22 Aug 2019, 17:11

Rewriting might be a little too much, but why not simply make it easy on yourself and simply launch another instance of the same script, that way everything keeps working, you only need to add one line: Run %A_ScriptFullPath% - so your ListFiles label would look like this (I also added a Return)

Code: Select all

ListFiles: ; start indenting your code, it helps to understand what is going on
Gui,2:Submit,nohide
FormatTime,TimeString,,yyyy-MM-dd hh:mm:ss tt
FileAppend,Filename|Extension|Size|Modified|Accessed|Created|FullPath`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
Gui,3: Add, Text, x12 y9 w690 h90 vVar,%Var%
Gui,3: Show, w720 h133,%AppName%
Loop, C:\*.* ,0,1 ;0 means only files are retrieved and 1 means subfolders are recursed.
	{
	GuiControl,3:,Var,%A_LoopFileFullPath%
	if A_LoopFileExt in pst,ost
		{
		FileAppend,%A_LoopFileName%|%A_LoopFileExt%|%A_LoopFileSize%|%A_LoopFileTimeModified%|%A_LoopFileTimeAccessed%|%A_LoopFileTimeAccessed%|%A_LoopFileFullPath%`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
		}
	}
FileAppend,[DIRECTORY LISTING FINISHED]`n,%OutputFolder%\%FileListing%(%PartitionLetter%_Partition).txt
Run %A_ScriptFullPath% ; will start a new instance of the script <<<<<<<<<<---------------
Return ; you forgot to close ListFiles: with a Return

Return to “Ask For Help”

Who is online

Users browsing this forum: avocado, Bing [Bot], dirtyacc, MannyKSoSo, Marcosa1020 and 204 guests