Established AHK User taking the dive into programming... Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DrDave
Posts: 9
Joined: 13 Mar 2016, 11:34

Established AHK User taking the dive into programming...

18 Jul 2017, 20:00

Hi folks,

First of all - I love AHK and have used it primarily within the realm of hotkeys and hot strings.

I've toyed around with the idea of increasing the functionality of what I use it for (I'm a doc and I use it for writing patient encounter notes) to include some scripting to increase the flexibility of use. I do have some experience in programming primarily with Delphi ObjectPascal. What seems to be the difference with AHK scripting language is though I appreciate the documentation provided, there's not (at least to my knowledge) a lot of scripting examples, etc. It would be awesome if there was AHK For Dummies primer.

So, having first made the qualification, I'd like to ask for some help.

I thought I would like to try to start with a hotstring which provided fairly generic content - I'd like to customize it.

I thought I would use the hotstring trigger to bring up a dialog box which would present several choices, established by radio buttons. then obviously depending upon the choice, the hotstring would be set to a certain value.

I am using the AutoGui application (thanks to the creators for the effort) to create the GUI with an Ok and Cancel button - but I'm having trouble determining how to return either a value of the radio button when the user clicks Ok.

Here's a pic of the script thus far:
Screen Shot 2017-07-18 at 8.56.24 PM.png
Screen Shot 2017-07-18 at 8.56.24 PM.png (113.26 KiB) Viewed 1698 times
I'd appreciate some guidance or any suggestions

David
DrDave
Posts: 9
Joined: 13 Mar 2016, 11:34

Re: Established AHK User taking the dive into programming...

18 Jul 2017, 20:04

NB gReturn obviously doesn't work....
DrDave
Posts: 9
Joined: 13 Mar 2016, 11:34

Re: Established AHK User taking the dive into programming...

18 Jul 2017, 20:36

So, I used MagicBox to develop this code:

Instruction := "Select a PARQ option appropriate for your procedure"
Content := "Select 1 option only`; click ""Ok"" to proceed, ""Cancel"" to abort"
Title := "PARQ for Procedure?"
MainIcon := 99
Buttons := 0x9
RadioButtons := []
RadioButtons.Push([201, "M3"])
RadioButtons.Push([202, "DAS Mx"])
RadioButtons.Push([203, "DAS Md"])
RadioButtons.Push([204, "DAS FMX"])
RadioButtons.Push([205, "Implant(s) Mx"])
RadioButtons.Push([206, "Implant(s) Md"])
cRadioButtons := RadioButtons.Length()
VarSetCapacity(pRadioButtons, 4 * cRadioButtons + A_PtrSize * cRadioButtons, 0)
Loop %cRadioButtons% {
iButtonID := RadioButtons[A_Index][1]
iButtonText := &(r%A_Index% := RadioButtons[A_Index][2])
NumPut(iButtonID, pRadioButtons, (4 + A_PtrSize) * (A_Index - 1), "Int")
NumPut(iButtonText, pRadioButtons, (4 + A_PtrSize) * A_Index - A_PtrSize, "Ptr")
}
DefaultRadio := 201
Parent := DllCall("GetDesktopWindow", "Ptr")

; TASKDIALOGCONFIG structure
x64 := A_PtrSize == 8
NumPut(VarSetCapacity(TDC, x64 ? 160 : 96, 0), TDC, 0, "UInt") ; cbSize
NumPut(Parent, TDC, 4, "Ptr") ; hwndParent
NumPut(Buttons, TDC, x64 ? 24 : 16, "Int") ; dwCommonButtons
NumPut(&Title, TDC, x64 ? 28 : 20, "Ptr") ; pszWindowTitle
NumPut(MainIcon, TDC, x64 ? 36 : 24, "Ptr") ; pszMainIcon
NumPut(&Instruction, TDC, x64 ? 44 : 28, "Ptr") ; pszMainInstruction
NumPut(&Content, TDC, x64 ? 52 : 32, "Ptr") ; pszContent
NumPut(cRadioButtons, TDC, x64 ? 76 : 48, "UInt") ; cRadioButtons
NumPut(&pRadioButtons, TDC, x64 ? 80 : 52, "Ptr") ; pRadioButtons
NumPut(DefaultRadio, TDC, x64 ? 88 : 56, "Int") ; nDefaultRadioButton

