Sign in to follow this  
Followers 0

Embed cmd.exe without a border?

22 posts in this topic

Posted

I am trying to create a program that has cmd.exe embedded into it. However, I would like for the cmd.exe window to be borderless.

Here is my code so far.

#include <GUIConstants.au3>
#include <Constants.au3>


Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 

$mainWindow = GUICreate("Embed Cmd", 500, 500, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState (@SW_SHOW)
GUIRegisterMsg(0xF, "WM_PAINT")

$pid = run("cmd.exe /T:F0 /k")
ProcessWait ($pid)
; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class
$cmdHandle = _ProcessGetHWnd($pid, 2)
Local $hWndChild = $cmdHandle[1][1]
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $mainWindow)
DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWndChild, "int", -20, "long", 0x80000000 + 0x40000000 + 0x40000)
GuiSetStyle(BitOr($WS_POPUP, $WS_BORDER), '', $hWndChild)
WinSetState($hWndChild, '', @SW_SHOW)
WinMove($hWndChild, '', 1, 300, 498, 200)

; inifinite event loop
While 1

; sleep for 100 milliseconds (to not hog the cpu)
	sleep(100)
	
; end of event loop	
WEnd


Func CLOSEClicked()	
; take care of things to do when exiting
	exitCleanup()
	Exit
EndFunc


Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
	Sleep(100)
	DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc  ;==>WM_PAINT



;===============================================================================
;
; Function Name:	_ProcessGetHWnd
; Description:	  Returns the HWND(s) owned by the specified process (PID only !).
;
; Parameter(s):	 $iPid		- the owner-PID.
;					$iOption	- Optional : return/search methods :
;						0 - returns the HWND for the first non-titleless window.
;						1 - returns the HWND for the first found window (default).
;						2 - returns all HWNDs for all matches.
;
;				   $sTitle		- Optional : the title to match (see notes).
;					$iTimeout	- Optional : timeout in msec (see notes)
;
; Return Value(s):  On Success - returns the HWND (see below for method 2).
;						$array[0][0] - number of HWNDs
;						$array[x][0] - title
;						$array[x][1] - HWND
;
;				   On Failure	- returns 0 and sets @error to 1.
;
; Note(s):			When a title is specified it will then only return the HWND to the titles
;					matching that specific string. If no title is specified it will return as
;					described by the option used.
;
;					When using a timeout it's possible to use WinWaitDelay (Opt) to specify how
;					often it should wait before attempting another time to get the HWND.
;
;
; Author(s):		Helge
;
;===============================================================================
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
	Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
	
	While 1
		
	; Get list of windows
		$aWin = WinList($sTitle)
		
	; Searches thru all windows
		For $i = 1 To $aWin[0][0]
			
		; Found a window owned by the given PID
			If $iPid = WinGetProcess($aWin[$i][1]) Then
				
			; Option 0 or 1 used
				If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
					Return $aWin[$i][1]
				
			; Option 2 is used
				ElseIf $iOption = 2 Then
					ReDim $aReturn[UBound($aReturn) + 1][2]
					$aReturn[0][0] += 1
					$aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
					$aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
				EndIf
			EndIf
		Next
		
	; If option 2 is used and there was matches then the list is returned
		If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
		
	; If timed out then give up
		If TimerDiff($hTimer) > $iTimeout Then ExitLoop
		
	; Waits before new attempt
		Sleep(Opt("WinWaitDelay"))
	WEnd
	
	
; No matches
	SetError(1)
	Return 0
EndFunc  ;==>_ProcessGetHWnd

I have included Helge's ProcessGetHWnd inside the code rather than include it just to make it easier to copy and run

For the most part, I am happy with how it works, but I really want to get rid of that border.

Any ideas?

Cheers!

Share this post


Link to post
Share on other sites



Posted

I have created a solution to embedding a borderless command prompt in a window. First I make a child window with $WS_POPUP and embedd the commend prompt in that window. Then I size the command prompt window so that it is just bigger than the child window and the command prompt window's borders and title bar are clipped outside of the child window.

Not an elegant solution, but it works.

I can post the code if anyone is interested.

Cheers!

Share this post


Link to post
Share on other sites

Posted

Post AwaY!

Share this post


Link to post
Share on other sites

Posted

Here is the updated code with the simulated borderless command prompt.

#include <GUIConstants.au3>
#include <Constants.au3>


Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainWindow = GUICreate("Embed Cmd", 500, 500, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState (@SW_SHOW)
GUIRegisterMsg(0xF, "WM_PAINT")

; create a borderless window that is a child to the main window
$embedWindow = GUICREATE("", 477, 165, 15, 320, $WS_POPUP, -1, $mainWindow)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow)

