每次创建线程前设置要传递的参数
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As LongPrivate m_hWNd As Long
Private m_iSize As LongPublic Function GetStepSize() As Long
StepSize = m_iSize
End Sub
Public Sub SetStepSize(ByVal iStepSize As Long)
m_iSize = iStepSize
If Not m_hWNd = 0 Then
SetProp m_hWNd, "CTest:StepSize", m_iSize
End If
End Sub
Public Sub SethWnd(ByVal hWnd As Long)
pRemoveProps
m_hWNd = hWnd
pSetProps
End Sub
Private Sub pSetProps()
SetStepSize(m_iSize)
End Sub
Private Sub pRemoveProps()
If Not m_hWNd = 0 Then
RemoveProp m_hWNd, "CTest:StepSize"
End If
End Sub在线程中读取参数
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private m_iSize As Long
Private m_hWNd As Long
Private Sub DefaultProp(ByVal sName As String, ByVal lDefault As Long) As Long
Dim lR As Long
If m_hWNd = 0 Then
DefaultProp = lDefault
Else
lR = GetProp(m_hWNd, sName)
If Not (lR = 0) Then
DefaultProp = lR
Else
DefaultProp = lDefault
End If
End If
End SubPublic Sub GetProp()
m_iSize = DefaultProp("CTest:StepSize", 4)
End Sub
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As LongPrivate m_hWNd As Long
Private m_iSize As LongPublic Function GetStepSize() As Long
StepSize = m_iSize
End Sub
Public Sub SetStepSize(ByVal iStepSize As Long)
m_iSize = iStepSize
If Not m_hWNd = 0 Then
SetProp m_hWNd, "CTest:StepSize", m_iSize
End If
End Sub
Public Sub SethWnd(ByVal hWnd As Long)
pRemoveProps
m_hWNd = hWnd
pSetProps
End Sub
Private Sub pSetProps()
SetStepSize(m_iSize)
End Sub
Private Sub pRemoveProps()
If Not m_hWNd = 0 Then
RemoveProp m_hWNd, "CTest:StepSize"
End If
End Sub在线程中读取参数
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private m_iSize As Long
Private m_hWNd As Long
Private Sub DefaultProp(ByVal sName As String, ByVal lDefault As Long) As Long
Dim lR As Long
If m_hWNd = 0 Then
DefaultProp = lDefault
Else
lR = GetProp(m_hWNd, sName)
If Not (lR = 0) Then
DefaultProp = lR
Else
DefaultProp = lDefault
End If
End If
End SubPublic Sub GetProp()
m_iSize = DefaultProp("CTest:StepSize", 4)
End Sub
给我一个用createthread创建线程传第参数的例子
2: 把createthread的lpParameter声明为byref as any.
3: 声明一个 typYourType 变量,并赋值。
4:createthread传入该变量。
5:申明TreadProc为:Public Function ThreadProc(lpParameter As typYourType) As Long
6:搞定。