Page 1 of 1
How to hide the console window
Posted: 15 Jun 2023 14:30
by Harrison Pratt
How can I run a console application without showing the console window?
Re: How to hide the console window
Posted: 16 Jun 2023 13:18
by Thomas Linder Puls
It seems you can do like this, but the console will however exist/flicker for a moment:
Code: Select all
implement main
open core
clauses
run() :-
R = freeConsole(),
if b_false = R then
E = exception::getLastError(),
exception::raise_nativeCallException("FreeConsole", E)
end if,
stdio::inputStream := inputStream_null::null,
stdio::outputStream := outputStream_null::null,
multiThread_native::sleep(2000),
nothing().
class predicates
freeConsole : () -> booleanInt Result language apicall.
end implement main
goal
mainExe::run(main::run).
The main things are don't use
console:: (notice the goal) and call
freeConsole.
You should also consider how to properly deal with exceptions (setting
mainExe::exceptionDumper to something sensible), a program like this will bring-up our "last-resort-exception" dialog and that it not completely user friendly.
(Windows Services also run without window, but are started and stopped and should figure out what to do in-between).
Re: How to hide the console window
Posted: 19 Jun 2023 11:50
by Harrison Pratt
The freeConsole works nicely although, as you said, it does flicker a console screen briefly, much like a console app.
What I was trying to do was to tidy up a tiny application that converts a clipboard string copied from medical journal titles to a valid Windows file name (i.e., remove ':' and similar characters) and put the cleaned string back on the clipboard. One day I got the notion that perhaps I could make the application (unncessarily) smaller by using a console app ... and went down a rabbit hole of exploration.
It looks like my original strategy works better for implementing a keyboard click-and-clean without screen flicker:
Create a GUI project and replace the
TaskWindow creation in
main.pro as shown in the code below.
Code: Select all
% DEFAULT CODE removed
clauses
run() :-
TaskWindow = taskWindow::new(),
TaskWindow:show().
Code: Select all
% NEW CODE
run() :-
if clipboard::putString(fileNameCleaner::cleanFName(clipboard::tryGetString())) then
_ = environment_native::beep(2100, 100)
else
_ = environment_native::beep(1600, 1000)
end if.
Also, I removed the
TaskWindow and
AboutDialog packages from the project. I probably could remove some of the unused PFC packages as well if I wanted to shrink the EXE size further.
Thomas, do you have any more thoughts on this?
Re: How to hide the console window
Posted: 19 Jun 2023 12:20
by Thomas Linder Puls
I think that is a fine solution. (Except for the beeping).
(Out of curiosity) What will run the application?
Re: How to hide the console window
Posted: 19 Jun 2023 13:16
by Harrison Pratt
I double-click the app's desktop icon to activate the link. I could also have created a keyboard shortcut, but chose not to do that.
It works like this:
- I open the article (web page or PDF), highlight & copy the title text
- click the icon (the beep lets me know it's converted the text),
- then I save the file with "print to PDF" using the cleaned text that's on the clipboard for the file name.
Re: How to hide the console window
Posted: 19 Jun 2023 13:48
by Thomas Linder Puls
OK, makes sense (as a personal tool).