一个在Panel中运行屏幕保护程序的例子 参考一下function EnumProc(ChildHandle:HWND): Boolean;stdcall;
var
buf: array[0..255] of char;
begin
GetWindowText(ChildHandle, buf, sizeof(buf)- 1);
xuer.Edit1.Text:=IntToStr(ChildHandle);
Result := true;
end;procedure Txuer.FormCreate(Sender: TObject);
var
buf : array[0..256] of char;
begin
GetSystemDirectory(buf, sizeof(buf) - 1);
FileListBox1.directory := strpas(buf);
end;procedure Txuer.FileListBox1Click(Sender: TObject);
var
i:integer;
begin
if Edit1.Text<>'' then i:=StrToInt(Edit1.Text);
{关闭前一个屏幕保护程序}
PostMessage(i,WM_QUIT,0,0);
{预览当前屏幕保护程序}
WinExec(Pchar(FileListBox1.FileName + ' /p ' + IntToStr(Panel2.handle)), SW_Show);
EnumChildwindows(Panel2.handle,TFNWndEnumProc(@enumproc), 0);
end;
var
buf: array[0..255] of char;
begin
GetWindowText(ChildHandle, buf, sizeof(buf)- 1);
xuer.Edit1.Text:=IntToStr(ChildHandle);
Result := true;
end;procedure Txuer.FormCreate(Sender: TObject);
var
buf : array[0..256] of char;
begin
GetSystemDirectory(buf, sizeof(buf) - 1);
FileListBox1.directory := strpas(buf);
end;procedure Txuer.FileListBox1Click(Sender: TObject);
var
i:integer;
begin
if Edit1.Text<>'' then i:=StrToInt(Edit1.Text);
{关闭前一个屏幕保护程序}
PostMessage(i,WM_QUIT,0,0);
{预览当前屏幕保护程序}
WinExec(Pchar(FileListBox1.FileName + ' /p ' + IntToStr(Panel2.handle)), SW_Show);
EnumChildwindows(Panel2.handle,TFNWndEnumProc(@enumproc), 0);
end;
===============================================
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,ShellApi;type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
hwnd_child : hwnd;
begin
ShellExecuteA(0,'open','notepad.exe',nil,nil,SW_SHOWNORMAL);
Sleep(1000);
Hwnd_child := FindwindowA(nil,'未定标题 - 记事本');
windows.SetParent(hwnd_child,panel1.handle);
SetWindowPos(hwnd_child,0,0,0,panel1.Width,panel1.Height,SWP_SHOWWINDOW);
end;end.
我爽.....