
在用API函数LineTo和MoveToEx绘制线条时用哪个API函数可以设置前景色呀?
请问在用API函数LineTo和MoveToEx绘制线条时,用哪个API函数可以设置用于绘图的前景色以便绘制不同颜色的线条呀?...
请问在用API函数LineTo和MoveToEx绘制线条时,用哪个API函数可以设置用于绘图的前景色以便绘制不同颜色的线条呀?
展开
2个回答
展开全部
画之前设置你所画设备场景的ForeColor即可
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpPoint As Any) As Long
Dim i As Integer
Private Sub Command1_Click()
Me.DrawWidth = i * 10
Me.ForeColor = QBColor(i)
MoveToEx Me.hdc, Me.ScaleWidth / 2, 0, ByVal 0&
LineTo Me.hdc, 10 * i, 100 * i
i = i + 1
If i > 7 Then i = 1
End Sub
Private Sub Form_Load()
i = 1
End Sub
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpPoint As Any) As Long
Dim i As Integer
Private Sub Command1_Click()
Me.DrawWidth = i * 10
Me.ForeColor = QBColor(i)
MoveToEx Me.hdc, Me.ScaleWidth / 2, 0, ByVal 0&
LineTo Me.hdc, 10 * i, 100 * i
i = i + 1
If i > 7 Then i = 1
End Sub
Private Sub Form_Load()
i = 1
End Sub
展开全部
在GDI中,设备场景(DC)的“前景色”和“背景色”分别是由当前选入DC的Pen对象和Brush对象决定的,因此,楼主的问题应该先用CreatePen或CreatePenIndirect创建指定颜色、样式和宽度的线条画笔(Pen),然后用selectObject把画笔选到DC中去,之后再画线就是用这个画笔画的了,最后别忘了用恢复原来的默认画笔并销毁自己创建的画笔,否则会引起GDI泄露。
代码大致是这样:
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Const PS_DASH = 1 ' -------
Private Const PS_DASHDOT = 3 ' _._._._
Private Const PS_DASHDOTDOT = 4 ' _.._.._
Private Const PS_DOT = 2 ' .......
Private Const PS_NULL = 5
Private Const PS_SOLID = 0
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim pt As POINTAPI
Dim hPen As Long
Dim hPenPrev As Long
hPen = CreatePen(PS_DOT, 1, vbRed)
Me.AutoRedraw = True
hPenPrev = SelectObject(Me.hdc, hPen)
MoveToEx Me.hdc, 10, 100, pt
LineTo Me.hdc, 200, 100
SelectObject Me.hdc, hPenPrev
DeleteObject hPen
End Sub
代码大致是这样:
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Const PS_DASH = 1 ' -------
Private Const PS_DASHDOT = 3 ' _._._._
Private Const PS_DASHDOTDOT = 4 ' _.._.._
Private Const PS_DOT = 2 ' .......
Private Const PS_NULL = 5
Private Const PS_SOLID = 0
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim pt As POINTAPI
Dim hPen As Long
Dim hPenPrev As Long
hPen = CreatePen(PS_DOT, 1, vbRed)
Me.AutoRedraw = True
hPenPrev = SelectObject(Me.hdc, hPen)
MoveToEx Me.hdc, 10, 100, pt
LineTo Me.hdc, 200, 100
SelectObject Me.hdc, hPenPrev
DeleteObject hPen
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询