I wanted to ask: is it possible to add additional flags for OpenConsole() in the future? Such as #PB_Console_Invisible and #PB_Console_Minimize (similar to OpenWindow()).
How can I do the same now, while these flags do not exist?
Now I will show you what I really need:
Code: Select all
Import "kernel32.lib"
GetConsoleWindow.i()
EndImport
If OpenConsole()
hwnd=GetConsoleWindow()
ShowWindow_(hwnd, #SW_HIDE) ;#SW_MINIMIZE
Sleep_(5000)
EndIf
Code: Select all
Import "kernel32.lib"
AttachConsole(processID.l)
EndImport
Why is this needed?
For the case when I do not want to show the console window, but simply perform some operations in it.
Code: Select all
ImportC "msvcrt.lib"
system(str.p-ascii)
EndImport
Now I did something like this:
Code: Select all
Structure RunProgramExtendedStructure
ProgramID.i
WindowHandle.i
EndStructure
Procedure EnumWindows(hwnd.i, lParam.i)
Protected Result.i = #True, PID.l, *RunProgramExtended.RunProgramExtendedStructure = lParam
Protected classText.s = Space(255)
If hwnd
If IsIconic_(hwnd) ;IsWindowVisible_(hwnd) = 0
GetClassName_(hwnd, @classText, 255)
If classText = "ConsoleWindowClass"
If GetWindowThreadProcessId_(hwnd, @PID)
If PID = *RunProgramExtended\ProgramID
*RunProgramExtended\WindowHandle = hwnd
Result = #False
EndIf
EndIf
EndIf
EndIf
Else
Result = #False
EndIf
ProcedureReturn Result
EndProcedure
Procedure RunProgramEx(file$, param$, dir$, showflag, lParam.i)
Protected Result.i = #False, *RunProgramExtended.RunProgramExtendedStructure = lParam
If Left(param$,1)<>" " : param$=" "+param$ : EndIf
Info.STARTUPINFO : Info\cb=SizeOf(STARTUPINFO) : Info\dwFlags=1
Info\wShowWindow=showflag : ProcessInfo.PROCESS_INFORMATION
If CreateProcess_(@file$,@param$,0,0,0,#NORMAL_PRIORITY_CLASS,0,@dir$,@Info,@ProcessInfo)
*RunProgramExtended\ProgramID = ProcessInfo\dwProcessId
Result.i = #True
EndIf
ProcedureReturn Result
EndProcedure
Define RunProgramExtended.RunProgramExtendedStructure
Define hwnd.i, *ExtendedStructure = @RunProgramExtended
Define app$ = GetEnvironmentVariable("comspec") ; Full path needed!
If RunProgramEx(app$, "", GetPathPart(app$), #SW_MINIMIZE, *ExtendedStructure) ;#SW_HIDE
Repeat
Sleep_(500)
EnumWindows_(@EnumWindows(), *ExtendedStructure)
hwnd = RunProgramExtended\WindowHandle
Until hwnd
Debug hwnd
Sleep_(3000)
ShowWindow_(hwnd, #SW_SHOW)
EndIf


