home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / articles / vbbultn / source / tooltips.bas < prev    next >
Encoding:
BASIC Source File  |  1994-12-21  |  4.3 KB  |  123 lines

  1. Option Explicit
  2. Type POINTAPI
  3.     x As Integer
  4.     y As Integer
  5. End Type
  6.  
  7. Global Const SW_SHOWNOACTIVATE = 4
  8. Global Const SEPARATOR = "/"
  9. Global Const GWW_HWNDPARENT = -8
  10.  
  11. Declare Function dwGetPropertyValue Lib "dwspydll.dll" (ByVal hctl&, ByVal propname$, iresptr%) As Variant
  12. Declare Function dwGetControlHwnd% Lib "dwspydll.dll" (hctl As Control)
  13. Declare Function dwGetControlHwndByID% Lib "dwspydll.dll" Alias "dwGetControlHwnd" (ByVal hctl&)
  14. Declare Sub GetCursorPos Lib "user" (lppoint As POINTAPI)
  15. Declare Function ShowWindow Lib "user" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  16. Declare Function GetActiveWindow% Lib "user" ()
  17.  
  18. Function ParseString (stringtoparse As String, subindex As Integer) As String
  19. 'assumes format of string being parsed is correct (a separator
  20. 'separates each substring), first substring at index 0
  21. Dim start%, offset%, substringcount%
  22.  
  23.     start% = 1
  24.     offset% = InStr(start%, stringtoparse, SEPARATOR)
  25.     
  26.     Do While (substringcount% < subindex)
  27.         start% = offset% + 1
  28.         substringcount% = substringcount% + 1
  29.         offset% = InStr(start%, stringtoparse, SEPARATOR)
  30.     Loop
  31.     
  32.     ParseString = Mid$(stringtoparse, start%, offset% - start%)
  33. End Function
  34.  
  35. Sub ShowToolTip (ByVal hctl&)
  36. Dim ctlhwnd%, res%
  37. Dim tagstring$, tipstring$
  38. Dim tippoint As POINTAPI
  39. Dim toffset%, loffset%, iresptr%
  40. Static changecolor%
  41.  
  42.     'get control hwnd and display tooltip for appropriate control
  43.     If hctl& Then
  44.         'gets Tag property and parses it, using the first substring
  45.         'for the status bar help
  46.         tagstring$ = dwGetPropertyValue(hctl&, "Tag", iresptr%)
  47.  
  48.         If (iresptr% = 0) And (Len(tagstring$) > 0) Then
  49.             tipstring$ = ParseString(tagstring$, 1)
  50.         End If
  51.     Else
  52.         ToolTipForm.Hide
  53.         'reset back to the normal tooltip appearance
  54.         If changecolor Then
  55.             ToolTipForm.BackColor = &H80FFFF
  56.             ToolTipForm!ToolTipLab.BackColor = &H80FFFF
  57.             ToolTipForm!ToolTipLab.ForeColor = 0
  58.             changecolor = False
  59.         End If
  60.     End If
  61.  
  62.     If tipstring$ <> "" Then
  63.         'the tooltip form is always loaded
  64.         ToolTipForm.ToolTipLab.Caption = tipstring$
  65.         'calculate position of the form
  66.         GetCursorPos tippoint
  67.         toffset% = 18: loffset% = -2    'offsets to cursor
  68.         ToolTipForm.Top = (tippoint.y + toffset%) * Screen.TwipsPerPixelY
  69.         ToolTipForm.Left = (tippoint.x + loffset%) * Screen.TwipsPerPixelX
  70.         ToolTipForm.Width = ToolTipForm.ToolTipLab.Width + (4 * Screen.TwipsPerPixelX)
  71.         ToolTipForm.Height = ToolTipForm.ToolTipLab.Height + (2 * Screen.TwipsPerPixelY)
  72.         ToolTipForm.ZOrder  'place on top of zorder
  73.  
  74.         'Under certain conditions, we can change the
  75.         'ToolTip appearance
  76.         tipstring$ = UCase$(ParseString(tagstring$, 2))
  77.         If tipstring$ = "WARNING" Then
  78.             'display different background and foreground colors
  79.             ToolTipForm.BackColor = &HFF
  80.             ToolTipForm!ToolTipLab.BackColor = &HFF
  81.             ToolTipForm!ToolTipLab.ForeColor = &HFFFFFF
  82.             changecolor = True
  83.         End If
  84.  
  85.         'do not activate the tooltip form after displaying it
  86.         res% = ShowWindow(ToolTipForm.hWnd, SW_SHOWNOACTIVATE)
  87.     Else
  88.         ToolTipForm.Hide
  89.         'reset back to the normal tooltip appearance
  90.         If changecolor Then
  91.             ToolTipForm.BackColor = &H80FFFF
  92.             ToolTipForm!ToolTipLab.BackColor = &H80FFFF
  93.             ToolTipForm!ToolTipLab.ForeColor = 0
  94.             changecolor = False
  95.         End If
  96.     End If
  97. End Sub
  98.  
  99. Sub UpdateStatusBar (ByVal hctl&, statusbar As Control)
  100. 'Gets the status help text from the control's tag property,
  101. 'also assume statusbar is a label control
  102. Dim statusstring$
  103. Dim iresptr%
  104.  
  105.     If hctl& = 0 Then   'clear status bar
  106.         statusbar.Caption = ""
  107.         Exit Sub
  108.     End If
  109.  
  110.     'gets Tag property and parses it, using the first substring
  111.     'for the status bar help
  112.     statusstring$ = dwGetPropertyValue(hctl&, "Tag", iresptr%)
  113.  
  114.     If (iresptr% = 0) And (Len(statusstring$) > 0) Then
  115.         'get first substring
  116.         statusstring$ = ParseString(statusstring$, 0)
  117.         statusbar.Caption = statusstring$
  118.     Else
  119.         statusbar.Caption = ""
  120.     End If
  121. End Sub
  122.  
  123.