?
Solved

Form does not hide in Delphi 7

Posted on 2003-03-26
3
Medium Priority
?
1,137 Views
Last Modified: 2010-04-04
Hi,

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);
begin
    Visible := FALSE;
    Application.ShowMainForm := Visible;
end;

procedure TForm1.CMClickIcon(var msg: TMessage);
begin
    Application.Restore;
    Visible := TRUE;
    Application.ShowMainForm := Visible;
    SetForegroundWindow(Application.Handle);
end;
0
Comment
Question by:Bohne
[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
3 Comments
 
LVL 1

Expert Comment

by:Knighty
ID: 8213340
you could try

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

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

Author Comment

by:Bohne
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?
0
 
LVL 1

Accepted Solution

by:
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);
begin
     ShowWindow(Application.Handle, SW_HIDE);
end;

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

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

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

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