views:

162

answers:

1

I use the following code to capture when the minimise button of my program is pressed so that I can hide the form from the taskbar, and as such minimise to the system tray.

procedure TForm1.WMSysCommand;
begin
   if (Msg.CmdType = SC_MINIMIZE) then
   begin
    form1.Hide;
    show1.Checked :=false;
    hide1.Checked :=true;
    end;
   if (Msg.CmdType = SC_CLOSE) then form1.Close;
end;

I have had to put the capture in for the close button too as this code was preventing the program closing via the close button. What I need help with is how to fix dragging the program window by the caption bar which has stopped working with this code.

+5  A: 

If you override the processing of a Windows message you need to take care to either handle all possible cases, or to call the inherited code for all unhandled cases:

procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
   if (Msg.CmdType = SC_MINIMIZE) then
   begin
     Hide;
     show1.Checked := False;
     hide1.Checked := True;
     Msg.Result := 0;
     exit;
   end;
   inherited;
end;
mghie
And don't forget to set the message result. (For this message, it should be zero.)
Rob Kennedy