| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1303 人关注过本帖, 1 人收藏
标题:drawfocusrect 用法存疑,
只看楼主 加入收藏
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:786
专家分:1160
注 册:2021-10-13
结帖率:96.72%
收藏(1)
已结贴  问题点数:20 回复次数:14 
drawfocusrect 用法存疑,
哪位兄弟对api比较熟悉,帮我看看我的这段程序那里的逻辑有问题?我得不到正确的矩形。。。
代码如下:
程序代码:
**************************************************
*-- 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
**************************************************


我的企图: 按下鼠标键,移动鼠标,实时画出一个矩形,鼠标松开后,矩形清除。
搜索更多相关主题的帖子: parent this thisform PROCEDURE Integer 
2022-09-20 00:01
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:786
专家分:1160
注 册:2021-10-13
收藏
得分:0 
程序运行结果,都不是矩形了。。。
图片附件: 游客没有浏览图片的权限,请 登录注册
2022-09-20 00:05
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:786
专家分:1160
注 册:2021-10-13
收藏
得分:0 
DECLARE Integer DrawFocusRect IN WIN32API Integer hdc , String lpRect

这个函数使用相同参数时,第一次画,第二次是擦除。我用计时器来记住上次画的参数,一遍在画新的矩形时,及时擦去旧的矩形。问题可能就出在这里timer1.timer
2022-09-20 00:13
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:300
专家分:436
注 册:2019-10-11
收藏
得分:20 
form1=CREATEOBJECT("form1")
form1.show()
read even
retu
**************************************************
*-- 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 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
        WITH this
            IF .x#.oldx or .y#.oldy
                lcrect=thisform.long2str(.x)+thisform.long2str(.y)+thisform.long2str(.oldx)+thisform.long2str(.oldy)
                DrawFocusRect(getdc(thisform.hwnd),lcrect)
            endif
            .x=nxcoord
            .y=nycoord
            .oldx=nxcoord
            .oldy=nycoord
        endwith
    ENDIF
    thisform.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
    thisform.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
    WITH thisform.container1
        IF .tox>.x and .toy>.y
            IF .tox#.oldx or .toy#.oldy
                lcrect=thisform.long2str(.x)+thisform.long2str(.y)+thisform.long2str(.oldx)+thisform.long2str(.oldy)
                DrawFocusRect(getdc(thisform.hwnd),lcrect)
                .oldx=.tox
                .oldy=.toy
                lcrect=thisform.long2str(.x)+thisform.long2str(.y)+thisform.long2str(.oldx)+thisform.long2str(.oldy)
                DrawFocusRect(getdc(thisform.hwnd),lcrect)

*************************************************************************************************
                ACTIVATE SCREEN
*                ?.iscleared &&我观察程序运行过程用
                ??.x,.y,.oldx,.oldy,.tox,.toy
*************************************************************************************************
*                IF .iscleared=.f.
*                    .iscleared=.t.
*                ELSE
*                    .iscleared=.f.
*                ENDIF
            ENDIF
        ENDIF
    endwith
    ENDPROC

    PROCEDURE unload
    CLEAR EVENTS
    ENDPROC
ENDDEFINE
2022-09-20 08:50
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:300
专家分:436
注 册:2019-10-11
收藏
得分:0 
long2str函数可以用bintoc代替
2022-09-20 08:55
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:0 
弄这个API的,都是高手
2022-09-20 08:57
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
先不用timer,手动按一下按一下试试
2022-09-20 10:21
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:786
专家分:1160
注 册:2021-10-13
收藏
得分:0 
回复 4楼 sych


非常感谢,看来是我画蛇添足了。
2022-09-20 11:47
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:786
专家分:1160
注 册:2021-10-13
收藏
得分:0 
回复 7楼 吹水佬
这个方法好,之前我在调试窗口都没法跟踪!
2022-09-20 11:48
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:786
专家分:1160
注 册:2021-10-13
收藏
得分:0 
回复 5楼 sych
bintoc怎么用?
2022-09-20 13:07
快速回复:drawfocusrect 用法存疑,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054193 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved