Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Class names for Excel's windows

    Hi,

    Does someone know where I can find more information on the class names for Excel's windows? e.g. I want to use API calls, like

    handle = FindWindow("ThunderDFrame", UserForm1.Caption)

    here, "ThunderDFrame" is the class name for Excel's UserForms. But what about sheets and charts??? Especially, if an embedded chart is in a chart window, is there a class name for this?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hans,

    The following are some XL window class names I have come across.

    XLMAIN, the main window with caption Microsoft Excel - Book1 or whatever
    XLDESK, the background window when no workbook is open, or all are minimised.
    EXCEL7, A worksheet sheet window, and as far as i know also a Chart window
    I think there is an EXCEL8, but not sure what it is
    EXCELE, is I think the one you refer to as an embedded chart in it's own (temporary) window.
    EXCEL<, is I think the formula bar. and as you pointed out
    ThunderDFrame is the UserForm Window

    Hope there is enough there to keep you going for a while, though I suspect I am missing some.

    Andrew

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Andrew,

    I printed that one for future reference. Thanks!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Thanks Andrew,

    your list is really helpful for me. Maybe I can add what I have:
    Excel Status Bar : EXCEL4 (that 's different from your class name, so I have to try that out)
    Excel Userform for Excel 97: ThunderXFrame
    Excel dialog sheet: bosa_sdm_xl9 (in Excel 2000), bosa_sdm_xl8 (in Excel 97) and bosa_sdm_xl (in Excel 5 and 95)

    I wrote a macro using API calls to have a UserForm always on top and now I want to do the same with a chart (don't know if this will work).

    Many Thanks again.

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hi Hans,

    I have come across some interesting window class names for both Excel and Word. I put together some API calls and a bit of code with a useform which is supposed to show the window under the cursor.

    It can bes used in Excel or Word (or I suppose any flavour of VBA or VB) and I attach a zip file for anybody interested. It contains a bas module and and a userform which can be imported into VBA (xl or word). Actually if you interested in Excel windows, it is better to run it from a running version of word, as you can work all Excel dialogs and get a name for them from the Word userform, and vice versa if you are interested in Word windows.

    It seems to work, though I have tried it in all circumstances - it a rough and ready method.

    BTW the userform is modeless.

    Andrew
    Attached Files Attached Files

  6. #6
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Wow, Andrew, this is wonderful.

    Although, there is still one thing... My code below seems to work for a userform, but not for an embedded chart. Any ideas??

    Option Explicit
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    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
    Sub set_on_top(hdl As Variant, bTop As Boolean)
    Const SWP_NOSIZE = &H1
    Const SWP_NOMOVE = &H2
    Const SWP_NOACTIVATE = &H10
    Const SWP_SHOWWINDOW = &H40
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    Dim WinFlags As Variant
    Dim PosFlag As Variant
    Dim return_code As Long
    WinFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
    Select Case bTop
    Case True
    PosFlag = HWND_TOPMOST
    Case False
    PosFlag = HWND_NOTOPMOST
    End Select
    return_code = SetWindowPos(hdl, PosFlag, 0, 0, 0, 0, WinFlags)
    End Sub

    Sub test()
    Dim handle As Long
    handle = FindWindow("EXCELE", "[alwaysontop.xls]Sheet1 Chart1")
    Call set_on_top(handle, True)
    End Sub


    If I replace EXCELE by ThunderDFrame and the second argument by UserForm1.Caption, the userform stays always on top. However, it does not work for an embedded chart. Maybe, I misspelled the window caption, but I don't think so.
    Of course, if I add a button to the UserForm to unload it, then the userform is gone, but i don't see a way to make disappear the chart if I don't want to see it anymore. Maybe, that's the reason that it doesn't work.

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hi Hans,

    I was thinking about this EXCELE window , and think that it just an ordinary which is borderless Window (if you check the class name it is EXCELE with or without the window frame). If a user selects to view it as window, then the border is drawn but as soon as the window looses focus, that event resets the window properties, and that might be why it does not respond to your code as you might expect. All this is pure speculation, and I don't really know.

    Anyway, I will try your code, if for no other reason than it looks useful.

    Thanks

    Andrew

  8. #8
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Yes, I agree!
    Thanks for the code and the comments.

  9. #9
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Andrew,

    Actually, the code definitely works if you add a userform to the project and put in the following:
    <pre>Private Sub UserForm_Activate()
    Dim handle As Long
    handle = FindWindow("ThunderDFrame", UserForm1.Caption)
    Call set_on_top(handle, True)
    End Sub
    </pre>


    Then the userform stays on top, no matter what other application gets the focus. For sheets and charts or embedded charts, I don't think it works.

  10. #10
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hans,

    Thanks for that. I have incorporated your code into the Window Class Name viewer , and also adapted it show the wndow caption and handle (hWnd), as they might be useful in debugging. I am attaching the upgraded (?) project and maybe you can see if I implemented your code correctly. (I tried the Form Activate befor I saw your code, but don't think it worked, but I will try your actual code).

    Andrew
    Attached Files Attached Files

  11. #11
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Kortrijk, Belgium
    Posts
    571
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Andrew,

    If you just put the few lines of code in the userform activate event and change the Userform1.caption argument with the frmShowClass.Caption like below

    Private Sub UserForm_Activate()
    Dim handle As Long
    handle = FindWindow("ThunderDFrame", frmShowClass.Caption)
    Call set_on_top(handle, True)
    End Sub

    I added my Excel workbook with your code but so that the frmShowClass userform stays on top. This makes it a wonderful tool to move over other applications and find out the class names.
    Attached Files Attached Files

  12. #12
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hans,

    Thanks for that. I think the last version I posted operates the same, stays on top i.e, except I put the call to your set_on_top code in the the code itself, rather than the UserForm. I don't suppose it matters really.

    I'm trying to figure out it will behave if theer are 2 instances running at the same time, say one from Word and one from Excel. I suppose really if there are more than 1, then each should have a different caption. This is purely academic, as one instance is enough.

    Can you think of any other useful info it might report on ?

    Andrew

  13. #13
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hans,

    I just noticed that you left in the line Call set_on_top(FindWindow("ThunderDFrame", "Window Class Name"), True) in the main code, which with your userform event is redundant.

    Andrew

  14. #14
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hi all,

    Thanks for bringing me over to this Hans, still interested just ran out of time! Maybe I am doing this wrong, but the code below places the userform on top regardless of what the class name is.
    <pre>Private Sub UserForm_Activate()
    Dim handle As Long
    handle = FindWindow("XLMAIN", UserForm1.Caption)
    Call set_on_top(handle, True)
    End Sub
    </pre>


    I have used EXCELE, ThunderDFrame, etc with the same results

  15. #15
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Class names for Excel's windows

    Hans,

    As I suspected, the UserForm Activate does not kick in response to the updating of label captions, so it seems that unless a call to the set_on_top sub is made by the main code, it will not have any effect. Sorry about that, but it seems that changing content of a user form does not actually activate the form. However placing a call to your sub in the main body works fine.

    I have made a slight alteration that adds the application name to the userform caption, just in case you have a version running from Excel, and want to check the XL dialog box class names. You will need to run the code from an application other than xl, as when xl displays most of it's dialogs, macro execution freezes. This happens for Print Preview (EXCELB, by the way) etc.

    Latest SR attached
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Posting Permissions

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