Results 1 to 13 of 13

Thread: Window Class Name

  1. #1

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Window Class Name

    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"?

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    I cannot give a description of a classname but you can find out the classname by using the api call GetClassName.

  3. #3
    Junior Member
    Join Date
    Nov 2000
    Location
    Kalpetta,Wayanad,Kerala,india
    Posts
    25

    Wink class Names

    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
    Attached Files Attached Files

  4. #4

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    brijmohank,

    Cool thanks for both the exe and the code, both worked perfectly .

    Could you tell me what a windows class name is?

  5. #5
    Tygur
    Guest
    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..

  6. #6
    Matthew Gates
    Guest
    Take a look at how Megatron described a Classname in this thread.

  7. #7

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Thank's all for clearing up this little mystery

  8. #8
    Member
    Join Date
    Apr 2001
    Location
    Lake Charles, LA, USA
    Posts
    43
    Does anyone know how to change the class name of an app?

  9. #9
    Gerco
    Guest
    Originally posted by cinder829
    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.

    The ony way is to edit the sourcecode for the program and recompile it.

  10. #10
    Member
    Join Date
    Apr 2001
    Location
    Lake Charles, LA, USA
    Posts
    43
    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.
    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?

  11. #11
    Gerco
    Guest
    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.
    A simple question deserves a simple answer: "You don't, it's impossible".

    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!

  12. #12
    Megatron
    Guest
    Originally posted by Tygur
    For example, ThunderTextBox is the classname for all VB TextBoxes (at least in vb6).
    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).

  13. #13
    Tygur
    Guest
    As you can tell, I just did a quick check

    I guess I should've mentioned that I was in the IDE, too (rather than just saying that I was using vb6).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width