DllCall("Comctl32.dll\TaskDialogIndirect", "Ptr", &TDC
, "Int*", Button := 0
, "Int*", Radio := 0
, "Int*", Checked := 0)

If (Radio == 201) {
; M3

} Else If (Radio == 202) {
; DAS Mx

} Else If (Radio == 203) {
; DAS Md

} Else If (Radio == 204) {
; DAS FMX

} Else If (Radio == 205) {
; Implant(s) Mx

} Else If (Radio == 206) {
; Implant(s) Md

}

If (Button == 1) {
; OK

} Else If (Button == 2) {
; Cancel

}
Guest

Re: Established AHK User taking the dive into programming...

18 Jul 2017, 21:49

Code: Select all

:*:\parq::
	for a,b in RB:=[["_201","M3"],["_202","DAS Mx","checked"],["_203","DAS Md"],["_204","DAS FMX"],["_205","Implant Mx"],["_206","Implant Md"]]
	gui,Add,Radio,% "v"b.1 " " b.3, % b.2
	gui,Add,button,g_OK Default,&OK
	gui,Add,button,g_cancel ,&Cancel 
	gui,Show,,PARQ for Procedure?
return

_OK:
	gui,Submit
	gui,Destroy
	for c,d in RB {
		e:=d.1
		if (%e%=1){
			SendInput,% d.2
		}
	}
return

_Cancel:
	gui,Destroy
return

GuiEscape:
GuiClose:
	ExitApp
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Established AHK User taking the dive into programming...  Topic is solved

19 Jul 2017, 00:56

Thx 4 mentioning [MagicBox]. Wasn't aware of it!
BTW, feel free to use the

Code: Select all

-tag option provided if you use the "Full Editor & Preview" while posting - to support your supporters. Good luck & happy scripting, Doc  :)
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: Established AHK User taking the dive into programming...

19 Jul 2017, 06:44

DrDave wrote:What seems to be the difference with AHK scripting language is though I appreciate the documentation provided, there's not (at least to my knowledge) a lot of scripting examples, etc. It would be awesome if there was AHK For Dummies primer...

I'd appreciate some guidance or any suggestions

David
David, I quite agree with your comments. I can't help with an AHK for Dummies primer but I find Jack Dunning's AHK blog and books to be chock full of examples and - more importantly - explanations of the "how's and why's" behind them, all in a way that (IMO) is easy to understand.

In my experience he's approachable and, when I've had questions, he's taken the time to work through them and explain the issue I'm having and the solution.

That's not to knock any of the many fine contributors to this forum, just recognition that being able to describe and explain a solution clearly in a way that is easy to understand is often as important (to me) as the solution itself. I just find his conversational style of writing to be easy to absorb and appreciate the way he often uses variations of code snippets to explain different methods of achieving the same or similar results.

I now subscribe to his free weekly newsletter and have several of his ebooks.

Jack's blog: https://jacksautohotkeyblog.wordpress.com/

Jack's free book explaining uses of AHK: https://jacksautohotkeyblog.wordpress.c ... more-34023

Jack's books: https://jacksautohotkeyblog.wordpress.c ... key-books/

I've no connection (other than being a subscriber and fan)... it's just that your post struck a chord.

Hope this helps...
DrDave
Posts: 9
Joined: 13 Mar 2016, 11:34

Re: Established AHK User taking the dive into programming...

19 Jul 2017, 11:19

[quote="BoBo"]Thx 4 mentioning [MagicBox]. Wasn't aware of it!
BTW, feel free to use the

Code: Select all

-tag option provided if you use the "Full Editor & Preview" while posting - to support your supporters. Good luck & happy scripting, Doc  :)[/quote]

You're very welcome - I think it's quite useful.

DrD

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest and 306 guests