Recent

Author Topic: Start Minimized show on bottom left corner (SOLVED)  (Read 1700 times)

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
Start Minimized show on bottom left corner (SOLVED)
« on: November 23, 2019, 10:35:01 am »
Hi,

I am using:
 - Windows 7 64 bit
 - Lazarus 2.0.6 64 bit
 - FPC 3.0.4 64 bit

I try to start my application minimized. When I do, the form still shows in a minimized format on the bottom left(Remind me good old windows 3.11). So fare, I tried the commands Application.Minimize;, ShowWindow(Handle, SW_MINIMIZE);  and FMain.WindowState:=wsMinimized;. I even try to close the application and add this line in the onclose event:  CloseAction:= caMinimize;

Seem like I can't find a way... the application still shows on the bottom left corner. I also tried to hide the application for testing purpose but it also disappears from the windows taskbar.   

This is my code:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TFMain.FormShow(Sender: TObject);
  3. begin
  4.   if VOptions.StartMinimized then
  5.     begin
  6.       Application.Minimize;
  7.       //Close;
  8.       //ShowWindow(Handle, SW_MINIMIZE);
  9.       //WindowState:=wsMinimized;
  10.       //FMain.WindowState:=wsMinimized;
  11.     end;
  12. end;
  13.  
  14. procedure TFMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  15. begin
  16.   if VOptions.CloseMinimized then
  17.     begin
  18.       if VOptions.SysTray then
  19.         CloseAction := caHide
  20.       else
  21.         begin
  22.           CloseAction:= caMinimize;
  23.           Application.Minimize;
  24.         end
  25.     end;
  26. end;
  27.  

I attached a picture of the window I try to hide. How can I call what "biMinimize", from the top right Form, do?

Thank you
 

« Last Edit: November 23, 2019, 03:33:27 pm by TheLastCayen »

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Start Minimized show on bottom left corner
« Reply #1 on: November 23, 2019, 10:57:51 am »
What you mean is to start your application hidden not minimized. Frankly almost never a good idea, although possible.
- How would you re-show it ? That takes extra key handling code, it is neigh impossible with the mouse.
- If it does not need a user interface, make it a console application or a service or daemon.
« Last Edit: November 23, 2019, 11:03:02 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
Re: Start Minimized show on bottom left corner
« Reply #2 on: November 23, 2019, 11:10:23 am »
Thank you Thaddy,

Actually not a bad idea since I also have an option for the systray.  But I kind of want to offer the option to start minimized without systray and still show in the taskbar. Since biMinimize can minimize to taskbar without showing the windows, there should be away. And honestly, Application.Minimize, that still shows a Form kind of feel like a bug. Base on the research I did before I post, it seems like that since a long time:(

My application drives other applications and save the setting... So, after it setup, the user doesn't need to interact with it as often. Mapped keys do the trick...  This is why I try to make that option available.

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Start Minimized show on bottom left corner
« Reply #3 on: November 23, 2019, 12:40:28 pm »
Well, just add a trayicon (with an actual icon loaded) then the TTrayIcon.Onclick will hide or show the application like so
Code: Pascal  [Select][+][-]
  1. procedure TForm1.TrayIcon1Click(Sender: TObject);
  2. begin
  3.   Application.MainForm.visible := not Application.Mainform.Visible;
  4. end;
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
Re: Start Minimized show on bottom left corner
« Reply #4 on: November 23, 2019, 02:00:17 pm »
Thank you,

It's shorter than what I was using;)

Code: Pascal  [Select][+][-]
  1. procedure TFMain.TrayIcon1DblClick(Sender: TObject);
  2. begin
  3.   if FMain.Visible then
  4.     FMain.Hide
  5.   else
  6.     begin
  7.       FMain.WindowState := wsNormal;
  8.       FMain.Show;
  9.     end;
  10. end;
  11.  

But I still want a way to do it when systray is disabled. There is a logic behind what I try to do. Even if you don't agree with that logic, avoiding will not help for this scenario:( If you search for the same question, you will notice many have also asked it and finally gave up:(

I was working on another part of my code and didn't had a chance to try the same code for Linux, so it may be OS-specific. Does anyone know a way to call what "biMinimize" call?

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Start Minimized show on bottom left corner
« Reply #5 on: November 23, 2019, 02:22:15 pm »
Your code does something completely different from my code:
My code ensures that the application is really hidden from the taskbar when clicked and only shows when it is necessary.
IOW it does exactly what you asked: trayicon clicked for hide: application does not show on the taskbar. trayicon clicked for show: application also shows on the taskbar.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

TheLastCayen

  • Jr. Member
  • **
  • Posts: 81
Re: Start Minimized show on bottom left corner
« Reply #6 on: November 23, 2019, 03:33:10 pm »
Thank you for the precision. This code will be useful.

I took a few minutes to try my code under linux mint Xfce and instead of minimizing in a small window, this code is just not working:

Code: Pascal  [Select][+][-]
  1. procedure TFMain.FormShow(Sender: TObject);
  2. begin
  3.     Application.Minimize;
  4. end;
  5.  

So I created a temporary button and added Application.Minimize. it works well under Linux. So instead I moved the code in the OnActivate method and it also works fine there. So I came back on my windows computer and this code Fix my Original issue:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TFMain.FormActivate(Sender: TObject);
  3. begin
  4.  if VOptions.StartMinimized then
  5.    Application.Minimize;
  6. end;  
  7.  
  8.  

So now my application start minimized or in the systray, depend of the options selected:)

 

TinyPortal © 2005-2018