Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1248
  • Last Modified:

Form does not hide in Delphi 7

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
Bohne
Asked:
Bohne
1 Solution
 
KnightyCommented:
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
 
BohneAuthor Commented:
... 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
 
grolschisgoodCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now