UpdateLayeredWindow过的窗口怎么显示控件(100分)

  • 主题发起人 主题发起人 wang_cai1
  • 开始时间 开始时间
W

wang_cai1

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