W
wang_cai1
Unregistered / Unconfirmed
GUEST, unregistred user!
参考代码:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ExtCtrls, Menus, gdipapi, gdipobj; //最后两个是 GDI+ 引擎<br><br>type<br> TForm1 = class(TForm)<br> Timer1: TTimer;<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> Procedure MoveForm(var M:TWMNCHITTEST); Message WM_NCHITTEST;<br> procedure Timer1Timer(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>const<br> WS_EX_LAYERED = $80000;<br> LWA_COLORKEY = 1;<br> LWA_ALPHA = 2;<br> ULW_COLORKEY = 1;<br> ULW_ALPHA = 2;<br> ULW_OPAQUE = 4;<br><br>var<br> Form1: TForm1;<br> bmp, old_bmp : HBITMAP;<br> DC : HDC;<br> bitmap:array[1..15] of tgpbitmap;<br> j:integer;<br><br>Function UpdateLayeredWindow(hWnd : HWND;<br> hdcDst : HDC; pptDst : PPoint; psize : PSize;<br> hdcSrc : HDC; pptSrc : PPoint;<br> crKey : COLORREF;<br> pblend : PBlendFunction;<br> dwFlags : DWORD): BOOL; stdcall;<br><br>implementation<br><br>{$R *.dfm}<br><br>Function UpdateLayeredWindow; external 'user32.dll';<br><br>Procedure TForm1.MoveForm (var M:TWMNCHITTEST); <br>begin<br> inherited;<br> M.Result:=HTCAPTION;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> i : integer;<br>begin<br> if SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED) = 0 then ShowMessage(SysErrorMessage(GetLastError)); <br> for i:=1 to 15 do bitmap:=tgpbitmap.Create('./images/dd.'+inttostr(i)+'.png');<br> form1.Width:=bitmap[1].GetWidth;<br> form1.Height:=bitmap[1].GetHeight;<br> J:=1;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>var<br> i:integer;<br>begin<br> SelectObject(DC, old_bmp);<br> DeleteObject(bmp);<br> DeleteDC(DC);<br> for i:=1 to 15 do bitmap.Free;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> pt1, pt2 : TPoint;<br> sz : TSize;<br> bf : TBlendFunction;<br>begin<br> if j>15 then j:=1;<br> pt1 := Point(left, top); <br> pt2 := Point(0, 0); <br> sz.cx := bitmap[1].GetWidth; <br> sz.cy := bitmap[1].GetHeight; <br> bf.BlendOp := AC_SRC_OVER; <br> bf.BlendFlags := 0; <br> bf.SourceConstantAlpha := $ff;<br> bf.AlphaFormat := AC_SRC_ALPHA; <br> DeleteObject(bmp); <br> bitmap[j].GetHBITMAP(0,bmp); <br> DeleteDC(DC);<br> DC := CreateCompatibleDC(Canvas.Handle); <br> old_bmp := SelectObject(DC, bmp);<br> UpdateLayeredWindow(Handle, Canvas.Handle, @pt1, @sz, DC, @pt2,0, @bf,ULW_ALPHA); // 有了这句话,WM_PAINT就不发生了,窗口也不画了,控件也看不见了<br> j:=j+1;<br>end;<br><br>end.