新建From1(窗体),新建Command1(按钮CommandButton),Label1(Label),Option1(OptionButton),代码:
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal ClassName As String, ByVal classlength As Long) As Long
Dim ClassName As String
Dim classlength As Long
Private Sub Form_Load()
ClassName = Space(128)
classlength = GetClassName(Form1.hWnd, ClassName, 128)
ClassName = Left(ClassName, classlength)
MsgBox "Form1 window class is: " & ClassName
End Sub
Private Sub Command1_Click()
ClassName = Space(128)
classlength = GetClassName(Command1.hWnd, ClassName, 128)
ClassName = Left(ClassName, classlength)
MsgBox "Command1 button class is: " & ClassName
End Sub
Private Sub Check1_Click()
ClassName = Space(128)
classlength = GetClassName(Check1.hWnd, ClassName, 128)
ClassName = Left(ClassName, classlength)
MsgBox "Check1 class is: " & ClassName
End Sub
Private Sub Option1_Click()
ClassName = Space(128)
classlength = GetClassName(Option1.hWnd, ClassName, 128)
ClassName = Left(ClassName, classlength)
MsgBox "Option1 class is: " & ClassName
End Sub
运行结果:
Form1 window class is: ThunderFormDC
Command1 button class is: ThunderCommandButton
Check1 class is: ThunderCheckBox
Option1 class is: ThunderOptionButton
小知识:Thunder是微软收购的以前软件公司的名字。