Tipp 0316 Mehrzeiliger ToolTipp-Text
Autor/Einsender:
Datum:
  Ralph Steinkönig
01.03.2003
Entwicklungsumgebung:   VB 6
Das folgende Beispiel zeigt, wie es mit relativ wenig Code und mit Hilfe einiger API-Funktionen möglich ist, mehrzeilige ToolTipps zu erstellten.
 
Option Explicit

Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Type TOOLINFO
  cbSize As Long
  uFlags As Long
  hwnd As Long
  uId As Long
  cRect As RECT
  hinst As Long
  lpszText As String
End Type

Private Declare Function CreateWindowEx Lib "user32" Alias _
      "CreateWindowExA" (ByVal dwExStyle As Long, _
      ByVal lpClassName As String, ByVal lpWindowName As String, _
      ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, _
      ByVal nWidth As Long, ByVal nHeight As Long, _
      ByVal hWndParent As Long, ByVal hMenu As Long, _
      ByVal hInstance As Long, lpParam As Any) As Long

Private Declare Function DestroyWindow Lib "user32" _
      (ByVal hwnd As Long) As Long

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Declare Function SendMessage Lib "user32.dll" Alias _
      "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
      ByVal wParam As Long, lParam As Any) As Long

Private Const WM_USER = &H400
Private Const TTM_ADDTOOL = WM_USER + 4
Private Const TTM_SETMAXTIPWIDTH = WM_USER + 24
Private Const TTF_IDISHWND = &H1
Private Const TTF_SUBCLASS = &H10

Private hToolTip As Long

Private Sub Form_Load()
  InitCommonControls

  hToolTip = CreateWindowEx( _
        0, "tooltips_class32", "", 0, 0, 0, 0, 0, 0, 0, 0, 0)

  SendMessage hToolTip, TTM_SETMAXTIPWIDTH, 0, 300

  SetMultiLineToolTip Command1.hwnd, _
                  "Das ist ein" & vbNewLine & "Test !"
  SetMultiLineToolTip Command2.hwnd, "Bei Klick auf diesen" & _
                  vbNewLine & "Button wird das" & vbNewLine & _
                  "Programm beendet ;-)"
End Sub

Private Sub Command1_Click()
  SetMultiLineToolTip Text1.hwnd, Text1.Text
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, _
      UnloadMode As Integer)
  DestroyWindow hToolTip
End Sub

Private Sub SetMultiLineToolTip(ByVal hwnd As Long, _
      ByVal sToolTip As String)

  Dim udtTool As TOOLINFO

  With udtTool
    .cbSize = Len(udtTool)
    .hwnd = hwnd
    .uFlags = TTF_IDISHWND Or TTF_SUBCLASS
    .uId = hwnd
    .lpszText = sToolTip
  End With
  SendMessage hToolTip, TTM_ADDTOOL, 0, udtTool
End Sub
 
Weitere Links zum Thema
Längere Einträge als ToolTipText anzeigen

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (3,3 kB) Downloads bisher: [ 1486 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Sonntag, 21. August 2011