在VB的类模块中使用定时器
长久以来,由于不能直接获得VB类成员函数指针,因为无法在VB的类模块中直接使用定时器控件或定时器API,基于俺编写的获得类成员函数指针的函数,俺编写了这个带定时器功能的类,希望给朋友们一些启发。
一、新建一个类,类名称为clsTimer,类代码如下:
Option Explicit
'* ******************************************** *
'* 模块名称:clsTimer.cls
'* 功能:在VB类模块中使用计时器
'* 作者:lyserver
'* ******************************************** *
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, ByVal Length As Long)
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Dim m_idTimer As Long
Dim m_Enabled As Boolean
Dim m_Interval As Long
Dim m_lTimerProc As Long
Private Sub Class_Initialize()
m_Interval = 0
m_lTimerProc = GetClassProcAddr(8)
End Sub
Private Sub Class_Terminate()
If m_idTimer <> 0 Then KillTimer 0, m_idTimer
End Sub
Public Property Get Interval() As Long
Interval = m_Interval
End Property
Public Property Let Interval(ByVal New_Value As Long)
If New_Value >= 0 Then m_Interval = New_Value
End Property
Public Property Get Enabled() As Boolean
Enabled = m_Enabled
End Property
Public Property Let Enabled(ByVal New_Value As Boolean)
m_Enabled = New_Value
If m_idTimer <> 0 Then KillTimer 0, m_idTimer
If New_Value And m_Interval > 0 Then
m_idTimer = SetTimer(0, 0, m_Interval, m_lTimerProc)
End If
End Property
Private Function GetClassProcAddr(ByVal Index As Long, Optional ParamCount As Long = 4, Optional HasReturnValue As Boolean) As Long
Static lR
相关文档:
很久以前的一个代码了。。。。。那时还沉迷于研究WindowsXP登录密码的计算方法。。。。
先新建一个VB工程,画一个CommandButton,改名为cmdGetSYSKEY,画一个TextBox,改名为txtSYSKEY,然后粘贴下面的代码,运行即可,在WindowsXP SP2 Build 2600 + VB6.0 SP6下测试通过,获得的SYSKEY与Cain&Abel v4.9.6一致。。。。 ......
Welcome to Microsoft Developer Support, Languages team blog! You will find a lot of language related troubleshooting resources here.
Troubleshooting PInvoke Related Issues
I am back with some more PInvoke Stuff. Recently I was working on a PInvoke issue which I found interesting ......
'**************************读图片文件**************************************
Sub GetPicfromDB(cn As ADODB.Connection)
On Error Resume Next
Dim ......
VB对INI文件操作
2009-02-25 00:17
INI 文件是什么样子?——不会吧,这都不知道。INI 文件就是 Windows 中常见
的以 .ini 为扩展名的文件,其内部格式和各部分的名称如下:
[Section1]
Key1=Value1
Key2=Value2
Key3=Vlaue3
[Section2]
Key1=Value1
Key2=Value5
Key4=Value4
Key5=...
...
& ......
使用VC编写VB使用DLL
一、在函数定义前必须加上extern "c",_stdcall关键字。
extern "C" int _stdcall Sum(int x,int y)
{
return x+y;
}
二、DLL的.def文件中必须加上入口函数
EXPORTS
sample @1
  ......