![]() |
#2
sam_jiang2022-09-20 00:05
|
代码如下:

**************************************************
*-- Form: form1 (d:\documents\visual foxpro 项目\drawrectangle.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 09/19/22 11:52:08 PM
*
DEFINE CLASS form1 AS form
Top = 0
Left = -1
Height = 650
Width = 1000
DoCreate = .T.
BorderStyle = 3
Caption = "Form1"
MaxButton = .F.
Name = "Form1"
ADD OBJECT container1 AS container WITH ;
Top = 0, ;
Left = 0, ;
Width = 1000, ;
Height = 650, ;
SpecialEffect = 1, ;
BackColor = RGB(255,255,255), ;
Name = "Container1"
ADD OBJECT form1.container1.timer1 AS timer WITH ;
Top = 10, ;
Left = 10, ;
Height = 23, ;
Width = 23, ;
Name = "Timer1"
PROCEDURE long2str
PARAMETERS longval
PRIVATE i, retstr
retstr = ""
FOR i = 24 TO 0 Step -8
retstr = CHR(int(longval/(2^i))) + retstr
longval = mod(longval, (2^i))
NEXT
Return retstr
ENDPROC
PROCEDURE Resize
this.container1.Width=this.Width-1
this.container1.Height=this.Height-1
ENDPROC
PROCEDURE container1.MouseMove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.tox=nxcoord
this.toy=nycoord
ENDPROC
PROCEDURE container1.MouseDown
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nbutton=1 &&mouse left
this.x=nxcoord
this.y=nycoord
ENDIF
this.timer1.Interval=100
ENDPROC
PROCEDURE container1.Init
this.AddProperty("X",0)
this.AddProperty("Y",0)
this.AddProperty("toX",0)
this.AddProperty("toY",0)
this.AddProperty("oldX",0)
this.AddProperty("oldY",0)
this.AddProperty("iscleared",.t.)
STORE 1 TO this.Top,this.left
this.Height=thisform.Height-1
this.Width=thisform.Width-1
ENDPROC
PROCEDURE container1.MouseUp
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.timer1.Interval=0
IF this.iscleared=.f.
lcrect=thisform.long2str(this.x)+thisform.long2str(this.y)+thisform.long2str(this.oldx)+thisform.long2str(this.oldy)
DrawFocusRect(getdc(thisform.hwnd),lcrect)
this.iscleared=.t.
ENDIF
ENDPROC
PROCEDURE timer1.Init
DECLARE Integer DrawFocusRect IN WIN32API ;
Integer hdc , ;
String lpRect
DECLARE Integer GetDC IN WIN32API ;
Integer hwnd
DECLARE integer ReleaseDC IN WIN32API integer hwnd,integer hdc
ENDPROC
PROCEDURE timer1.Timer
IF this.parent.tox>this.parent.x and this.parent.toy>this.parent.y
IF this.Parent.tox#this.Parent.oldx or this.Parent.toy#this.Parent.oldy
lcrect=thisform.long2str(this.parent.x)+thisform.long2str(this.parent.y)+thisform.long2str(this.parent.tox)+thisform.long2str(this.parent.toy)
DrawFocusRect(getdc(thisform.hwnd),lcrect)
*************************************************************************************************
ACTIVATE SCREEN
?this.parent.iscleared &&我观察程序运行过程用
??this.parent.x,this.Parent.y,this.parent.oldx,this.parent.oldy,this.parent.tox,this.parent.toy
*************************************************************************************************
this.parent.oldx=this.Parent.tox
this.parent.oldy=this.Parent.toy
IF this.Parent.iscleared=.f.
this.Parent.iscleared=.t.
ELSE
this.Parent.iscleared=.f.
ENDIF
ENDIF
ENDIF
ENDPROC
ENDDEFINE
*
*-- EndDefine: form1
**************************************************
我的企图: 按下鼠标键,移动鼠标,实时画出一个矩形,鼠标松开后,矩形清除。