; launch the command prompt (black on white, without the operating system message)
$pid = run("cmd.exe /T:F0 /k")
ProcessWait ($pid)
; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class
$cmdHandle = _ProcessGetHWnd($pid, 2)
$hWndChild = $cmdHandle[1][1]
; make the command prompt window a child to the earlier created borderless child window
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $embedWindow)
; resize the command prompt window so that its bolder and title bar are outside the borderless child window 
;  giving the appearance of a borderless command prompt
WinMove($hWndChild, '', -4, -30, 485, 206)
WinSetState($hWndChild, '', @SW_SHOW)
WinSetState($embedWindow, '', @SW_SHOW)

; inifinite event loop
While 1

; sleep for 100 milliseconds (to not hog the cpu)
    sleep(100)
    
; end of event loop    
WEnd


Func CLOSEClicked()    
; take care of things to do when exiting
	Winkill($hWndChild)
    Exit
EndFunc


Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    Sleep(100)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc  ;==>WM_PAINT



;===============================================================================
;
; Function Name:    _ProcessGetHWnd
; Description:      Returns the HWND(s) owned by the specified process (PID only !).
;
; Parameter(s):     $iPid        - the owner-PID.
;                    $iOption    - Optional : return/search methods :
;                        0 - returns the HWND for the first non-titleless window.
;                        1 - returns the HWND for the first found window (default).
;                        2 - returns all HWNDs for all matches.
;
;                   $sTitle        - Optional : the title to match (see notes).
;                    $iTimeout    - Optional : timeout in msec (see notes)
;
; Return Value(s):  On Success - returns the HWND (see below for method 2).
;                        $array[0][0] - number of HWNDs
;                        $array[x][0] - title
;                        $array[x][1] - HWND
;
;                   On Failure    - returns 0 and sets @error to 1.
;
; Note(s):            When a title is specified it will then only return the HWND to the titles
;                    matching that specific string. If no title is specified it will return as
;                    described by the option used.
;
;                    When using a timeout it's possible to use WinWaitDelay (Opt) to specify how
;                    often it should wait before attempting another time to get the HWND.
;
;
; Author(s):        Helge
;
;===============================================================================
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
    
    While 1
        
    ; Get list of windows
        $aWin = WinList($sTitle)
        
    ; Searches thru all windows
        For $i = 1 To $aWin[0][0]
            
        ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                
            ; Option 0 or 1 used
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]
                
            ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
                EndIf
            EndIf
        Next
        
    ; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
        
    ; If timed out then give up
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop
        
    ; Waits before new attempt
        Sleep(Opt("WinWaitDelay"))
    WEnd
    
    
; No matches
    SetError(1)
    Return 0
EndFunc  ;==>_ProcessGetHWnd

In the end, it does what I want, but it seems like a sloppy solution. I wish I could get it so that the command prompt window would not display until it was repositions, but if I hide it on creation, it fails to become a child of the other window. rats.

Cheers!

Share this post


Link to post
Share on other sites

Posted

It would be a much more pratical and elegant soluction to create 2 edit controls to represent the output and input of the cmd.exe,and hide the true window.

Like this(just a gui,not functional,made in Koda):

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 356, 303, 303, 219)
$Input1 = GUICtrlCreateInput("Input1", 10, 270, 251, 21)
$Button1 = GUICtrlCreateButton("Button1", 270, 268, 75, 25, 0)
$Edit1 = GUICtrlCreateEdit("", 10, 10, 335, 239)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

		Case $Form2
		Case $Form2
		Case $Form2
		Case $Form2
		Case $Input1
		Case $Button1
		Case $Edit1
	EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Posted

I thought about doing that but was unable to figure out a way to continuously get the output from the commandline into an edit box. How is that done?

Share this post


Link to post
Share on other sites

Posted

$CmdStr = GUICtrlRead($cmd)
$CmdStr = StringStripWS($CmdStr, 3)
If StringInStr($CmdStr, " ") Then
    $CmdStr = '"' & $CmdStr & '"'
EndIf
If StringLen($Params) Then
    $CmdStr &= " " & $Params
EndIf
Sleep(160)
RunWait(@ComSpec & " /c " & $CmdStr & " >> C:\cmd-output.txt", "", @SW_HIDE)
Sleep(800)
$txt = FileRead("C:\cmd-output.txt")
GUICtrlSetData($output,$txt)
line.

Share this post


Link to post
Share on other sites

Posted

I considered that also, but (unless I implemented it incorrectly) it will display the output of a command line program only after the program has finished executing.

