dcsimg
Results 1 to 20 of 20

Thread: [RESOLVED] multi tooltip Class dont work with VBA

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Resolved [RESOLVED] multi tooltip Class dont work with VBA

    i use the VB6 class CToolTip.
    In vb 6 the code work perfect... instead in VBA have error in: TT.Create Me.hwnd

    my VBA code:
    Code:
    Option Explicit
    Dim TT As CTooltip
    Dim m_bInLable As Boolean
    
    Private Sub Form_Load()
       Set TT = New CTooltip
       TT.Style = TTBalloon
       TT.Icon = TTIconInfo
    End Sub
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
       If m_bInLable Then
          m_bInLable = False
          TT.Destroy
       End If
    End Sub
    Private Sub Label151_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
       If Not m_bInLable Then
          m_bInLable = True
          TT.Title = "Multiline tooltip"
          TT.TipText = "Label151"
          TT.Create Me.hwnd
       End If
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: multi tooltip Class dont work with VBA

    try using 0 instead, else you need to get the hwnd of the application window using application.hwnd or windows API depending on excel version
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by westconn1 View Post
    try using 0 instead, else you need to get the hwnd of the application window using application.hwnd or windows API depending on excel version
    Ok
    But 0 wehere?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: multi tooltip Class dont work with VBA

    Code:
    TT.Create 0
    forms (Me) in vba do not have an hwnd, that is the error
    if 0 does not work you have to find the hwnd of the excel application
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: multi tooltip Class dont work with VBA

    Pete,

    or use FindWindow on his UserForm. This definitely returns the hWnd for the UserForm
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: multi tooltip Class dont work with VBA

    This definitely returns the hWnd for the UserForm
    i have previously spent time drilling down in spyxx, but never found individual hwnd for user forms, so i must have been doing something wrong

    you might post some code to help him?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: multi tooltip Class dont work with VBA

    Pete,

    you might remember this thread: http://www.vbforums.com/showthread.p...Box&highlight=

    There i state, that FindWindow for UserForm returns a valid handle.

    Do we really have to pull out some code for this, when there are tons a examples on the Internet?
    http://optionexplicitvba.blogspot.co...e-on-hwnd.html
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by Zvoni View Post
    Pete,

    you might remember this thread: http://www.vbforums.com/showthread.p...Box&highlight=

    There i state, that FindWindow for UserForm returns a valid handle.

    Do we really have to pull out some code for this, when there are tons a examples on the Internet?
    http://optionexplicitvba.blogspot.co...e-on-hwnd.html
    TKS to the all... bt sure not for me:-(

    Attached the VB 6 version... can you arrange the code for a Userform and label in VBA for Excel?
    Tks.
    Attached Files Attached Files

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: multi tooltip Class dont work with VBA

    Code:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Dim TT As CTooltip
    Dim m_bInLable As Boolean
    Dim MyhWnd As Long
    
    Private Sub UserForm_Activate()
      Set TT = New CTooltip
       TT.Style = TTBalloon
       TT.Icon = TTIconInfo  
       MyhWnd = FindWindow("ThunderDFrame", me.caption)
    End Sub
    
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
       If m_bInLable Then
          m_bInLable = False
          TT.Destroy
       End If
    End Sub
    Private Sub Label151_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
       If Not m_bInLable Then
          m_bInLable = True
          TT.Title = "Multiline tooltip"
          TT.TipText = "Label151"
          TT.Create MyhWnd
       End If
    End Sub
    AIRCODE!
    Not tested
    Last edited by Zvoni; Sep 17th, 2018 at 06:27 AM.
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by Zvoni View Post
    Code:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Dim TT As CTooltip
    Dim m_bInLable As Boolean
    Dim MyhWnd As Long
    
    Private Sub UserForm_Activate()
      Set TT = New CTooltip
       TT.Style = TTBalloon
       TT.Icon = TTIconInfo  
       MyhWnd = FindWindow("ThunderDFrame", me.caption)
    End Sub
    
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
       If m_bInLable Then
          m_bInLable = False
          TT.Destroy
       End If
    End Sub
    Private Sub Label151_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
       If Not m_bInLable Then
          m_bInLable = True
          TT.Title = "Multiline tooltip"
          TT.TipText = "Label151"
          TT.Create MyhWnd
       End If
    End Sub
    AIRCODE!
    Not tested
    no effect....
    Attached my Wbook for Test
    Attached Files Attached Files

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: multi tooltip Class dont work with VBA

    for this to work you need to find the hwnd of the form child
    on testing it seems to be 2 less than that of the thunderframe, no guarantees on that, but it worked for multiple tests on my machine,
    myhwnd = myhwnd -2

    i am sure there is a findchildwindow API (only the one child window to find) that would be more appropriate, no time now

    anyway the tooltip will work in excel userform, with a bit of trial and error
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: multi tooltip Class dont work with VBA

    Or you leave out "ThunderDFrame" out of the API-Call, and just pass the Caption of the UserForm to the API with vbNullString for the Class.
    For finding ChildWindows you need FindWindowEx, but i'd be careful with that one in VBA, since contrary to vb6 there are many controls, that definitely don't have a hWnd (see my mentioned post above)
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: multi tooltip Class dont work with VBA

    Proof positive that it works
    Attached Files Attached Files
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by Zvoni View Post
    Proof positive that it works
    TKS!
    but in my attached file have a workbook with a class.
    now i need to show multitool tip in label1... possible?

    in post #8 the vb6 version and on post #10 the workbook with my test

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: multi tooltip Class dont work with VBA

    i changed zvoni's code in your workbook very slightly and the tooltip works

    add to module
    Code:
    Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long
    change
    Code:
    Private Sub UserForm_Activate()
    Dim ret As Long
    ret = FindWindow("ThunderDFrame", Me.Caption)
    MyhWnd = FindWindowEx(ret, ByVal 0&, vbNullString, vbNullString)
    Set TT = New cToolTip
       TT.Style = TTBalloon
       TT.Icon = TTIconInfo
       
    End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by westconn1 View Post
    i changed zvoni's code in your workbook very slightly and the tooltip works

    add to module
    Code:
    Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long
    change
    Code:
    Private Sub UserForm_Activate()
    Dim ret As Long
    ret = FindWindow("ThunderDFrame", Me.Caption)
    MyhWnd = FindWindowEx(ret, ByVal 0&, vbNullString, vbNullString)
    Set TT = New cToolTip
       TT.Style = TTBalloon
       TT.Icon = TTIconInfo
       
    End Sub
    EXCELLENT!
    tks Zvoni & westconn1... for patience and for code.
    Now all is ok.!... Pizza from Napoli?
    Last edited by luca90; Sep 19th, 2018 at 02:09 AM.

  17. #17
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by luca90 View Post
    EXCELLENT!
    tks Zvoni & westconn1... for patience and for code.
    Now all is ok.!... Pizza from Napoli?
    I'm more partial to Spaghetti Bolognese!
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: multi tooltip Class dont work with VBA

    Quote Originally Posted by Zvoni View Post
    I'm more partial to Spaghetti Bolognese!
    Very good!
    But i think all italian food is eccellent or not?
    :-)
    Last edited by luca90; Sep 19th, 2018 at 10:00 AM.

  19. #19
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,435

    Re: [RESOLVED] multi tooltip Class dont work with VBA

    Yep!
    I adore Pasta fagioli...
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,743

    Re: [RESOLVED] multi tooltip Class dont work with VBA

    Quote Originally Posted by Zvoni View Post
    Yep!
    I adore Pasta fagioli...
    me too i love Pasta fagioli, but wih Provola and cozze, is a dream!!!
    COME IN ITALY, NAPLES ... MY HOME IS YOUR HOME!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width