VB 在桌面屏幕上画一条直线如何让它重绘?
发布网友
发布时间:2022-04-26 05:08
我来回答
共5个回答
热心网友
时间:2022-06-21 00:27
'屏幕重绘 源码如下
'画多线声波色条
Public Sub DrawFrequencies(intSamples() As Integer, picbox As PictureBox)
'FFT_SAMPLES = 1024
Dim sngRealOut(FFT_SAMPLES - 1) As Single
Dim sngBand As Single
Dim hBrush As Long
Dim i As Long
Dim j As Long
Dim intRed As Integer
Dim intGreen As Integer
Dim intBlue As Integer
Dim rcBand As RECT
If UBound(intSamples) < FFT_SAMPLES - 1 Then Exit Sub
If clsFFT Is Nothing Then
Set clsFFT = New clsFourier
clsFFT.NumberOfSamples = FFT_SAMPLES
clsFFT.WithTimeWindow = 1
End If
'读入数据
For i = 0 To FFT_SAMPLES - 1 'FFT_SAMPLES = 1024
clsFFT.RealIn(i + 1) = intSamples(i) '动态数值传送
Next
' lower band amplitudes
For i = 0 To FFT_BANDS - 1 'band(i) = 0 FFT_BANDS = 22
band(i) = band(i) - FFT_BANDLOWER 'FFT_BANDLOWER = 0.07
If band(i) < 0 Then band(i) = 0
Next
'band(0) = 0 : band(1) = 0 : band(2) = 0 : band(3) = 0 : band(4) = 0 : band(5) = 0 : band(6) = 0
For i = 0 To FFT_SAMPLES / 2
'FFT_SAMPLES = 1024
sngRealOut(i) = clsFFT.ComplexOut(i + 1) / (FFT_SAMPLES / 4) / 32767
If sngRealOut(i) > FFT_MAXAMPLITUDE Then
sngRealOut(i) = FFT_MAXAMPLITUDE
End If
sngRealOut(i) = sngRealOut(i) / FFT_MAXAMPLITUDE 'FFT_MAXAMPLITUDE = 0.2
Next
j = FFT_STARTINDEX
For i = 0 To FFT_BANDS - 1 'FFT_BANDS = 22
For j = j To j + FFT_BANDWIDTH 'FFT_BANDWIDTH = 3
sngBand = sngBand + sngRealOut(j)
Next
sngBand = (sngBand * (Hanning(i + 3, FFT_BANDS + 3) + 1)) / FFT_BANDWIDTH
'MsgBox band(i) '--------------------------------
If band(i) < sngBand Then band(i) = sngBand
If band(i) > 1 Then band(i) = 1
j = j + FFT_BANDSPACE
Next
' draw bars
picbox.Cls
intRed = 255
intBlue = 50
'画整个色块 共22块色条
For i = 0 To FFT_BANDS - 1 'FFT_BANDS = 22 picbox.ScaleHeight = 18
intGreen = (band(i) * 255) ' i ( 0-21)
hBrush = CreateSolidBrush(RGB(intRed, intGreen, intBlue))
'画单个色块
With rcBand
.Right = i * (DRW_BARWIDTH + DRW_BARSPACE) + DRW_BARWIDTH + DRW_BARXOFF
.Left = i * (DRW_BARWIDTH + DRW_BARSPACE) + DRW_BARXOFF
'单个色块的高度 忽上忽下 DRW_BARYOFF=2 常数 band(i)自定精度数组(0-22) 从小到大
'.Top = max(DRW_BARYOFF, Min(picbox.ScaleHeight, picbox.ScaleHeight - (picbox.ScaleHeight * band(i))) - DRW_BARYOFF) ' - 1)
.Top = max(2, Min(18, 18 - (18 * band(i))) - 2)
.Bottom = picbox.ScaleHeight - DRW_BARYOFF
End With
FillRect picbox.hdc, rcBand, hBrush '用指定刷子填充色块区域
DeleteObject hBrush
Next
End Sub
热心网友
时间:2022-06-21 00:27
我有办法。
用windowfrompoint拿到窗口句柄,然后用setwindowlong取代他原来的wndproc,在wm_paint事件里执行你的绘画操作。
autoredraw是个很没有意思的属性,他大量浪费资源。比较好的做法是在paint事件里处理。
例如你在x,y画线
public lpfn as long
public functoin Doit()
dim hWindow as long
hwindow=windowfrompoint(x,y)
lpfn=setwindowlong(hwindow,GWL_WNDPROC, addressof WndPorc)
end function
public function WndProc (byval hwnd as long, byval uMsg as long, byval wparam as long, byval lparam as long)
callwindowproc lpfn,hwnd,umsg,wparam,lparam
if umsg=wm_paint then
'linto或者任何操作
end if
end function
热心网友
时间:2022-06-21 00:28
把当前屏幕位图截成Bitmap保存,编辑然后把它设为墙纸
热心网友
时间:2022-06-21 00:28
捕捉屏幕的刷新事件,在这里调用划线。
热心网友
时间:2022-06-21 00:29
有API函数可让它重绘.你找以下<windows API函数大全>.里面有.
用window 的图元文件重绘.