Recent

Author Topic: Cant hide window from taskbar when executing application created with Lazarus  (Read 2169 times)

MaartenJB

  • Jr. Member
  • **
  • Posts: 97
Hi,

I want to launch an application with TProcess made with Lazarus, but it won't let me hide the application. If I do the same with for example mspaint.exe it works fine:

Code: Pascal  [Select][+][-]
  1. uses ..., process;
  2.  
  3. var
  4.   aProcess: TProcess;
  5. begin
  6.  
  7.   aProcess := TProcess.Create(nil);
  8.   try
  9.  
  10.     if (CheckBox1.Checked)
  11.     then aProcess.CommandLine := 'mspaint.exe'           // <--- Works
  12.     else aProcess.CommandLine := 'C:\Temp\project1.exe';  // <--- Doesnt Work  ( Vanilla Lazarus application )
  13.  
  14.     aProcess.CurrentDirectory:= ExtractFilePath(aProcess.CommandLine);
  15.     aProcess.Options := aProcess.Options - [poWaitOnExit];
  16.     aProcess.ShowWindow:=swoHIDE;     // <---  This should hide the application
  17.     aProcess.Execute;
  18.   finally
  19.     aProcess.Free;
  20.   end;
  21. end;
  22.  

« Last Edit: August 17, 2021, 08:51:08 am by MaartenJB »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Since you seem to be in Windows, try with:
Code: Pascal  [Select][+][-]
  1.     {... etc ...}
  2.     Exclude(aProcess.Options, poWaitOnExit); {== aProcess.Options - [poWaitOnExit];}
  3.     Include(aProcess.Options, poNoConsole);
  4.     aProcess.ShowWindow:=swoHIDE;
  5.     {... etc ...}

Note, though, that some programs don't like to be run hidden, so they take steps to prevent it in their own initialization. There's nothing you can do about it.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 2799
Hi!

For Windows only there is the  property TPROCESS.ShowWindow:

Try the option swoHide.

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 4219
For Windows only there is the  property TPROCESS.ShowWindow:

Try the option swoHide.

That was already in the OP's oiginal code. It's in fact what got him baffled: that it works with mspaint.exe but not with (his?) testmon.exe

Just saying ... :-[
« Last Edit: August 16, 2021, 05:00:52 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 2799
Hi!

What ist testmon.exe?

If it is your own code:
Does it got wsMaximized or fsStayOnTop?



That was already in the OP's oiginal code.

Sorry. Lack of concentration.
Just looking in the airspace over Afghanistan.
Turkish Airforce just flew in it with an A400M (TUAF580 )

Winni


MaartenJB

  • Jr. Member
  • **
  • Posts: 97
Thanks for responding

@lucamar, I've tried it your suggestion, but it still appears in the taskbar.

@winni, testmon.exe is just a blanco/vanilla Lazarus application, i've changed the name to project1.exe to make it more clear.

 

TinyPortal © 2005-2018