Page 1 of 1
Console invisible or hide [WINDOWS ONLY]
Posted: Wed Jun 11, 2014 10:04 pm
by minimy
Hi friends! Many time searching how make invisible the console window. Well, here is a little trip.
Code: Select all
OpenConsole("MyConsole"):Delay(1000)
Opacity= 100:hwnd = FindWindow_(0,"MyConsole"); put 0 to invisible, 255 opaque
SetWindowLong_(hwnd, #GWL_EXSTYLE, $00080000):If OpenLibrary(1, "user32.dll"):CallFunction(1, "SetLayeredWindowAttributes", hwnd, 0, Opacity, 2):CloseLibrary(1):EndIf
Input()
I hope you enjoy!!
Re: Console invisible or hide [WINDOWS ONLY]
Posted: Wed Jun 11, 2014 10:24 pm
by netmaestro
Are you using the demo version? If not, that stuff is native. Also, there's a better way to get the console hwnd:
Code: Select all
Import ""
GetConsoleWindow_() As "_GetConsoleWindow@0"
EndImport
OpenConsole("MyConsole")
hwnd = GetConsoleWindow_()
Opacity= 100 ; put 0 To invisible, 255 opaque
SetWindowLong_(hwnd, #GWL_EXSTYLE, #WS_EX_LAYERED) : SetLayeredWindowAttributes_(hwnd, 0, Opacity, 2)
Input()
GetConsoleWindow is in kernel32.lib which is always open so a null import is all you need.
Re: Console invisible or hide [WINDOWS ONLY]
Posted: Thu Jun 12, 2014 3:38 pm
by minimy
netmaestro wrote:Are you using the demo version? If not, that stuff is native. Also, there's a better way to get the console hwnd:
Code: Select all
Import ""
GetConsoleWindow_() As "_GetConsoleWindow@0"
EndImport
OpenConsole("MyConsole")
hwnd = GetConsoleWindow_()
Opacity= 100 ; put 0 To invisible, 255 opaque
SetWindowLong_(hwnd, #GWL_EXSTYLE, #WS_EX_LAYERED) : SetLayeredWindowAttributes_(hwnd, 0, Opacity, 2)
Input()
GetConsoleWindow is in kernel32.lib which is always open so a null import is all you need.
Hi NetMaestro, Thanks for your time!
Not..

Im using 5.21LTS, Im registered user! Have 5.22 but not installed because have Pure_color and others..

And i have to say, im very happy with the price and product! (Thanks Fred & Cia.!)
Sorry NetMaestro, but is the same to get the hwnd of the window? I think, can you explain a little why is better the other way? (I dont know)
I try this other way with your code:
Code: Select all
Import "":GetConsoleWindow_() As "_GetConsoleWindow@0":EndImport
win=OpenWindow(#PB_Any,0,0,300,100,"Dummy Invisible",#PB_Window_Invisible)
OpenConsole("MyConsole") : hwnd = GetConsoleWindow_() : SetParent_(hwnd,WindowID(win))
Input()
CloseWindow(win):End
No task in taskbar with this code. This is the right way to do this?
Nunca te acostarĂ¡s sin saber algo nuevo. (Spanish proverb)

Re: Console invisible or hide [WINDOWS ONLY]
Posted: Tue Aug 22, 2023 6:30 am
by Little John
This looks pretty cool.

Thanks to both of you!
I've updated netmaestro's code, so that it runs with the most recent PureBasic x86 and x64 versions on Windows 11:
Code: Select all
; PB 6.03 beta 5
Import ""
CompilerIf #PB_Compiler_32Bit
GetConsoleWindow_() As "_GetConsoleWindow@0"
CompilerElseIf #PB_Compiler_64Bit
GetConsoleWindow_() As "GetConsoleWindow"
CompilerEndIf
EndImport
OpenConsole("MyConsole")
hwnd = GetConsoleWindow_()
Opacity = 160 ; 0: invisible, 255: opaque
SetWindowLongPtr_(hwnd, #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(hwnd, 0, Opacity, 2)
Input()
Re: Console invisible or hide [WINDOWS ONLY]
Posted: Sun Mar 03, 2024 8:41 am
by Michael Vogel
The
GetConsoleWindow function does only work when creating a 'Windows' executable, when using 'Console'
FindWindow must be used (as seen in the first post and below, keep in mind not to remove the delay command).
Creating a console executable seems to have other limitations as well, I am not able to remove the window titlebar (GWL_STYLE)...
Code: Select all
OpenConsole("MyConsole")
Delay(100)
Opacity=200
hwnd=FindWindow_(0,"MyConsole")
SetWindowLong_(hwnd, #GWL_EXSTYLE, $00080000)
If OpenLibrary(1, "user32.dll")
CallFunction(1, "SetLayeredWindowAttributes", hwnd, 0, Opacity, 2)
CloseLibrary(1)
EndIf
ShowWindow_(hwnd,#SW_MAXIMIZE)
SetWindowLongPtr_(hwnd,#GWL_STYLE,GetWindowLongPtr_(hwnd,#GWL_STYLE)&~#WS_THICKFRAME&~#WS_DLGFRAME)
PrintN("Done.")
Input()