-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
How to hide the console window
How can I run a console application without showing the console window?
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
Re: How to hide the console window
It seems you can do like this, but the console will however exist/flicker for a moment:
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).
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).
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).
Regards Thomas Linder Puls
PDC
PDC
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: How to hide the console window
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.
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?
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.
Thomas, do you have any more thoughts on this?
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
Re: How to hide the console window
I think that is a fine solution. (Except for the beeping).
(Out of curiosity) What will run the application?
(Out of curiosity) What will run the application?
Regards Thomas Linder Puls
PDC
PDC
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: How to hide the console window
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:
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.
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
Re: How to hide the console window
OK, makes sense (as a personal tool).
Regards Thomas Linder Puls
PDC
PDC