I need to display the output realtime, as the program is running. This is one of the main reasons I chose to embed cmd.exe into the main window.

Cheers!

Share this post


Link to post
Share on other sites

Posted

I considered that also, but (unless I implemented it incorrectly) it will display the output of a command line program only after the program has finished executing.

I need to display the output realtime, as the program is running. This is one of the main reasons I chose to embed cmd.exe into the main window.

Cheers!

Well getting the output instantly is not a problem. You can do that. THe problem is with applications that ask you questions or start up command line up that you need to interact with. Like for example netsh. Getting instant output from commands like ipconfig etc is not a problem and quite simple to do. I haven't yet checked how it's done in newest beta but with 3.2.10.0 it's working fine.

Share this post


Link to post
Share on other sites

Posted (edited)

This gets rid of the flash of the initial command prompt (although it still flashes on the taskbar)

Also does away with the need for the _ProcessGetHWnd function.

#include <GUIConstants.au3>
#include <Constants.au3>


Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainWindow = GUICreate("Embed Cmd", 500, 500, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState (@SW_SHOW)
GUIRegisterMsg(0xF, "WM_PAINT")

; create a borderless window that is a child to the main window
$embedWindow = GUICREATE("", 477, 165, 15, 320, $WS_POPUP, -1, $mainWindow)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow)


; launch the command prompt with a unique distinguishable title (black on white, without the operating system message)
$cmdTitle = CHR(01) & CHR(02)
$pid = run('cmd.exe /c start "' & $cmdTitle &'" /MIN cmd.exe /T:F0 /k',@ScriptDir,@SW_HIDE)
WinWait($cmdTitle)

; get the handle of the cmd window to pass to SetParent; 
$hWndChild = WinGetHandle($cmdTitle)

; make the command prompt window a child to the earlier created borderless child window
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $embedWindow)
; resize the command prompt window so that its bolder and title bar are outside the borderless child window
;  giving the appearance of a borderless command prompt
WinMove($hWndChild, '', -4, -30, 485, 206)
;WinSetState($hWndChild, '', @SW_SHOW) ; no longer need this line
WinSetState($embedWindow, '', @SW_SHOW)
WinActivate($hWndChild) ; Added this line to make sure the embedded command prompt gets focus


; inifinite event loop
While 1

; sleep for 100 milliseconds (to not hog the cpu)
    sleep(100)
   
; end of event loop   
WEnd


Func CLOSEClicked()   
; take care of things to do when exiting
    Winkill($hWndChild)
    Exit
EndFunc


Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    Sleep(100)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc  ;==>WM_PAINT

Only thing I can't figure out is why the command prompt cursor appears to be a little fatter than usual... :)

Edit: spellin' korection

Edited by ResNullius

Share this post


Link to post
Share on other sites

Posted

ReFran,

That looks good. I am torn between this method andhe original embedding cmd.exe method.

  • Embedding seems to give a smoother looking scrolling of th output.
  • Embedding gives awkward horizontal scroolling during output. rats.

ResNullius,

A big improvement. Thanks.

On my system (XPSP2) the prompt is the same fatness as i usually see it. Perhaps it has something to do with me always setting the colours to black text on white background.

Cheers

Share this post


Link to post
Share on other sites

Posted

The script doesn-t show a borderless command prompt on my pc ... XP SP2 Professional

wierd or it's my pc ?

Share this post


Link to post
Share on other sites

Posted

Here is another version of embed Command Line prompt:

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $Init_Dir = "C:\"

$Main_GUI = GUICreate("Embed Command Line Prompt", 550, 300, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUIRegisterMsg(0xF, "WM_PAINT")

$iCmd_PID = Run(@ComSpec & " /k CD " & $Init_Dir, "", @SW_HIDE)
ProcessWait($iCmd_PID)

$Embed_hWnd = _GetHWndByPID($iCmd_PID)
WinMove($Embed_hWnd, "", -2, -23, 549, 342)
WinSetState($Embed_hWnd, "", @SW_SHOWMINIMIZED)
GUISetState(@SW_SHOW, $Main_GUI)

DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $Embed_hWnd, "hwnd", $Main_GUI)


While 1
	Sleep(100)
	If WinActive($Main_GUI) Then WinActivate($Embed_hWnd)
WEnd

Func Quit()
	ProcessClose($iCmd_PID)
    Exit
EndFunc

Func _GetHWndByPID($iPID)
	Local $aWinList = WinList()
	
	For $i = 1 To UBound($aWinList)-1
		If WinGetProcess($aWinList[$i][1]) = $iPID Then Return $aWinList[$i][1]
	Next
	
	Return 0
