我先了.
当需要在小窗口预览是,win95会传给你的程序一个参数,这个参数是一个数字,
表示那个小窗口的句柄,你自己定义一个窗口class,作为那个小窗口的子类就
可以了.
procedure ExecPreview;
var WndClass:TWndClass;
Atom:TAtom;
DC:hDC;
MyWnd:hWnd;
Msg:TMsg;
begin
//create a new window class
ParamHandle:=StrToInt(ParamStr(2));
//第2个参数是句柄
with WndClassdo
begin
style:=CS_PARENTDC;
lpfnWndProc:=@MyWndProc;
//你自己的处理窗口消息的函数
cbClsExtra:=0;
cbWndExtra:=0;
hIcon:=0;
hCursor:=0;
hbrBackground:=0;
lpszMenuName:=NIL;
lpszClassName:='ScreenSaverClass';
end;
WndClass.hInstance:=hInstance;
Atom:=Windows.RegisterClass(WndClass);
//get some info on parent window
GetWindowRect(ParamHandle, PrevRect);
pw:=(prevrect.right-prevrect.left);
ph:=(prevrect.bottom-prevrect.top);
Staticrect:=GetStretchRect(frmscreensaver.img0.width,frmscreensaver.img0.height);
PrevRect.Right:=PrevRect.Right-PrevRect.Left;
PrevRect.Bottom:=PrevRect.Bottom-PrevRect.Top;
PrevRect.Left:=0;
PrevRect.Top:=0;
//and now create the window as child of the window given in ParamHandle
MyWnd:=CreateWindow('ScreenSaverClass','Window of the world',WS_CHILD or
WS_DISABLED or WS_VISIBLE,0,0,PrevRect.Right,PrevRect.Bottom,
ParamHandle,0,hInstance,nil);
//get the DC for the new created window
DC:=GetDC(MyWnd);
//用来画屏保画面的canvas
PreviewCanvas:=TCanvas.Create;
PreviewCanvas.Handle:=DC;
//把canvas挂到小窗口上
PreviewCanvas.brush.Color:=clblack;
PreviewCanvas.fillrect(prevrect);
logomode:=true;
PreviewCanvas.StretchDraw(staticrect,frmscreensaver.img0.picture.graphic);
// previewcanvas.Refresh;
//开始消息循环
while GetMessage(Msg,0,0,0)do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
在你自己的消息处理函数MyWndProc中,你只要处理一下几个消息即可:
WM_DESTROY or WM_CLOSE //表示结束
WM_PAINT //表示窗口需要刷新
这是我的一个程序里面的片断,里面可能有些你永不上的变量,你领会意思
就可以了.