标题:gdi 绘图的问题
取消只看楼主
afeibfp
Rank: 2
等 级:论坛游民
威 望:1
帖 子:11
专家分:31
注 册:2007-6-1
 问题点数:0 回复次数:1 
gdi 绘图的问题
在dc里绘制一个矩形,外框是否绘制根据设置分别用LineTo绘制,包括外框的粗细,代码如下:
程序代码:
Public Sub DrawRectBox(hdc As Long)
Dim cRect As RECT
Dim hBrushFill As Long
Dim hNewPen As Long
Dim tLB As LOGBRUSH
Dim off1 As Long, off2 As Long

    'Debug.Print Me.Name
    Call SetRect(cRect, 8, 8, 112, 64)  '设置绘制的矩形
    
    '根据边框粗细设置画笔
    tLB.lbColor = GetSysColor(COLOR_WINDOWTEXT)
    hNewPen = ExtCreatePen(PS_GEOMETRIC Or PS_ENDCAP_FLAT Or PS_SOLID, mlBorderSize, tLB, 0, ByVal 0&)
    hNewPen = SelectObject(hdc, hNewPen)

    '根据边框大小(1-4),计算偏移
    off1 = mlBorderSize \ 2: off2 = mlBorderSize - off1 - 1
    Debug.Print off1, off2

    If (mlBorderStyle And afrEdgeTop) <> 0 Then     '上边
        Call MoveToEx(hdc, cRect.Left - off1, cRect.Top, 0&)
        Call LineTo(hdc, cRect.right + off2, cRect.Top)
    End If
    
    If (mlBorderStyle And afrEdgeBottom) <> 0 Then  '下边
        Call MoveToEx(hdc, cRect.Left - off1, cRect.bottom, 0&)
        Call LineTo(hdc, cRect.right + off2, cRect.bottom)
    End If
    If (mlBorderStyle And afrEdgeLeft) <> 0 Then    '左边
        Call MoveToEx(hdc, cRect.Left, cRect.Top - off1, 0&)
        Call LineTo(hdc, cRect.Left, cRect.bottom + off2)
    End If
    If (mlBorderStyle And afrEdgeRight) <> 0 Then   '右边
        Call MoveToEx(hdc, cRect.right, cRect.Top - off1, 0&)
        Call LineTo(hdc, cRect.right, cRect.bottom + off2)
    End If

    hNewPen = SelectObject(hdc, hNewPen)    '删除gdi对象
    Call DeleteObject(hNewPen)
End Sub


但是绘制直线的位置是错误的,可是令人惊奇的是在代码前添加 debug.print me.name 时却绘制正确了。图见附件
根据debug.print 可以看到off1,off2的值已经发生变化了
Desktop.zip (6.46 KB)

这到底是为什么???
2014-05-31 01:20
afeibfp
Rank: 2
等 级:论坛游民
威 望:1
帖 子:11
专家分:31
注 册:2007-6-1
得分:0 
已经把bug定位到MoveToEx了,请看这个帖子:https://bbs.bccn.net/viewthread.php?tid=432302&extra=page%3D1&frombbs=1
2014-05-31 03:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-432300-1-1.html




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

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