I'm trying to use @joedf 's LibCon library (https://github.com/joedf/LibCon.ahk) for debugging my script, and I decided I wanted to keep it for the final product as well so that users can keep track of stuff.
I'm trying to parent the console window that is generated to a GUI so I can add buttons, text, etc.
Currently, this is what it looks like. This is the code so far, when I try to use SetChild, be it the ID or the Title version, the console window never appears to be rendered inside the GUI. I'm using AutoHotkey v1.1.34.03
Code: Select all
#NoEnv
#SingleInstance, Force
#Persistent
#InstallKeybdHook
#UseHook
#KeyHistory, 0
#HotKeyInterval 1
#MaxHotkeysPerInterval 2500
#Include LibCon.ahk ; include the LibCon-library : https://github.com/joedf/LibCon.ahk
OnExit, CleanUp
Global ConsoleID
Global ConsoleH
Global MainWT := "MainWindow"
Gui, 1: Show , x5 y600 w300 h100, %MainWT%
Gui, +LastFound
Gui 1: +hwndGui1
SmartStartConsole()
GetConsoleTitle(ConsoleID)
SetConsoleSize( 121, 10, 0 )
SetConsoleTitle( "Console" )
ID := DllCall("GetParent", UInt,WinExist("A")), ID := !ID ? WinExist("A") : ID
;MoveWindow(ahk_id %id%, 0, 740) ;Used only if the windows are seperate
;SetChildID(ID, 1) ;To attempt to parent Console to MainWindow
puts(TimeStamp() . " - Hello World!") ; write some test to the console
sleep, 5000
puts(TimeStamp() . " - Some more text")
sleep, 5000
return
; Library
SetChildID(Window_ID, Gui_Number)
{
Gui, %Gui_Number%: +LastFound
Return DllCall("SetParent", "uint", Window_ID, "uint", WinExist()) ; success = handle to previous parent, failure =null
}
SetChildTitle(Window_Title_Text, Gui_Number)
{
WinGetTitle, Window_Title_Text_Complete, %Window_Title_Text%
Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "uint",0, "str", Window_Title_Text_Complete)
Gui, %Gui_Number%: +LastFound
Return DllCall( "SetParent", "uint", Parent_Handle, "uint", WinExist() ) ; success = handle to previous parent, failure =null
}
Set_Parent_by_class(Window_Class, Gui_Number)
{
Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "str", Window_Class, "uint",0)
Gui, %Gui_Number%: +LastFound
Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle ) ; success = handle to previous parent, failure =null
}
MoveWindow(WinTitle, xPos, yPos)
{
WinGetPos,,, Width, Height, %WinTitle%
WinMove, %WinTitle%,, xPos, yPos
}
TimeStamp()
{
FormatTime, HelixTime, A_Now, M/d/yyyy hh:mm:ss
return HelixTime
}
CleanUp:
FreeConsole() ;Kill Console and keep ahk running till exit
sleep 100
ExitApp
GuiClose:
FreeConsole()
ExitApp