晕,<br>1. 'abc'是3个字符<br>TextOut(_hdc,0,0,'abc',3);<br>2. Delphi是不区别大小写,而c是区别的,<br>所以hdc:HDC在c语言正确,但在delphi行不通,所以改为_hdc:HDC;才可以<br>3. BeginPaint(), EndPaint() 是只能用在响应WM_PAINT消息,而不是在FormCreate<br><br>4. 注意:Textout(..)显示的文字,窗体上如果有控件,可能会遮挡显示的文字<br><br>下面代码调试通过<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> private<br> { Private declarations }<br> protected<br> procedure WMPaint(var Message: TWMPaint); message WM_PAINT;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.WMPaint(var Message: TWMPaint);<br>var<br> _hdc:HDC;<br> _hwnd:hwnd;<br> lpPaint: tagPaintStruct;<br>begin<br> _hdc:=BeginPaint(Self.Handle,lpPaint);<br> TextOut(_hdc, 0, 0,'abc', 3);<br> EndPaint(Self.Handle, lpPaint);<br>end;<br><br>end.<br><br><br>上面代码用WindowsApi麻烦, 用Delphi的Canvas方便:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> procedure FormPaint(Sender: TObject);<br> private<br> { Private declarations }<br> protected<br> <br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br><br><br>procedure TForm1.FormPaint(Sender: TObject);<br>begin<br> Canvas.TextOut(0, 0, 'abc');<br>end;<br><br>end.