Code: |
{ In the main program I used a variable named Monitors of type "array of TstringList" whose dimension is given by the number of buttons (different monitors available) to keep in memory all the hanldes associated with every button. Another variable named CurrentMonitor keeps in memory the index of the actual monitor (the caption of the button). This is the code: }
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ProcessView, StdCtrls, Buttons, abfComponents, Menus, ImgList, AppEvnts, TrayIcon;
type TForm1 = class(TForm) //these are the buttons (1..5) to switch from a monitor to another /// SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton5: TSpeedButton; ///////////////////////////////////////////////////////////////////////
ImageList1: TImageList; //ImageList connected to the Popup menu PopupMenu1: TPopupMenu; //popup menu displayed by the trayicon
//PopupMenu Items/////// ShowApplication: TMenuItem; //Show the form HideApplication: TMenuItem; //Hide the form N1: TMenuItem; // - CloseApplication: TMenuItem; //Close the application ////////////////////////////////
TrayIcon1: TTrayIcon; //my TrayIcon component; you can use yours procedure SpeedButton1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure ShowApplicationClick(Sender: TObject); //click on ShowApplication (TMenuItem) procedure HideApplicationClick(Sender: TObject); //click on HideApplication (TMenuItem) procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure CloseApplicationClick(Sender: TObject); //click on CloseApplication (TMenuItem) private { Private declarations } Monitors: array[1..5] of TStringList; CurrentMonitor: Integer; public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.SpeedButton1Click(Sender: TObject); var i: integer; Rect: TRect; begin // GetProcessList;
Monitors[CurrentMonitor].Assign(HandleList);
for i := 0 to HandleList.Count - 1 do begin ShowWindow(StrToInt(HandleList.Strings[i]), SW_HIDE); end;
CurrentMonitor := StrToInt((Sender as TSpeedButton).Caption); for i := 0 to Monitors[CurrentMonitor].Count - 1 do begin ShowWindow(StrToInt(Monitors[CurrentMonitor].Strings[i]), SW_SHOW); end; end;
procedure TForm1.FormCreate(Sender: TObject); var i: integer; begin // ShowWindow(Application.Handle, SW_HIDE); SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) and not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW); ShowWindow(Application.Handle, SW_SHOW);
CurrentMonitor := 1; for i := Low(Monitors) to High(Monitors) do Monitors[i] := TStringList.Create; end;
procedure TForm1.FormDestroy(Sender: TObject); var i: integer; begin // for i := Low(Monitors) to High(Monitors) do Monitors[i].Free; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var i, j: integer; begin for i := Low(Monitors) to High(Monitors) do begin for j := 0 to Monitors[i].Count - 1 do begin ShowWindow(StrToInt(Monitors[i].Strings[j]), SW_SHOW); end; end; end;
procedure TForm1.FormShow(Sender: TObject); begin // Height := 61; Width := 173; Top := Screen.Height - Height - 30; Left := Screen.Width - Width; end;
procedure TForm1.ShowApplicationClick(Sender: TObject); begin // Application.MainForm.Show; end;
procedure TForm1.HideApplicationClick(Sender: TObject); begin // Application.MainForm.Hide; end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin // if MessageDlg('Do you want to close Monitors?', mtConfirmation, [mbOK, mbCancel], 0) = mrCancel then CanClose := False; end;
procedure TForm1.CloseApplicationClick(Sender: TObject); begin Close; end;
end. |
Просьба писать ваши замечания, наблюдения и все остальное,
что поможет улучшить предоставляемую информацию на этом сайте.
ВСЕ КОММЕНТАРИИ МОДЕРИРУЮТСЯ ВРУЧНУЮ, ТАК ЧТО СПАМИТЬ БЕСПОЛЕЗНО!