AutoHotkey Community

It is currently May 26th, 2012, 9:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: July 1st, 2009, 9:01 pm 
Offline

Joined: May 13th, 2009, 11:30 pm
Posts: 11
Hi,

I've written some AHK apps in the past, but nothing too fancy.

For my next project I'd like to create a GUI for a Perl script that I use called get_iplayer. The Perl script runs from a console window usually and calls a couple of Win32 binaries, again from the command line.

Since the command line is where the action is, I'd like to put the console window in my GUI. Like this mockup:

Image

Can anyone give me some pointers? I've seen a few scripts and libraries that will write the output of a console to a variable, but I'm not sure I need to get that advanced. I just want to send commands to the console window based on button presses in the GUI.

Hope that makes sense. All advice appreciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 9:12 pm 
Can probably be done,
try this: http://www.autohotkey.com/forum/post-277100.html#277100


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 9:27 pm 
Offline

Joined: May 13th, 2009, 11:30 pm
Posts: 11
I didn't know you could do that! Thanks for the tip.

That's a little bit more Windows trickery than I was planning, although it shows a possible solution. I'll try and find a way of launching a console and automatically fixing it within the GUI.

Is there anything any less, erm..., hacky? I was hoping there was some kind of GUI element that I could simply position in the GUI.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 9:31 pm 
Offline

Joined: May 13th, 2009, 11:30 pm
Posts: 11
Hrm... Looks like I might be able to something with the CMDRet DLL.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 1st, 2009, 10:57 pm 
Offline

Joined: May 13th, 2009, 11:30 pm
Posts: 11
Z_Gecko, I think I'm going to to dig deeper in your code since the CMDRet DLL doesn't handle the output from my Perl program too well.

I'll admit that your code is quite advanced for me. Could you give me some pointers for some background reading? I'm looking to invoke a console when the AHK script starts and then fix it in place in the GUI.

Thanks for your help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 1:21 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I played around a bit, and came up with this:
Code:
; Styles we want to remove from the console window:
WS_POPUP := 0x80000000
WS_CAPTION := 0xC00000
WS_THICKFRAME := 0x40000
WS_EX_CLIENTEDGE := 0x200

; Styles we want to add to the console window:
WS_CHILD := 0x40000000

; Styles we want to add to the Gui:
WS_CLIPCHILDREN := 0x2000000

; Flags for SetWindowPos:
SWP_NOACTIVATE := 0x10
SWP_SHOWWINDOW := 0x40
SWP_NOSENDCHANGING := 0x400

; Create Gui and get window ID.
Gui, +LastFound +%WS_CLIPCHILDREN%
GuiWindow := WinExist()

; Launch hidden cmd.exe and store process ID in pid.
Run, %ComSpec%,, Hide, pid

; Wait for console window to be created, store its ID.
DetectHiddenWindows, On
WinWait, ahk_pid %pid%
ConsoleWindow := WinExist()

; Get size of console window, excluding caption and borders:
VarSetCapacity(ConsoleRect, 16)
DllCall("GetClientRect", "uint", ConsoleWindow, "uint", &ConsoleRect)
ConsoleWidth := NumGet(ConsoleRect, 8)
ConsoleHeight:= NumGet(ConsoleRect, 12)

; Apply necessary style changes.
WinSet, Style, % -(WS_POPUP|WS_CAPTION|WS_THICKFRAME)
WinSet, Style, +%WS_CHILD%
WinSet, ExStyle, -%WS_EX_CLIENTEDGE%

; Put the console into the Gui.
DllCall("SetParent", "uint", ConsoleWindow, "uint", GuiWindow)

; Move and resize console window. Note that if SWP_NOSENDCHANGING
; is omitted, it incorrectly readjusts the size of its client area.
DllCall("SetWindowPos", "uint", ConsoleWindow, "uint", 0
    , "int", 10, "int", 10, "int", ConsoleWidth, "int", ConsoleHeight
    , "uint", SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_NOSENDCHANGING)

; Add a button below the console.
Gui, Add, Button, % "y" ConsoleHeight+20, OK

; Show the Gui. Specify width since auto-sizing won't account for the console.
Gui, Show, % "W" ConsoleWidth+20

; Be sure to close cmd.exe later.
OnExit, Exiting

; If cmd.exe exits prematurely, fall through to ExitApp below.
Process, WaitClose, %pid%

GuiEsape:
GuiClose:
ButtonOK:
Exiting:
OnExit
Process, Close, %pid% ; May be a bit forceful? No effect if it already closed.
ExitApp
Tested only on Windows 7 RC.
Image

Background reading -- AutoHotkey: DllCall, Run, VarSetCapacity; MSDN: SetParent, CreateWindow (see dwStyle), GetClientRect, SetWindowPos.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 3:39 pm 
Nice, even though it crashes after resizing the console.

Is it possible to remove the titlebar of the console and the "resizeability", to prevent direct resizing or closing?

I tried by adding this, but this doesn't work:
Code:
; Apply necessary style changes.
WinSet, Style, % -(WS_POPUP|WS_CAPTION|WS_THICKFRAME)
WinSet, Style, +%WS_CHILD%
WinSet, ExStyle, -%WS_EX_CLIENTEDGE%

WinSet, Style, -0xC00000, ahk_pid %pid% ; no titlebar
WinSet, Style, -0x40000, ahk_pid %pid% ; no resize
WinSet, Redraw, , ahk_pid %pid%
;WinHide, ahk_pid %pid%
;WinShow, ahk_pid %pid%

; Put the console into the Gui.
DllCall("SetParent", "uint", ConsoleWindow, "uint", GuiWindow)


:roll:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2009, 8:04 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
n-l-i-d wrote:
Nice, even though it crashes after resizing the console.

Is it possible to remove the titlebar of the console and the "resizeability", to prevent direct resizing or closing?
Ah, now I recall on some versions of Windows you cannot do that. I tested on Windows 7 RC, and removing the WS_CAPTION, etc. style removes the title bar and borders, so it cannot be resized by the user.

Edit: I also experimented with inserting the console (via SetParent) into a control rather than directly into the Gui in order to "clip" it, but it seemed to prevent the console from receiving input. It also caused rendering issues like what you'd get without the WS_CLIPCHILDREN style, but adding that style to the control (rather than the Gui) didn't seem to help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 6th, 2009, 7:44 pm 
Offline

Joined: May 13th, 2009, 11:30 pm
Posts: 11
You guys are superstars. Tons of things for me to try out. Many thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Making it larger.
PostPosted: January 3rd, 2010, 1:21 am 
Lexikos wrote:
I played around a bit, and came up with this:


Hey this is awesome! I was thinking about doing this to make a custom console app that has multiple command consoles on different tabs and hides/shows on the touch of the tilde key like in-game consoles.

The thing is... is there any way to make the console a different size? I'd like it to maximize up the width (including making the actual console capable of filling up text columns all the way out), and potentially be able to change the size of the height / rows.

I tried by changing the values of the ConsoleWidth and Console Height in the numget method, but it just gave me strange results.

Thanks,
Umpitygrumpity


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], Google [Bot], Google Feedfetcher, krajan, Yahoo [Bot] and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group