API中最菜的问题。(0分)

Z

zhengxb

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我刚刚抄书上的例子,但出错了,我不知道如何定义句柄。<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormMouseUp(Sender:Tobject;Button:TMouseButton;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Shift:TShiftState;x,y:integer);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; TheRect:TRect;<br>&nbsp; hdc:HDC;<br>&nbsp; str1:pChar;<br>implementation<br><br>{$R *.DFM}<br>procedure TForm1.FormMouseUp(Sender:Tobject;Button:TMouseButton;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Shift:TShiftState;x,y:integer);<br>begin<br>&nbsp; TheRect.Left:=x;<br>&nbsp; theRect.Top:=y;<br>&nbsp; theRect.Right:=x+100;<br>&nbsp; theRect.Bottom:=y+100;<br>&nbsp; hdc1:=GetDC(self.Handle);<br>&nbsp; SetTextColor(hdc1,rgb(255,0,0));<br>&nbsp; setbkMode(hdc1,transparent);<br>&nbsp; str1:='同志工作室';<br>&nbsp; drawText(hdc1,str1,-1,theRect,DT_left);<br>end;<br>end.<br>//出错信息。<br>[Error] Unit1.pas(21): Constant or type identifier expected<br>[Error] Unit1.pas(33): Undeclared identifier: 'hdc1'<br>
 
&gt;hdc1:=GetDC(self.Handle);<br>hdc1没有定义
 
我知道没有定义,但我不知道如何定义。这是书上给的,我不知道如何改正
 
procedure TForm1.FormMouseUp(Sender:Tobject;Button:TMouseButton;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Shift:TShiftState;x,y:integer);<br>var<br>&nbsp;hdc1:HDC; //&lt;---- here <br>begin
 
var<br>&nbsp; Form1: TForm1;<br>&nbsp; TheRect:TRect;<br>&nbsp; hdc1:HDC; // -&gt;&gt; 修改 &nbsp;hdc:HDC 少了个 1<br>&nbsp; str1:pChar;
 
顶部