Подсказка при наведении курсора - VB

Узнай цену своей работы

Формулировка задачи:

Подскажите, пожалуйста, как сделать так, чтобы подсказка, которая появляется при наведении курсора, отображалась не на всю ширину экрана, а миниатюрно,хотя бы в пределах формы?
Листинг программы
  1. Private Sub Form_Load()
  2. Label2.ToolTipText = "Данная программа производит заполнение матриц 7*7 случайными значениями,производит вычисление максимального, минимального элемента каждой матрицы,указывая соответственно его координаты, вычисляет общую сумму элементов каждой матрицы.Также имеется возможность обмена максимальных элементов местами."
  3. End Sub

Решение задачи: «Подсказка при наведении курсора»

textual
Листинг программы
  1. Option Explicit
  2.  
  3. 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
  4. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
  5. ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As _
  6. Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  7. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As _
  8. Any) As Long
  9. Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, _
  10. lpRect As RECT) As Long
  11. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  12.  
  13. Private Type RECT
  14.         Left As Long
  15.         Top As Long
  16.         Right As Long
  17.         Bottom As Long
  18. End Type
  19.  
  20. Private Type TOOLINFO
  21.     cbSize As Long
  22.     uFlags As Long
  23.     hwnd As Long
  24.     uid As Long
  25.     RECT As RECT
  26.     hinst As Long
  27.     lpszText As String
  28.     lParam As Long
  29. End Type
  30.  
  31. Private Const CW_USEDEFAULT = &H80000000
  32.  
  33. Private Const SWP_NOMOVE = &H2
  34. Private Const SWP_NOACTIVATE = &H10
  35. Private Const SWP_NOSIZE = &H1
  36. Private Const HWND_NOTOPMOST = -2
  37. Private Const HWND_TOP = 0
  38. Private Const HWND_TOPMOST = -1
  39. Private Const HWND_BOTTOM = 1
  40. Private Const WS_POPUP = &H80000000
  41. Private Const WS_EX_TOPMOST = &H8&
  42.  
  43. Private Const WM_USER = &H400
  44.  
  45. Private Const CP_ACP = 0
  46. Private Const CP_OEMCP = 1
  47.  
  48. Private Const WC_COMPOSITECHECK = &H200
  49. Private Const WC_DEFAULTCHAR = &H40
  50. Private Const WC_DEFAULTCHECK = &H100
  51. Private Const WC_DIALOG = 8002&
  52. Private Const WC_DISCARDNS = &H10
  53. Private Const WC_SEPCHARS = &H20
  54.  
  55. Private Const TTDT_AUTOMATIC = 0
  56. Private Const TTDT_AUTOPOP = 2
  57. Private Const TTDT_INITIAL = 3
  58. Private Const TTDT_RESHOW = 1
  59.  
  60. Private Const TTF_ABSOLUTE = &H80
  61. Private Const TTF_CENTERTIP = &H2
  62. Private Const TTF_DI_SETITEM = &H8000
  63. Private Const TTF_IDISHWND = &H1
  64. Private Const TTF_RTLREADING = &H4
  65. Private Const TTF_SUBCLASS = &H10
  66. Private Const TTF_TRACK = &H20
  67. Private Const TTF_TRANSPARENT = &H100
  68.  
  69. Private Const TTM_ACTIVATE = (WM_USER + 1)
  70. Private Const TTM_ADDTOOLA = (WM_USER + 4)
  71. Private Const TTM_ADDTOOLW = (WM_USER + 50)
  72. Private Const TTM_ADJUSTRECT = (WM_USER + 31)
  73. Private Const TTM_DELTOOLA = (WM_USER + 5)
  74. Private Const TTM_DELTOOLW = (WM_USER + 51)
  75. Private Const TTM_ENUMTOOLSA = (WM_USER + 14)
  76. Private Const TTM_ENUMTOOLSW = (WM_USER + 58)
  77. Private Const TTM_GETBUBBLESIZE = (WM_USER + 30)
  78. Private Const TTM_GETCURRENTTOOLA = (WM_USER + 15)
  79. Private Const TTM_GETCURRENTTOOLW = (WM_USER + 59)
  80. Private Const TTM_GETDELAYTIME = (WM_USER + 21)
  81. Private Const TTM_GETMARGIN = (WM_USER + 27)
  82. Private Const TTM_GETMAXTIPWIDTH = (WM_USER + 25)
  83. Private Const TTM_GETTEXTA = (WM_USER + 11)
  84. Private Const TTM_GETTEXTW = (WM_USER + 56)
  85. Private Const TTM_GETTIPBKCOLOR = (WM_USER + 22)
  86. Private Const TTM_GETTIPTEXTCOLOR = (WM_USER + 23)
  87. Private Const TTM_GETTOOLCOUNT = (WM_USER + 13)
  88. Private Const TTM_GETTOOLINFOA = (WM_USER + 8)
  89. Private Const TTM_GETTOOLINFOW = (WM_USER + 53)
  90. Private Const TTM_HITTESTA = (WM_USER + 10)
  91. Private Const TTM_HITTESTW = (WM_USER + 55)
  92. Private Const TTM_NEWTOOLRECTA = (WM_USER + 6)
  93. Private Const TTM_NEWTOOLRECTW = (WM_USER + 52)
  94. Private Const TTM_POP = (WM_USER + 28)
  95. Private Const TTM_RELAYEVENT = (WM_USER + 7)
  96. Private Const TTM_SETDELAYTIME = (WM_USER + 3)
  97. Private Const TTM_SETMARGIN = (WM_USER + 26)
  98. Private Const TTM_SETMAXTIPWIDTH = (WM_USER + 24)
  99. Private Const TTM_SETTIPBKCOLOR = (WM_USER + 19)
  100. Private Const TTM_SETTIPTEXTCOLOR = (WM_USER + 20)
  101. Private Const TTM_SETTITLEA = (WM_USER + 32)
  102. Private Const TTM_SETTITLEW = (WM_USER + 33)
  103. Private Const TTM_SETTOOLINFOA = (WM_USER + 9)
  104. Private Const TTM_SETTOOLINFOW = (WM_USER + 54)
  105. Private Const TTM_TRACKACTIVATE = (WM_USER + 17)
  106. Private Const TTM_TRACKPOSITION = (WM_USER + 18)
  107. Private Const TTM_UPDATE = (WM_USER + 29)
  108. Private Const TTM_UPDATETIPTEXTA = (WM_USER + 12)
  109. Private Const TTM_UPDATETIPTEXTW = (WM_USER + 57)
  110. Private Const TTM_WINDOWFROMPOINT = (WM_USER + 16)
  111.  
  112. Private Const TTS_ALWAYSTIP = &H1
  113. Private Const TTS_BALLOON = &H40
  114. Private Const TTS_NOANIMATE = &H10
  115. Private Const TTS_NOFADE = &H20
  116. Private Const TTS_NOPREFIX = &H2
  117.  
  118. Private Const TOOLTIPS_CLASS = "tooltips_class"
  119. Private Const TOOLTIPS_CLASSA = "tooltips_class32"
  120.  
  121. Dim hwndTT As Long
  122.  
  123. Private Sub Form_Load()
  124.  
  125.     Dim ti As TOOLINFO
  126.  
  127.     Dim uid As Long
  128.     uid = 0
  129.  
  130.     Dim strTT As String * 50
  131.     strTT = "Title"
  132.  
  133.     Dim strPntr As String
  134.     strPntr = "Это первая стока подсказки." & vbCrLf & "Это вторая строка." & vbCrLf & "Это третья строка! """
  135.  
  136.     Dim LPTSTR As String
  137.     LPTSTR = strPntr
  138.  
  139.     Dim RECT As RECT
  140.  
  141.     Dim RetVal As Long
  142.  
  143.     hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASSA, vbNullString, WS_POPUP Or TTS_NOPREFIX Or TTS_BALLOON, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, Me.hwnd, 0, App.hInstance, 0)
  144.  
  145.     SetWindowPos hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE
  146.  
  147.     GetClientRect Command1.hwnd, RECT
  148.    
  149.     ti.cbSize = Len(ti)
  150.     ti.uFlags = TTF_CENTERTIP Or TTF_SUBCLASS
  151.     ti.hwnd = Command1.hwnd
  152.     ti.hinst = App.hInstance
  153.     ti.uid = uid
  154.     ti.lpszText = LPTSTR
  155.     ti.RECT.Left = RECT.Left
  156.     ti.RECT.Top = RECT.Top
  157.     ti.RECT.Right = RECT.Right
  158.     ti.RECT.Bottom = RECT.Bottom
  159.  
  160.     SendMessage hwndTT, TTM_ADDTOOLA, 0, ti
  161.     SendMessage hwndTT, TTM_SETMAXTIPWIDTH, 0, 80
  162.     ti.lpszText = strPntr
  163.     SendMessage hwndTT, TTM_UPDATETIPTEXTA, 0, ti
  164.     SendMessage hwndTT, TTM_SETTIPBKCOLOR, RGB(255, 255, 255), 0
  165.     SendMessage hwndTT, TTM_SETTIPTEXTCOLOR, RGB(0, 0, 150), 0
  166.     SendMessage hwndTT, TTM_UPDATETIPTEXTA, 0, ti
  167.  
  168. End Sub
  169.  
  170. Private Sub Form_Unload(Cancel As Integer)
  171.     DestroyWindow hwndTT
  172.  
  173. End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.929 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы