OpenConsole() to return window handle if successful

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

OpenConsole() to return window handle if successful

Post by Mistrel »

The console handle can be obtained through this method already

Code: Select all

OpenConsole()

*hwndConsole = GetForegroundWindow_()

Print("Console Window Handle = " + Str(*hwndConsole))

Input()
But it would be much more convenient if the handle were returned upon creation.
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Re: OpenConsole() to return window handle if successful

Post by horst »

I support this suggestion.

The GetForegroundWindow_() method is not safe, because it assumes that the console window is in the foreground. I just managed to crash the PB IDE, just because it happened to be in the foreground (it was not involved in the testing of the compiled console program).

I use this method:

Code: Select all

ConTitle$ = Space(300)
If GetConsoleTitle_(@ConTitle$,300)
  ConsoleHandle = FindWindow_(0,@ConTitle$)
EndIf 
which will at least avoid catching a non-console window.

@PB team:
Is there any reason why OpenConsole() does not return the console handle?
Horst.
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

On win 2000,xp and vista can can you use GetConsoleWindow().

Code: Select all

Import ""
	GetConsoleWindow()
EndImport

OpenConsole()

hwndConsole = GetConsoleWindow()

Print("Console Window Handle = " + Str(hwndConsole))

Input()
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post by horst »

hallodri wrote:On win 2000,xp and vista can can you use GetConsoleWindow().

Code: Select all

Import ""
	GetConsoleWindow()
EndImport

OpenConsole()

hwndConsole = GetConsoleWindow()

Print("Console Window Handle = " + Str(hwndConsole))

Input()
Thanks, but what the heck is Import "" ? I could not find any documentation about importing nothing.
Horst.
Post Reply