Solved

shortcut settings: start minimized

Posted on 1997-04-30
7
871 Views
Last Modified: 2010-05-18
I'm trying to create Delphi 2.0 application which responds properly when started
with icons with Run: "Minimized" specified. And I just can't do it.

Borland's TI 2778 says about it this:

A: Delphi's Application object creates a hidden "application
   window," and it is that window, rather than your main form,
   that is being sent the command to show minimized. To fix this,
   make your main form's OnCreate event handler look like this:

      procedure TForm1.FormCreate(Sender: TObject);
      {$IFDEF WIN32}           { Delphi 2.0 (32 bit) }
      var
        MyInfo: TStartUpInfo;
      {$ENDIF}
      begin
      {$IFDEF WIN32}           { Delphi 2.0 (32 bit) }
        GetStartUpInfo(MyInfo);
        ShowWindow(Handle, MyInfo.wShowWindow);
      {$ENDIF}
      {$IFDEF WINDOWS}         { Delphi 1.0 (16 bit) }
        ShowWindow(Handle, cmdShow);
      {$ENDIF}
      end;


If I do this, TApplication and main form get out of sync. Application (i.e. the
icon in the toolbar) think the application is running restored (it has minimize
menu item enabled while restore is disabled). Main form is even worse. It is
"minimize-like" in the lower left corner of desktop, just over the toolbar, as
if it was MDI child of the desktop. I tried to put Application.Minimize call in
FormCreate or FormShow, but it doesn't make matters better.

I have an ugly "fix": at the end of FormCreate to post the message (minimize me)
if minimize flag is on in the shortcut. On response to the message I then
minimize the application. Result is that app starts normal and immediately after
minimizes. Looks ugly.

Does anyone know how to do it properly, or Borland guys just forgot about that
feature ?

Thank you in advance
0
Comment
Question by:lkovac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:sperling
ID: 1335798
You can't do it "properly"... Don't know if Borland forgot it or just didn't bother...

Try a simple fix.... Set your FormStyle to wsMinimized, and then in OnCreate write something like this:

GetStartupInfo...
case MyInfo.wShowWindow of
  SW_SHOW,
  SW_SHOWNORMAL : Application.Restore;
  SW_MAXMIMIZE : PostMessage(Application.Handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
  SW_MINIMIZE : ; // Already minimized
end


You'll probably have to add some more of the warious SW_XXX constants in the case statement, but this would at least let you mimic proper startup behaviour.

Regards,

Erik.



0
 

Author Comment

by:lkovac
ID: 1335799
No, Eric, this doesn't work. I didn't try with Maximized, but that wsMinimized makes main form to create that ugly minimized window in lower left corner just over the taskbar (as if desktop was MDI parent for it) (at least on NT 4.0 it is doing that). My solution with posting user defined message is much better, I even improved it with Hiding (see following code), but there is still that ugly animation going first up then down... However, I still hope somebody has better solution (maybe even the hack to VCL source code) because with this problem how can one create commercial product with Delphi ?

Here is my code:

const
  WM_MINIMIZE = WM_USER + 1;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
    bMinimize: boolean;
    procedure Minimize(var msg: TMessage); message WM_MINIMIZE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  si: TStartupInfo;
begin
  si.cb := SizeOf(TStartupInfo);
  GetStartupInfo(si);
  if ((SW_MINIMIZE = si.wShowWindow) or (SW_SHOWMINIMIZED = si.wShowWindow) or (SW_SHOWMINNOACTIVE = si.wShowWindow)) then
  begin
    bMinimize := True;
    PostMessage(Handle, WM_MINIMIZE, 0, 0);
  end
  else
    bMinimize := False;
end;

procedure TForm1.Minimize(var msg: TMessage);
begin
  Application.Minimize;
  bMinimize := False;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  if bMinimize then
    Hide
  else
    if not Visible then
      Show;
end;




0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335800
This is how I did it successfully in Delphi 1.0. I haven't tried it in Delphi 2 yet, but I see no reason for it not to work

   procedure TForm1.FormCreate(Sender: TObject);
   begin
      ShowWindow(Handle, CmdShow);
      {the rest of your program}
   end;

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lkovac
ID: 1335801
No, that doesn't work in Delphi 2.0 . Delphi 2.0 is completely different in this problem.
0
 

Author Comment

by:lkovac
ID: 1335802
Adjusted points to 200
0
 
LVL 2

Accepted Solution

by:
gysbert1 earned 200 total points
ID: 1335803
It seems this is definately a bug in delphi2. I tested this and it does work in delphi1 !!

There is a hack that will solve your problem, although it is pretty crude ;^)

In oncreate set the position of your form according to the windowstate passed to the application as above. If it should be minimized call showwindow(handle,SW_ShowNoActivate); as well as setting the position to something ridiculous like left:=10000. In your onactivate you can now set the left property to what you want it. Even save it if you want to be thorough ...

The code in the borland TI's as well as the help files suggests your original code should work but on my system it also creates a minimized child some invisible MDI parent !?



0
 

Author Comment

by:lkovac
ID: 1335804
Great reply. Using your advice I was able to make it work. However, it
needed little bit more tweaking (regarding the animation when minimizing on
NT and making application aware of state (right click on icon on taskbar
should enable restore or minimize properly).

This is the solution for application which can be "normal" or minimized
(dialog main form). If it could be also maximized, solution would be much
more complicated. Here is the full solution:

unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

const
  WM_MINIMIZE = WM_USER + 1;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    bMinimize: boolean;
    l, t: integer;
    procedure Minimize(var msg: TMessage); message WM_MINIMIZE;
    procedure WMMove(var Message: TWMMove); message WM_MOVE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  si: TStartupInfo;
begin
  l := Left;
  t := Top;
  si.cb := SizeOf(TStartupInfo);
  GetStartupInfo(si);
  if ((SW_MINIMIZE = si.wShowWindow) or (SW_SHOWMINIMIZED = si.wShowWindow) or (SW_SHOWMINNOACTIVE = si.wShowWindow)) then
  begin
    bMinimize := True;
    MoveWindow(Handle, 3000, 3000, Width, Height, False);
    PostMessage(Handle, WM_MINIMIZE, 0, 0);
  end
  else
    bMinimize := False;
end;

procedure TForm1.Minimize(var msg: TMessage);
begin
  if bMinimize then
    ShowWindow(Application.Handle, SW_HIDE);
  Application.Minimize;
  if bMinimize then
  begin
    bMinimize := False;
    Left := l;
    Top := t;
    ShowWindow(Application.Handle, SW_SHOWNA);
  end;
end;

procedure TForm1.WMMove(var Message: TWMMove);
begin
  if not bMinimize then
    MoveWindow(Application.Handle, Left, Top, Width, 0, False);
end;

end.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question