EndFunc

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc

:)

The script doesn-t show a borderless command prompt on my pc ... XP SP2 Professional

wierd or it's my pc ?

It's depend on the Theme that used in your system, we can calculate it with GetSystemMetrics.

Share this post


Link to post
Share on other sites

Posted

; create a borderless window that is a child to the main window
$embedWindow = GUICREATE("", 477, 165, 15, 320, $WS_POPUP, -1, $mainWindow)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow)

A child window cannot have the POPUP style so that won't work (the boderless bit)

Share this post


Link to post
Share on other sites

Posted

A child window cannot have the POPUP style so that won't work (the boderless bit)

[excuse]

I didn't really analyze the OP's code for those subtleties, I was just looking at suppresing the flash of the console on startup before it was made a child of the GUI.

[/excuse]

@MsCreatoR

I like yours! :)

Share this post


Link to post
Share on other sites

Posted

Using Edit Control Functions, you can near mimic DOS like edit controls.

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <AVIConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <Constants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>
#include <GDIPlusConstants.au3>
#include <HeaderConstants.au3>
#include <ImageListConstants.au3>
#include <IPAddressConstants.au3>
#include <ListBoxConstants.au3>
#include <ListViewConstants.au3>
#include <MemoryConstants.au3>
#include <MenuConstants.au3>
#include <ProgressConstants.au3>
#include <RebarConstants.au3>
;~ #include <ScrollBarConstants.au3>
#include <SecurityConstants.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <StructureConstants.au3>
#include <TabConstants.au3>
#include <ToolbarConstants.au3>
#include <TooltipConstants.au3>
#include <TreeviewConstants.au3>
#include <UpDownConstants.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 634, 453, 193, 115)
HotKeySet("{BACKSPACE}", "Testet")
HotKeySet("{ENTER}", "Testt")
HotKeySet("{DEL}", "Testt")
$Edit1 = GUICtrlCreateEdit("", 0, 0, 633, 449)
GUICtrlSetData(-1, @SystemDir & ">")
GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)
Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)

#EndRegion ### END Koda GUI section ###

While 1
	Sleep(10)
	_GUICTrlEdit_SetSel($Edit1, _GUICtrlEdit_GetTextLen($Edit1)+1, _GUICtrlEdit_GetTextLen($Edit1)+1)
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd

Func Testt ()
	Local $sCmd = StringMid(GUICtrlRead($Edit1), $sLastLine+1)
	_GUICtrlEdit_BeginUpdate($Edit1)
	recall_command($sCmd)
	_GUICtrlEdit_EndUpdate($Edit1)
	_GUICtrlEdit_AppendText($Edit1, @SystemDir & ">")
	Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)
	MsgBox(1, "", $sLastLine)
EndFunc
	

Func recall_command($info)
    $cmdinfo = Run(@ComSpec & " /c " & $info,  @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD)
    While 1
        $line = StdoutRead($cmdinfo)
        If @error Then Return
		If $line = "" Then ContinueLoop
        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & $line);
    WEnd
EndFunc   ;==>recall_command

Func Testet ()
	Local $sSel = _GUICtrlEdit_GetSel($Edit1)
	If $sSel[0] <= $sLastLine Then Return
	If $sSel[1] - $sSel[0] = 0 Then
		GUICtrlSetData($Edit1, StringTrimRight(GUICtrlRead($Edit1), 1))
	Else
		_GUICtrlEdit_ReplaceSel($Edit1, "")
	EndIf
EndFunc

bit bugged, and very rough.

Share this post


Link to post
Share on other sites

Posted

A child window cannot have the POPUP style so that won't work (the boderless bit)

hey guys i need some help with the embedding of the cmd.exe

this things i want but i cant get it working

i want the popup style so that i only see the cmd bar and not a above titbar of autoit

if i move the cmd windows with my mouse (so in my autoit aplication) i wannt move my entire windows not only the cmd.exe

can somebody help me on this one pleas :D

Share this post


Link to post
Share on other sites

Posted

hey guys i need some help with the embedding of the cmd.exe

this things i want but i cant get it working

i want the popup style so that i only see the cmd bar and not a above titbar of autoit

if i move the cmd windows with my mouse (so in my autoit aplication) i wannt move my entire windows not only the cmd.exe

can somebody help me on this one pleas :D

Can you show what you have so far?

Share this post


Link to post
Share on other sites

Posted (edited)

4 years later and i cant compile this script, is this for an older autoit version ? what should i change ?

or i am just stupid ? ;)

i realy need this as a base to learn.

Here is the updated code with the simulated borderless command prompt.

