回复 2楼 风吹过b
直接用picture.line写的,后面用到bitblt函数,都是在当前窗体中的。
下面是源代码:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal VbSrcCopy As Long) As Long
Public s As Long
Dim x As Single
Dim hvar As Long
Dim y(0) As Single
Private Sub Command1_Click()
Picture1.Refresh
Timer1.Enabled = True
Timer1.Interval = 20
Call AdsOcx1.AdsCreateVarHandle("MAX1.x", hvar)
End Sub
Private Sub Form_Load()
AdsOcx1.EnableErrorHandling = True
AdsOcx1.AdsAmsServerNetId = AdsOcx1.AdsAmsClientNetId
AdsOcx1.AdsAmsServerPort = 801
'CX1000的Run-Time System 1的端口号
AdsOcx1.AdsAmsConnect
Call AdsOcx1.AdsCreateVarHandle("MAX1.x", hvar)
Picture1.Scale (-4400, 2600)-(4400, -2600)
Picture1.ScaleMode = 1
Picture1.Refresh
Picture1.AutoRedraw = True
s = 200
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call AdsOcx1.AdsDeleteVarHandle(hvar)
AdsOcx1.AdsAmsDisconnect
End Sub
Private Sub Timer1_Timer()
'Read variable
Call AdsOcx1.AdsSyncReadSingleVarReq(hvar, 4, x)
Text1.Text = CStr(x)
Call AdsOcx1.AdsSyncReadReq(&HF030&, 100&, 4&, y)
Text2.Text = CStr(y(0))
Dim w As Long, h As Long, y1 As Single, m As Single
Dim hBmp As Long, ShowMode As Long, ii As Long, t1 As Integer
w = Picture1.Width
h = Picture1.Height
hBmp = Picture1.hDC
ShowMode = &HCC0020 'ROP模式(复制)
Picture1.DrawWidth = 1
y1 = (s - y(0)) / s * h * 2 - 5000
ii = BitBlt(hBmp, 0, 0, w - 6, h, hBmp, -1, 0, ShowMode)
Picture1.Line (w - 1, m)-(w, y1), RGB(255, 0, 0)
m = y1
End Sub
求指点!