Mini-guide: Custom Robin dialogs via AHK

There will likely be a way to create custom dialogs from within Robin in the future, but for now I’m using AutoHotkey to work around this.

RobinCode screenshot:

Code listing:

System.RunDOSCommand \
    DOSCommandOrApplication: "autohotkey.exe C:\work\RobinTests\d13.ahk | more" \
    WorkingDirectory:'C:\work\RobinTests' \
    StandardOutput=> StandardOutput \
    StandardError=> StandardError \
    ExitCode=> ExitCode
    
Display.ShowMessage \
    Title:'Returned from AHK     ' \
    Message: StandardOutput \
    Icon:Display.Icon.None \
    Buttons:Display.Buttons.OK \
    DefaultButton:Display.DefaultButton.Button1 \
    IsTopMost:False ButtonPressed=> ButtonPressed

Listing for AutoHotkey script (d13.ahk):

IconFile := "C:\Icons\Robin.ico"

Gui, New, +HwndDialogWindow
Gui, Color, cf0000
Gui, Font, cffffff
Gui, Add, Text, w60, Output1
Gui, Font
Gui, Add, Edit, x+5 yp w200 vOutput1
Gui, Font, cffffff
Gui, Add, Text, x10 y+15 w60, Output2
Gui, Font
Gui, Add, Edit, x+5 yp w200 vOutput2
Gui, Font, cffffff
Gui, Add, Text, x10 y+15 w60, Output3
Gui, Font
Gui, Add, Edit, x+5 yp w200 vOutput3
Gui, Add, Button, x10 y+15, Submit
gui, Show, ,Robin Dialogs
ChangeWindowIcon(IconFile, DialogWindow)

return

ButtonSubmit:
Gui, Submit
global msg
msg =
(
%Output1%
%Output2%
%Output3%
)
gosub, Bailing

ChangeWindowIcon(IconFile, hWnd) {
   ;hWnd  := WinExist(WinSpec)
    if (!hWnd){
        Msgbox "Window Not Found"
        return 
    }
    hIcon := DllCall("LoadImage", uint, 0, str, IconFile, uint, 1, int, 0, int, 0, uint, LR_LOADFROMFILE:=0x10)
    if (!hIcon)
	      Throw "Icon file missing or invalid in `nChangeWindowIcon(" IconFile ", " WinSpec ")`n`n"
    SendMessage, WM_SETICON:=0x80, ICON_SMALL2:=0, hIcon,, ahk_id %hWnd%  ; Set the window's small icon
    SendMessage, WM_SETICON:=0x80, ICON_BIG:=1   , hIcon,, ahk_id %hWnd% ; Set the window's big icon to the same one.
    Return
} 

;OnExit("ExitFunc")
Bailing:

OnExit("ExitFunc")
; Register an object to be called on exit:
OnExit(ObjBindMethod(MyObject, "Exiting"))

ExitFunc(ExitReason, ExitCode)
{
    if ExitReason not in Logoff,Shutdown
    {
        MsgBox, , Attention!, Output values will now be returned to the calling Robin script., 2
            return 0  ; OnExit functions must return non-zero to prevent exit.
    }
    ; Do not call ExitApp -- that would prevent other OnExit functions from being called.
}

class MyObject
{
    Exiting()
    {
		FileAppend, %msg%, *
    }
}

ExitApp

I won’t venture into an AutoHotkey tutorial here, but basically the script does the following:

  • Creates a GUI with custom icon, with three Edit boxes for input, and a Submit button.
  • A routine is called by the Submit button to pass the content of the Edit boxes to the Robin script.

(Outputs can easily be customized to return any type of string information - JSON, dictionaries, - and so on- although you will need to do some post-processing in Robin to use your returned strings.)
In the dialog shown below, the icon was extracted from a Robin executable using Resource Hacker.

RobinDialogs

Regards,
burque505

5 Likes