首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi 開發 Win98 螢幕保護程式預覽器:多程式同時預覽管理工具

     編輯:Delphi

螢幕保護程式預覽介面原理

Win98 顯示屬性「螢幕保護程式」頁籤提供預覽功能:傳遞命令列參數 screensaver.exe /p<HWND>,其中 <HWND> 為預覽視窗控制代碼(10 進位)。支援預覽的螢幕保護程式會將自身視窗建立為該預覽視窗的子視窗,實現嵌入式預覽。此機制打破「同時間只能運行一個螢幕保護程式」限制,使多程式同時預覽成為可能。

介面佈局與元件配置

視窗採「倒品字」三區佈局:

  • 上左:TFileListBox(Mask=*.scr、Directory=GetSystemDirectory)列出系統螢幕保護程式
  • 上右:TListBox 顯示目前預覽中的程式(含視窗標題與控制代碼)
  • 下方:TPanel(Align=alClient)作為預覽容器視窗

核心功能實作

啟動預覽(FileListBox 雙擊):

procedure TForm1.FileListBox1DblClick(Sender: TObject);
begin
  WinExec(PChar(FileListBox1.FileName + ' /p' + IntToStr(Panel2.Handle)), SW_SHOW);
  FreshList; // 更新預覽清單
end;

列舉子視窗更新預覽清單:

function EnumProc(h: HWND; l: Integer): Boolean; stdcall;
var Buf: array[0..255] of Char;
begin
  GetWindowText(h, Buf, SizeOf(Buf)-1);
  if IsWindowVisible(h) then
    Form1.ListBox1.Items.Add('+' + StrPas(Buf) + ':' + IntToStr(h))
  else
    Form1.ListBox1.Items.Add('-' + StrPas(Buf) + ':' + IntToStr(h));
  Result := True;
end;

procedure TForm1.FreshList;
begin
  ListBox1.Clear;
  EnumChildWindows(Panel2.Handle, @EnumProc, 0);
end;

右鍵選單控制預覽程式(顯示/隱藏/關閉):

procedure TForm1.HideClick(Sender: TObject);
var h: Integer; s: String;
begin
  if ListBox1.ItemIndex = -1 then Exit;
  s := ListBox1.Items[ListBox1.ItemIndex];
  h := StrToInt(Copy(s, Pos(':', s)+1, Length(s)));
  ShowWindow(h, SW_HIDE); FreshList;
end;

procedure TForm1.ShowClick(Sender: TObject);
var h: Integer; s: String;
begin
  if ListBox1.ItemIndex = -1 then Exit;
  s := ListBox1.Items[ListBox1.ItemIndex];
  h := StrToInt(Copy(s, Pos(':', s)+1, Length(s)));
  ShowWindow(h, SW_SHOW); FreshList;
end;

procedure TForm1.CloseClick(Sender: TObject);
var h: Integer; s: String;
begin
  if ListBox1.ItemIndex = -1 then Exit;
  s := ListBox1.Items[ListBox1.ItemIndex];
  h := StrToInt(Copy(s, Pos(':', s)+1, Length(s)));
  PostMessage(h, WM_QUIT, 0, 0); FreshList;
end;

完整單元程式碼與編譯說明

完整程式包含 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl, ExtCtrls, Menus 單元。D6/D7 編譯通過。此工具對螢幕保護程式開發者極具參考價值,也可作為系統管理輔助工具。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved