Recent

Author Topic: hiding main window's taskbar button on windows  (Read 8380 times)

wht244

  • Jr. Member
  • **
  • Posts: 79
hiding main window's taskbar button on windows
« on: November 26, 2010, 07:36:04 pm »
Code: [Select]
  es := GetWindowLong(Application.Handle, GWL_EXSTYLE);
  SetWindowLong(Application.Handle, GWL_EXSTYLE, es or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
this code allows to hide taskbar button for window, which handle is set as the first parameter in these two functions. by that code i can hide taskbar button of whole application. but only in delphi.
then, how to hide taskbar button of an application in lazarus?

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: hiding main window's taskbar button on windows
« Reply #1 on: November 26, 2010, 09:13:58 pm »
oddly, i think that stopped working recently; anyway, if your application title is different than form captions, this will do the job:
Code: [Select]
  h := FindWindow('Window', PChar(Application.Title));
  ShowWindow(h, 0);

if it's the same as main form caption, we need a bit more (this should work in either case):
Code: [Select]
  h := FindWindow('Window', PChar(Application.Title));
  p := GetParent(h);
  if h = Self.Handle then repeat
    h := FindWindowEx(p, h, 'Window', PChar(Application.Title));
  until (h = 0)  or  (h <> Self.Handle);
  ShowWindow(h, 0);

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: hiding main window's taskbar button on windows
« Reply #2 on: December 16, 2016, 04:08:43 am »
No need to... just don't create that button...  :P

Code: Pascal  [Select][+][-]
  1. PROGRAM Project1;
  2.  {$MODE OBJFPC}{$H+}
  3.  
  4.  USES
  5.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  6.   cthreads,
  7.   {$ENDIF}{$ENDIF}
  8.   Interfaces,
  9.   Forms,
  10.   Unit1;
  11.  
  12.   {$R *.RES}
  13.  
  14. BEGIN
  15.  RequireDerivedFormResource:= True;
  16.   Application.Initialize;
  17.    Form1:= TForm1.Create(Application);
  18.    Form1.Show;
  19.   Application.Run;
  20. END.      
  21.  


Code: Pascal  [Select][+][-]
  1. Unit Unit1;
  2.  {$MODE OBJFPC}{$H+}
  3.  
  4. Interface
  5.  USES
  6.   Classes, Forms, Controls;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Procedure FormCreate (Sender: TObject);
  12.    Procedure FormClose  (Sender: TObject; Var CloseAction: TCloseAction);
  13.   End;
  14.  
  15.  VAR
  16.   Form1: TForm1;
  17.  
  18. Implementation
  19.  {$R *.LFM}
  20.  
  21.  
  22. Procedure TForm1.FormCreate(Sender: TObject);
  23.  Begin
  24.   SetBounds(500, 200, 500, 300);
  25.   Caption:= 'No TaskbarButton...';
  26.  End;
  27.  
  28.  
  29. Procedure TForm1.FormClose(Sender: TObject; Var CloseAction: TCloseAction);
  30.  Begin
  31.   Application.Terminate;
  32.  End;
  33.  
  34. End.            
  35.  
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: hiding main window's taskbar button on windows
« Reply #3 on: December 16, 2016, 03:28:50 pm »
No need to... just don't create that button...  :P
Or even shorter :P
Code: Pascal  [Select][+][-]
  1. ...
  2. begin
  3.   RequireDerivedFormResource := True;
  4.   Application.Initialize;
  5. //  Application.CreateForm(TForm1, Form1);
  6.   Form1 := TForm1.Create(Application);
  7.   Form1.ShowModal;
  8. //  Application.Run;
  9. end.
  10.  

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: hiding main window's taskbar button on windows
« Reply #4 on: December 16, 2016, 11:19:34 pm »
Really nice...  :)
Yes, if you only need one window... funny, I never tried that one... good to know !!!
Thanks a lot ...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: hiding main window's taskbar button on windows
« Reply #5 on: December 19, 2016, 06:54:58 am »
And even more logical

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, unit1, unit2, unit3
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17.   Application.Initialize;
  18.   Application.ShowMainForm:=False;
  19.   Application.CreateForm(TForm1, Form1);
  20.   Application.CreateForm(TForm2, Form2);
  21.   Form2.Show;
  22.   Application.CreateForm(TForm3, Form3);
  23.   Application.Run;
  24. end.    
  25.  
  26.  

and in form2 side

Code: Pascal  [Select][+][-]
  1. procedure TForm2.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.  application.Terminate;
  4. end;  
  5.  

And this method is not limited to single windows. Entire application can be created.

remember: Forget Form1 leave as it is.

I have not tested but it may be applicable to all the platforms.
keep Coding...  ;)
« Last Edit: December 19, 2016, 06:56:49 am by Deepaak »
Holiday season is online now. :-)

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: hiding main window's taskbar button on windows
« Reply #6 on: December 19, 2016, 11:57:09 am »
Good solutions from good people ;D
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: hiding main window's taskbar button on windows
« Reply #7 on: December 19, 2016, 12:06:48 pm »
What's wrong with:

Code: Pascal  [Select][+][-]
  1. RequireDerivedFormResource := True;
  2. Application.Initialize;
  3. Application.MainFormOnTaskBar:= False;
  4. Application.CreateForm(TForm1, Form1);
  5. Application.Run;

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: hiding main window's taskbar button on windows
« Reply #8 on: December 19, 2016, 12:33:38 pm »
Hey Fungus
What's wrong with:

Code: Pascal  [Select][+][-]
  1. RequireDerivedFormResource := True;
  2. Application.Initialize;
  3. Application.MainFormOnTaskBar:= False;
  4. Application.CreateForm(TForm1, Form1);
  5. Application.Run;
In Lazarus 1.6.2 this code does not work in Win7 operating system. Yet ;
Code: Pascal  [Select][+][-]
  1. ...
  2. begin
  3.   RequireDerivedFormResource := True;
  4.   Application.Initialize;
  5. //  Application.CreateForm(TForm1, Form1);
  6.   Form1 := TForm1.Create(Application);
  7.   Form1.ShowModal;
  8. //  Application.Run;
  9. end.
  10.  
It works fine.
« Last Edit: December 19, 2016, 12:38:17 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018