1. What is a windows class name?
2. How do I determine the windows class name of a given application. For example how do I determine that Excel's window's class name is "XLMain" and word's class name "OpusApp"?
Printable View
1. What is a windows class name?
2. How do I determine the windows class name of a given application. For example how do I determine that Excel's window's class name is "XLMain" and word's class name "OpusApp"?
I cannot give a description of a classname but you can find out the classname by using the api call GetClassName.
To find Window class names,you can use the following code
Run this program and move mouse over the windows you will get the corresponding "window class names"
in a form put 3 labels with their "Auto Size" property to true and
place a timer also.Now place the following code
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Label3.Caption = "KeyCode = " & KeyCode
End Sub
Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 1
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim b As POINTAPI
Dim r, s, t As String
GetCursorPos b
Label1.Caption = "Mouse Position =" & " { " & b.X & " , " & b.Y & " }"
r = WindowFromPoint(b.X, b.Y)
t = Space(128)
s = GetClassName(r, t, 128)
Label2.Caption = "ClassName = " & t
End Sub
brijmohank,
Cool thanks for both the exe and the code, both worked perfectly :cool: .
Could you tell me what a windows class name is?
When a program creates a new window, it has to tell windows what kind of window it is. That's what the class name is for. For example, ThunderTextBox is the classname for all VB TextBoxes (at least in vb6).
If anyone wants to explain further, they can go ahead..
Take a look at how Megatron described a Classname in this thread.
Thank's all for clearing up this little mystery http://www.vbforums.com/
Does anyone know how to change the class name of an app?
You don't. period. The app wouldn't be able to create it's window if you changed the class name.Quote:
Originally posted by cinder829
Does anyone know how to change the class name of an app?
The ony way is to edit the sourcecode for the program and recompile it.
That's what I want to know how to do. I'm not interested in changing the class name during execution, or changing another programs class name, what I want to know is how do you set the class name of a vb program at design time so that it can be MyAppName instead of ThunderFormDC. Anyone?Quote:
You don't. period. The app wouldn't be able to create it's window if you changed the class name.
The ony way is to edit the sourcecode for the program and recompile it.
A simple question deserves a simple answer: "You don't, it's impossible".Quote:
Originally posted by cinder829
how do you set the class name of a vb program at design time so that it can be MyAppName instead of ThunderFormDC.
For the same reason as above, the VB runtime system NEEDS the class names to be as they are, you cannot change them and still expect your program to work.
You might be able to fake them though. Create your own WndClass and create a window of that class, hide it and pass all window messages you get to the ThunderMain class (your VB main form).
DISCLAIMER: I did not test the method above, I just came up with it, if your computer blows up, your wife leaves you or anything at all happens, it's not my fault!
Careful there. ThunderTextBox is the name for the VB TextBox in the IDE only. Once you compile it, the class will change from ThunderTextBox to ThunderRT6TextBox. (replace 6 with your VB version number).Quote:
Originally posted by Tygur
For example, ThunderTextBox is the classname for all VB TextBoxes (at least in vb6).
As you can tell, I just did a quick check :D
I guess I should've mentioned that I was in the IDE, too (rather than just saying that I was using vb6).