使用API重化窗口外观(200分)

  • 主题发起人 主题发起人 slfeng
  • 开始时间 开始时间
S

slfeng

Unregistered / Unconfirmed
GUEST, unregistred user!
下面一段代码的初衷是重化窗口界面,结果无效<br>使用兼容内存是为了防止闪动(我画的东西比较多,直接画容易闪动)<br>请兄弟们看看问题出在哪?<br><br>procedure TPasswordForm.FormPaint(Sender: TObject);<br>var width_:longint;<br>&nbsp; &nbsp; height_:longint;<br>&nbsp; &nbsp; DC : HDC;<br>&nbsp; &nbsp; MemDc :HDC;<br>&nbsp; &nbsp; FormHd: HWND;<br>&nbsp; &nbsp; tempCanvas :TCanvas;<br>&nbsp; &nbsp; BOOL1:BOOL;<br>begin<br>&nbsp; tempCanvas := TCanvas.Create();<br><br>&nbsp; DC := self.GetDeviceContext(FormHd);<br><br>&nbsp; tempCanvas.Handle:= CreateCompatibleDC(DC);<br><br><br>&nbsp; //Draw sth. on tempCanvas....<br>&nbsp; ......<br><br>&nbsp; width_ = 10;<br>&nbsp; height_ = 15;<br>&nbsp;<br><br>&nbsp; if BitBlt( DC,<br> 0,<br> 0,<br> width_,<br> height_,<br> tempCanvas.handle,<br> 0,<br> 0,<br> SRCCOPY) <br> then showmessag('error)';<br><br>&nbsp; DeleteDC(self.Canvas.Handle);<br>&nbsp; tempCanvas.Free;<br>end;
 
FormHd没有赋值。
 
formhd是Var参数,你看看Delphi帮助<br>它是传出值
 
1:<br>if not ... then shomessage('error');<br>2:<br>你最后一个参数使用可能有错!
 
参数应该没错,我从Delphi帮助中Copy的
 
[:(][:D]<br>//测试一下笑脸
 
你应该创建一个 bitmap ,将他选入 tempcanvas 对应的 DC 中才能使绘出的内容有效,如:<br>var<br>&nbsp; DC, MemDC: HDC;<br>&nbsp; MemBitmap, OldBitmap: HBITMAP;<br>&nbsp; tempCanvas: TCanvas;<br>begin<br>&nbsp; DC := GetDC(0);<br>&nbsp; MemBitmap := CreateCompatibleBitmap(DC, ClientRect.Right, ClientRect.Bottom);<br>&nbsp; ReleaseDC(0, DC);<br>&nbsp; MemDC := CreateCompatibleDC(0);<br>&nbsp; OldBitmap := SelectObject(MemDC, MemBitmap);<br>&nbsp; tempCanvas := TCanvas.Create;<br>&nbsp; try<br>&nbsp; &nbsp; tempCanvas.Handle := MemDC;<br>&nbsp; &nbsp; ... //在 tempCanvas 上绘图<br>&nbsp; &nbsp; DC := GetDC(Handle);<br>&nbsp; &nbsp; BitBlt(DC, 0, 0, ClientRect.Right, ClientRect.Bottom, MemDC, 0, 0, SRCCOPY);<br>&nbsp; &nbsp; ReleaseDC(Handle, DC);<br>&nbsp; finally<br>&nbsp; &nbsp; SelectObject(MemDC, OldBitmap);<br>&nbsp; &nbsp; DeleteDC(MemDC);<br>&nbsp; &nbsp; DeleteObject(MemBitmap);<br>&nbsp; &nbsp; tempCanvas.Free;<br>&nbsp; end;<br>end;<br>其实对于 Form 可以设置 DoubleBuffered 为 True, 在 OnPaint 事件中直接在 Form 的<br>Canvas 上绘图实际就是在 MemoryDC 上作图,VCL 自动帮你把 MemoryDC 上的东西再画到<br>Form 的 DC 上的。 &nbsp; <br>
 
if BitBlt( DC,<br> 0,<br> 0,<br> width_,<br> height_,<br> tempCanvas.handle,<br> 0,<br> 0,<br> SRCCOPY) <br> then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[red]else[/red] showmessag('error)';<br>
 
多人接受答案了。
 
后退
顶部