The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cobold on May 31, 2009, 12:10:34 PM

Title: Started from CLI or by double click?
Post by: cobold on May 31, 2009, 12:10:34 PM
Greetings,

if you start a console-app by double clicking on it, the console window will vanish when the program exits. For some people that's embarrasing. So it would be nice if your program could find out if it was called from the command line interface or by double click and issue an inkey before exit.
f. ex:

.if <doubleclick>
    inkey
.endif
exit

Result: program issues inkey ONLY if started by double click. Interesting behaviour of GetCommandLine is following:
it returns "C:\<path>\progname" when the program was started by double-click, and
progname only when started from CLI, so
include \masm32\include\masm32rt.inc

.code
start:
    invoke GetCommandLine
    mov esi,eax
    print eax,13,10
    .if byte ptr[esi] == 34
        print "Started by double click",13,10
        inkey
    .else
        print "Started from cmd",9
    .endif
    exit
end start


would do the job.
Any better ideas?
Title: Re: Started from CLI or by double click?
Post by: dedndave on May 31, 2009, 12:25:04 PM
        INVOKE  GetStartupInfo
should have something in there
Title: Re: Started from CLI or by double click?
Post by: dedndave on May 31, 2009, 12:57:07 PM
you might also try GetConsoleMode - they may be different values at startup (maybe not)

another one is GetConsoleTitle
for CLI, it is "Command Prompt"
if started by explorer, it is the current folder under which the console was opened

one more to try -  GetConsoleWindow