Form does not hide in Delphi 7

Posted on 2003-03-26
Medium Priority
Last Modified: 2010-04-04

I have an application that minimizes to the system tray. That's why I have a procedure AppMinimize which hides the application-form. The tray-icon is already present, so I don't have to initialize it.

When I click the icon, CMClickIcon is executed, which makes the window visible again!

And where is the problem now? All this works very well with Delphi 3. But with Delphi 7 I encounter a very strange problem: The application starts minimized, I click the icon, the application restores. I minimze the window, it disapears and only the icon is visible. I click the icon again, the application restores.

But now: I minimize the application, it minimizes but remains visible in the taskbar!!!
So the minimize works exactly one time! The second time it stays visible in the taskbar!!! Why this?!? Why does it only work the first time?!? And why does it work in Delphi 3 but not in Delphi 7?!?

Thank you very much for your help!

Here is the code i use:

procedure TForm1.AppMinimize(Sender:TObject);
    Visible := FALSE;
    Application.ShowMainForm := Visible;

procedure TForm1.CMClickIcon(var msg: TMessage);
    Visible := TRUE;
    Application.ShowMainForm := Visible;
Question by:Bohne
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

Expert Comment

ID: 8213340
you could try

to show form:
  SendMessage(Self.Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
  ShowWindow(Self.Handle, SW_SHOW);

to hide:
  ShowWindow(Self.Handle, SW_HIDE);

Author Comment

ID: 8228343
... I'm sorry, but this doesn't work at all! The form doesn't even hide once! It just minimizes. And afterwards it does not recover correctly! :-(

Any other ideas?

Accepted Solution

grolschisgood earned 100 total points
ID: 8229696
to have my application minimise to the system tray i do the following

on form create
1. i create the icon in the system tray
2. ShowWindow(Application.Handle, SW_HIDE); //hide the task bar icon

i then have a Application Events component on my form to capture minimise clicks.....
procedure TMain.ApplicationEvents1Minimize(Sender: TObject);
     ShowWindow(Application.Handle, SW_HIDE);

the popup menu on my icon in the system tray performs the following when you click the open button...
procedure TMain.Open1Click(Sender: TObject);
     ShowWindow(Application.Handle, SW_RESTORE);
     ShowWindow(Application.Handle, SW_HIDE);

ive also overrode the windows preocedure to pop up my menu on right clicks
procedure TMain.WndProc(var Msg : TMessage);
var p : TPoint;
  case Msg.Msg of
    WM_USER + 1:
    case Msg.lParam of
      WM_RBUTTONDOWN: begin
         PopupMenu1.Popup(p.x, p.y);
         PostMessage(Handle, WM_NULL, 0, 0);

you can play around with this to depending on how you want you app displayed at inital start up.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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