#include 
#include 


Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

$mainWindow = GUICreate("Embed Cmd", 500, 500, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState (@SW_SHOW)
GUIRegisterMsg(0xF, "WM_PAINT")

; create a borderless window that is a child to the main window
$embedWindow = GUICREATE("", 477, 165, 15, 320, $WS_POPUP, -1, $mainWindow)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow)

; launch the command prompt (black on white, without the operating system message)
$pid = run("cmd.exe /T:F0 /k")
ProcessWait ($pid)
; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class
$cmdHandle = _ProcessGetHWnd($pid, 2)
$hWndChild = $cmdHandle[1][1]
; make the command prompt window a child to the earlier created borderless child window
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $embedWindow)
; resize the command prompt window so that its bolder and title bar are outside the borderless child window
;  giving the appearance of a borderless command prompt
WinMove($hWndChild, '', -4, -30, 485, 206)
WinSetState($hWndChild, '', @SW_SHOW)
WinSetState($embedWindow, '', @SW_SHOW)

; inifinite event loop
While 1

; sleep for 100 milliseconds (to not hog the cpu)
	sleep(100)
	
; end of event loop	
WEnd


Func CLOSEClicked()	
; take care of things to do when exiting
	Winkill($hWndChild)
	Exit
EndFunc


Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
	Sleep(100)
	DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc  ;==>WM_PAINT



;===============================================================================
;
; Function Name:	_ProcessGetHWnd
; Description:	  Returns the HWND(s) owned by the specified process (PID only !).
;
; Parameter(s):	 $iPid		- the owner-PID.
;					$iOption	- Optional : return/search methods :
;						0 - returns the HWND for the first non-titleless window.
;						1 - returns the HWND for the first found window (default).
;						2 - returns all HWNDs for all matches.
;
;				   $sTitle		- Optional : the title to match (see notes).
;					$iTimeout	- Optional : timeout in msec (see notes)
;
; Return Value(s):  On Success - returns the HWND (see below for method 2).
;						$array[0][0] - number of HWNDs
;						$array[x][0] - title
;						$array[x][1] - HWND
;
;				   On Failure	- returns 0 and sets @error to 1.
;
; Note(s):			When a title is specified it will then only return the HWND to the titles
;					matching that specific string. If no title is specified it will return as
;					described by the option used.
;
;					When using a timeout it's possible to use WinWaitDelay (Opt) to specify how
;					often it should wait before attempting another time to get the HWND.
;
;
; Author(s):		Helge
;
;===============================================================================
Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
	Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
	
	While 1
		
	; Get list of windows
		$aWin = WinList($sTitle)
		
	; Searches thru all windows
		For $i = 1 To $aWin[0][0]
			
		; Found a window owned by the given PID
			If $iPid = WinGetProcess($aWin[$i][1]) Then
				
			; Option 0 or 1 used
				If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
					Return $aWin[$i][1]
				
			; Option 2 is used
				ElseIf $iOption = 2 Then
					ReDim $aReturn[UBound($aReturn) + 1][2]
					$aReturn[0][0] += 1
					$aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
					$aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
				EndIf
			EndIf
		Next
		
	; If option 2 is used and there was matches then the list is returned
		If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
		
	; If timed out then give up
		If TimerDiff($hTimer) > $iTimeout Then ExitLoop
		
	; Waits before new attempt
		Sleep(Opt("WinWaitDelay"))
	WEnd
	
	
; No matches
	SetError(1)
	Return 0
EndFunc  ;==>_ProcessGetHWnd

In the end, it does what I want, but it seems like a sloppy solution. I wish I could get it so that the command prompt window would not display until it was repositions, but if I hide it on creation, it fails to become a child of the other window. rats.

Cheers!

Edited by armoros

Share this post


Link to post
Share on other sites

Posted

There have been numerous changes to AutoIt in the last 4 years. Make sure you have the full version of Scite4AutoIt3 which you can find here. Then, run Au3Check on the script, CTRL-F5 in Scite, and look for the error messages. Fix the errors, then try and run it. It may be that the code is too old to run, which is why resurrecting such old threads is generally frowned upon around here. Good luck.

Share this post


Link to post
Share on other sites

Posted

There have been numerous changes to AutoIt in the last 4 years. Make sure you have the full version of Scite4AutoIt3 which you can find here. Then, run Au3Check on the script, CTRL-F5 in Scite, and look for the error messages. Fix the errors, then try and run it. It may be that the code is too old to run, which is why resurrecting such old threads is generally frowned upon around here. Good luck.

Thank you mr BrewManNH i will try to clear things..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.