Run console application minimized

Run console application minimized

Hi!

Can anyone enlighten a poor, stupid soul how to make a Fortan executable (console application) run as a minimized icon in the taskbar?

Thanks,

Olof

18 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Well, the simplest way to do it is from "outside". Simply, in the "Program" tab of "Properties" dialog for the shortcut to the app, set "Run Minimized".

If the application is started by another application, you could run it minimized using WinExec (in another application's code):

 
USE DFWIN 
... 
iSt=WinExec("MyConsole.exe"C,SW_SHOWMINIMIZED) 
... 

Finally, if it is a must to minimize it from within the application itself,
you could try something like this:

 
SUBROUTINE MinimizeMyApp() 
 
USE DFWIN 
INTEGER hModule, hWindow 
CHARACTER*256:: sExeName 
 
hModule=GetModuleHandle(NULL) 
iSt=GetModuleFileName(hModule, sExeName, 256) 
hWindow=FindWindow(NULL, sExeName) 
iSt=ShowWindow(hWindow, SW_SHOWMINIMIZED) 
iSt=ShowWindow(hWindow, SW_SHOWMINIMIZED) 
 
END SUBROUTINE 

(This works on Win2k, where title of Console window displays the
full path of the .exe file. If this is different on Win9x/NT4, you could
extract filename from full path:

sExeName=sExeName(SCAN(sExeName,'',.TRUE) : )

HTH

Jugoslav

Jugoslav
www.xeffort.com

Test....
Ughhh. Why me, why, why, why, why, why,

Testing ...
Is the problem because I'm putting a link?

Testing ...

Is the problem because I'm putting an external link?

- ??

Ok. Putting an HTML link to the URL below in my message posting is enough to make it not show up. Why, why, why, why, .... It worked before. I promised myself I wouldn't comment any further on the message board, but it's getting kinda hard to refrain.

[Later]

After another failed posting, it seems you don't have to use anchor tags any more to post an HTML link. Is this the issue causing the problems. Does the forum have a Users Guide? Ughh.

[Later still]
No, it's not just the anchor tags because this message still won't post. #$@#$#@

[Much later]
I removed the #)(*$*# damn deja URL even as just text because this message won't post with it.

-jt

Hi, Jugoslav!

Thanks for the reply. The executable will be run from a Visual Basic application. Any comments other than the all the good ones you've already posted :)?

Olof

The gist of what I've been trying to post is that if your ultimate goal is to launch the console app with no window at all, this can be done easily using CreateProcess.

Steve L posted a CVF example recently on c.l.f. (feel free to search c.l.f. on deja for CreateProcess if you're interested).

If you want to call CreateProcess from VB, there are a number of MS KB articles you'd find useful. (Q129796 Q129797). To hide the console window, you'd want to do the equivalent of

StartupInfo.dwFlags = STARTF_USESHOWWINDOW
StartupInfo.wShowWindow = SW_HIDE

hth,
John

PS - Sorry for the lack of links. It's certainly not for a lack of trying. :-/

John,

I forgot to thank you for the assistance in few previous posts
(the messages from the old Forum). You're trully a saint - not
only for the helpfulness, but for the martyrdom you pass coping
with the Compaq Message Forum beast. Well, finally, what one
shouldn't do when posting a message here?
(It's potentially stupid question - since if you write what shouldn't
be done it would not occur here :-))

Olof,

Just one warning: be careful when executing an exe from within
another app. It depends on what you want exe to do, but my experience
is that exes doing the calculations are dangerous in the following
sense:

You know, Windows is multi-tasking OS. That means, if you want to
execute an .exe, it would be run in a separate process, i.e. in parallel
with the calling process. So, the calling app will not wait for the exe to
finish and then pick up the results; it would simply go further its way.
If that's the situation (call an exe and then display the results written
in some files), you'd better convert the exe into a DLL and then call
the DLL from VB. Also, you can apply the trick with pausing the VB
caller for the time sufficient that the exe finishes, or, clearer, apply
something like the following (you'll have to translate it into VB):

 
SUBROUTINE ExecAppAndWait(szCmdLine) 
 
USE DWIN 
 
IMPLICIT LOGICAL(b) 
IMPLICIT INTEGER(h-n) 
 
TYPE(T_STARTUPINFO)::         StdInfo 
TYPE(T_PROCESS_INFORMATION):: ProcInfo 
 
CHARACTER*(*)::         szCmdLine 
 
StdInfo%cb=64 
StdInfo%lpReserved=NULL  
StdInfo%lpDesktop=0  
StdInfo%lpTitle=NULL  
StdInfo%dwX=0  
StdInfo%dwY=0  
StdInfo%dwXSize=0  
StdInfo%dwYSize=0  
StdInfo%dwXCountChars=0  
StdInfo%dwYCountChars=0  
StdInfo%dwFillAttribute=0  
StdInfo%dwFlags=STARTF_USESHOWWINDOW 
StdInfo%wShowWindow=SW_HIDE 
StdInfo%cbReserved2=0  
StdInfo%lpReserved2=NULL  
StdInfo%hStdInput=0  
StdInfo%hStdOutput=0  
StdInfo%hStdError=0  
 
bProcess=CreateProcess(NULL_CHARACTER,szCmdLine,NULL_SECURITY_ATTRIBUTES,     & 
                       NULL_SECURITY_ATTRIBUTES,.FALSE.,                      & 
                       NORMAL_PRIORITY_CLASS,NULL,TRIM(sBazaDir)//CHAR(0),    & 
                       StdInfo,ProcInfo) 
hProcess=ProcInfo.hProcess 
 
iExitCode=STILL_ACTIVE 
DO WHILE(iExitCode.EQ.STILL_ACTIVE) 
      bDummy=GetExitCodeProcess(hProcess,LOC(iExitCode)) 
END DO 
 
END SUBROUTINE ExecAppAndWait 

Regards,

Jugoslav

Jugoslav
www.xeffort.com

Here is an elegant way to call an EXE from VB and wait for the end of execution.

Regards,
Sabalan.

If your ultimate goal is to start a console app programmatically without displaying the console window, you can do this easily using CreateProcess. Steve L. posted an example on c.l.f. not too long ago. You can see it on deja.com at, http://x69.deja.com/getdoc.xp?AN=688011871.

hth,
John

  
use dfwin
implicit none
type (T_STARTUPINFO) :: StartupInfo
type (T_PROCESS_INFORMATION) :: ProcessInfo
integer ret

StartupInfo = T_STARTUPINFO( &
SIZEOF(StartupInfo),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

! Specify that newly created window is to start hidden
StartupInfo%dwFlags = STARTF_USESHOWWINDOW
StartupInfo%wShowWindow = SW_HIDE

ret = CreateProcess (NULL_CHARACTER, & ! Application Name
"SUBDIRFEM.EXE"C, & ! Command line
NULL_SECURITY_ATTRIBUTES, &
NULL_SECURITY_ATTRIBUTES, &
FALSE, & ! InheritHandles
CREATE_NEW_CONSOLE, & ! CreationFlags
NULL, & ! Environment variables
"SUBDIR"C, & ! Current directory
StartupInfo, &
ProcessInfo)
end
 

Send Visual Fortran support requests to vf-support@compaq.com

Steve Lionel (mailto:Steve.Lionel@compaq.com)
Fortran Engineering
Compaq Computer Corporation, Nashua NH

I'll try this once more.

I was trying to say, if your ultimate goal is to launch the console app with no window at all, this can be done easily using CreateProcess. Steve L posted a CVF example recently on c.l.f.

But if you want to call CreateProcess from VB instead, that example would be of minor help.

If you're interested in this option, there are a number of MS KB articles you'd find useful. (Q129796 Q129797). To hide the console window, you'd want to do the equivalent of

StartupInfo.dwFlags = STARTF_USESHOWWINDOW
StartupInfo.wShowWindow = SW_HIDE

hth,
John

I discovered what the problem was with John's posting - it contained strings of digits which were interpreted as possible phone numbers, and for reasons unknown to me, the software is set up to cause messages with possible phone numbers to be held for review by a moderator.. but nothing ever told me such messages were there.

I THINK I have figured out a way to turn off the phone number filter for the Fortran forum - we shall see. Meanwhile I'll check the moderation queue every once in a while.

Learn something new every day...

Steve

Retired 12/31/2016

Hi Steve,

Thanks. I don't suppose there's any way for a user to cancel/delete their own posting, is there? (I believe it was possible in the old forum) If not, feel free to prune my posts in this thread down to one.

-John

Steve,

I seem to have done something extraordinary to my postings to the invisible controls thread, that became visible after moderation. Any idea what's causing this?

Walter Kramer

John - I'll ask about deleting your own postings - you can ask me to do it if you need something deleted (or edited).

Walter, I discovered that many postings were being held for moderator approval - when I approved them, they appeared.

Steve

Retired 12/31/2016

I discovered that you need to add the following lines to the end of my example code for running a program minimized:

ret = CloseHandle( ProcessInfo.hThread )

ret = CloseHandle( ProcessInfo.hProcess )

otherwise there might be a resource leak or the created process might not go away when done.

Steve

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today