Macaubal
não registrado
|
|
ENUNCIADA !
|
|
|
Postada em 06/03/2008 11:00 hs
Alguem sabe como deixar o ToolTipText do VB6 igual do WinXP?
|
|
|
|
Treze
|
SÃO VICENTE SP - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 06/03/2008 11:25 hs
Crie um projecto Standard Adicione uma class e de-lhe o nome de CBalloonToolTip Adicione 2 textbox e um command button ao form1
Coloque o seguinte codigo no form1: --------------------------------------------------------------------------------------------------- Dim TT1 As New CBalloonToolTip '//Demo for On Demand tooltip Dim TT2 As New CBalloonToolTip '//Demo for mouse over tooltip
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Function CapsLockOn() As Boolean Dim iKeyState As Integer iKeyState = GetKeyState(vbKeyCapital) CapsLockOn = (iKeyState = 1 Or iKeyState = -127) End Function
Private Sub Command1_Click() If Text1.Text <> "mypassword" Then TT1.Style = TTBalloon TT1.Icon = TTIconError TT1.Title = IIf(Text1.Text = "", "Blank Password", "Invalid Password") TT1.TipText = "Please Enter Correct Password..." TT1.PopupOnDemand = True TT1.CreateToolTip Text1.hwnd TT1.Show 0, Text1.Height / Screen.TwipsPerPixelX - 1 '//In Pixel only End If End Sub
Private Sub Form_Load() TT2.Style = TTBalloon TT2.Icon = TTIconInfo TT2.Title = "Information" TT2.TipText = "A little cute tooltip for Textbox2" TT2.PopupOnDemand = False TT2.ForeColor = vbWhite TT2.BackColor = &HCE7110 TT2.VisibleTime = 6000 'After 6 Seconds tooltip will go away TT2.CreateToolTip Text2.hwnd End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) TT1.Destroy End Sub
Private Sub Form_Paint() TT1.Destroy End Sub
Private Sub Form_Resize() TT1.Destroy End Sub Private Sub Form_Unload(Cancel As Integer) TT1.Destroy TT2.Destroy End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If CapsLockOn Then TT1.Style = TTBalloon TT1.Icon = TTIconWarning TT1.Title = "Caps Lock is on" TT1.TipText = "Check your caps lock key..." TT1.CreateToolTip Text1.hwnd TT1.Show 0, Text1.Height / Screen.TwipsPerPixelX - 1 Else TT1.Destroy End If End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) TT1.Destroy End Sub ---------------------------------------------------------------------------------------------------
coloque o seguinte codigo na class: --------------------------------------------------------------------------------------------------- Option Explicit
Private Declare Sub InitCommonControls Lib "comctl32.dll" ()
''Windows API Functions Private Declare Function CreateWindowEx Lib "user32.dll" 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, _ ByRef lpParam As Any) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByRef lParam As Any) As Long
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long
Private Declare Function DestroyWindow Lib "user32" ( _ ByVal hwnd As Long) As Long
Private Declare Function ClientToScreen Lib "user32" ( _ ByVal hwnd As Long, _ lpPoint As POINTAPI) As Long
''Windows API Constants Private Const WM_USER = &H400 Private Const CW_USEDEFAULT = &H80000000
''Windows API Types Private Type RECT left As Long top As Long right As Long bottom As Long End Type
Private Type POINTAPI X As Long Y As Long End Type
'Tooltip Window Constants Private Const TTS_NOPREFIX = &H2 Private Const TTF_TRANSPARENT = &H100 Private Const TTF_CENTERTIP = &H2 Private Const TTM_ADDTOOLA = (WM_USER + 4) Private Const TTM_ACTIVATE = WM_USER + 1 Private Const TTM_UPDATETIPTEXTA = (WM_USER + 12) Private Const TTM_SETMAXTIPWIDTH = (WM_USER + 24) Private Const TTM_SETTIPBKCOLOR = (WM_USER + 19) Private Const TTM_SETTIPTEXTCOLOR = (WM_USER + 20) Private Const TTM_SETTITLE = (WM_USER + 32) Private Const TTS_BALLOON = &H40 Private Const TTS_ALWAYSTIP = &H1 Private Const TTF_SUBCLASS = &H10 Private Const TTF_TRACK = &H20 Private Const TTF_IDISHWND = &H1 Private Const TTM_SETDELAYTIME = (WM_USER + 3) Private Const TTDT_AUTOPOP = 2 Private Const TTDT_INITIAL = 3 Private Const TTM_TRACKACTIVATE = WM_USER + 17 Private Const TTM_TRACKPOSITION = WM_USER + 18 Private Const WS_POPUP = &H80000000
Private Const TOOLTIPS_CLASSA = "tooltips_class32"
''Tooltip Window Types Private Type TOOLINFO lSize As Long lFlags As Long hwnd As Long lId As Long lpRect As RECT hInstance As Long lpStr As String lParam As Long End Type
Public Enum ttIconType TTNoIcon = 0 TTIconInfo = 1 TTIconWarning = 2 TTIconError = 3 End Enum
Public Enum ttStyleEnum TTStandard TTBalloon End Enum
'local variable(s) to hold property value(s) Private mvarBackColor As Long Private mvarTitle As String Private mvarForeColor As Long Private mvarIcon As ttIconType Private mvarCentered As Boolean Private mvarStyle As ttStyleEnum Private mvarTipText As String Private mvarVisibleTime As Long Private mvarDelayTime As Long Private mvarPopupOnDemand As Boolean
'private data Private m_lTTHwnd As Long ' hwnd of the tooltip Private m_lParentHwnd As Long ' hwnd of the window the tooltip attached to Private ti As TOOLINFO
Private Sub Class_Initialize() InitCommonControls mvarDelayTime = 500 mvarVisibleTime = 5000 mvarPopupOnDemand = False End Sub Private Sub Class_Terminate() Destroy End Sub '////////////////////////////////////////////////////// Public Property Get VisibleTime() As Long VisibleTime = mvarVisibleTime End Property Public Property Let VisibleTime(ByVal lData As Long) mvarVisibleTime = lData End Property '////////////////////////////////////////////////////// Public Property Get DelayTime() As Long DelayTime = mvarDelayTime End Property Public Property Let DelayTime(ByVal lData As Long) mvarDelayTime = lData End Property '////////////////////////////////////////////////////// Public Property Let Icon(ByVal vData As ttIconType) mvarIcon = vData If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle End If End Property Public Property Get Icon() As ttIconType Icon = mvarIcon End Property '////////////////////////////////////////////////////// Public Property Let ForeColor(ByVal vData As Long) mvarForeColor = vData If m_lTTHwnd <> 0 Then SendMessage m_lTTHwnd, TTM_SETTIPTEXTCOLOR, mvarForeColor, 0& End If End Property Public Property Get ForeColor() As Long ForeColor = mvarForeColor End Property '////////////////////////////////////////////////////// Public Property Let Title(ByVal vData As String) mvarTitle = vData If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle End If End Property Public Property Get Title() As String Title = ti.lpStr End Property '////////////////////////////////////////////////////// Public Property Let PopupOnDemand(ByVal vData As Boolean) mvarPopupOnDemand = vData 'If m_lTTHwnd <> 0 Then 'End If End Property Public Property Get PopupOnDemand() As Boolean PopupOnDemand = mvarPopupOnDemand End Property '////////////////////////////////////////////////////// Public Property Let BackColor(ByVal vData As Long) mvarBackColor = vData If m_lTTHwnd <> 0 Then SendMessage m_lTTHwnd, TTM_SETTIPBKCOLOR, mvarBackColor, 0& End If End Property Public Property Get BackColor() As Long BackColor = mvarBackColor End Property '////////////////////////////////////////////////////// Public Property Let TipText(ByVal vData As String) mvarTipText = vData ti.lpStr = vData If m_lTTHwnd <> 0 Then SendMessage m_lTTHwnd, TTM_UPDATETIPTEXTA, 0&, ti End If End Property Public Property Get TipText() As String TipText = mvarTipText End Property '////////////////////////////////////////////////////// Public Property Let Style(ByVal vData As ttStyleEnum) mvarStyle = vData End Property Public Property Get Style() As ttStyleEnum Style = mvarStyle End Property '////////////////////////////////////////////////////// Public Property Let Centered(ByVal vData As Boolean) mvarCentered = vData End Property Public Property Get Centered() As Boolean Centered = mvarCentered End Property
'X and Y are in Pixel so dont send vbTwips value Public Sub Show(Optional X As Long = 0, Optional Y As Long = 0)
Dim pt As POINTAPI Dim ptTip As Long Dim ret As Long
With pt .X = X .Y = Y End With
ret = ClientToScreen(Form1.Text1.hwnd, pt)
ptTip = pt.Y * &H10000 ptTip = ptTip + pt.X
' These two messages will set the position of the tooltip: ret = SendMessage(m_lTTHwnd, TTM_TRACKPOSITION, 0, ByVal ptTip) ret = SendMessage(m_lTTHwnd, TTM_TRACKACTIVATE, True, ti)
End Sub Public Function CreateToolTip(ByVal ParentHwnd As Long) As Boolean Dim lWinStyle As Long If m_lTTHwnd <> 0 Then DestroyWindow m_lTTHwnd End If m_lParentHwnd = ParentHwnd
''create baloon style if desired If mvarStyle = TTBalloon Then lWinStyle = lWinStyle Or TTS_BALLOON
m_lTTHwnd = CreateWindowEx(0&, _ TOOLTIPS_CLASSA, _ vbNullString, _ lWinStyle, _ 0&, _ 0&, _ 0&, _ 0&, _ m_lParentHwnd, _ 0&, _ 0&, _ 0&)
''now set our tooltip info structure With ti '//dont incude TTF_SUBCLASS for on demand ''if we want it centered, then set that flag If mvarCentered Then If mvarPopupOnDemand = False Then .lFlags = TTF_SUBCLASS Or TTF_CENTERTIP Or TTF_IDISHWND Else .lFlags = TTF_IDISHWND Or TTF_TRACK Or TTF_CENTERTIP End If Else If mvarPopupOnDemand = False Then .lFlags = TTF_SUBCLASS Or TTF_IDISHWND Else .lFlags = TTF_IDISHWND Or TTF_TRACK Or TTF_TRANSPARENT End If End If
'set the hwnd prop to our parent control's hwnd .hwnd = m_lParentHwnd .lId = m_lParentHwnd '0 .hInstance = App.hInstance '.lpstr = ALREADY SET '.lpRect = lpRect .lSize = Len(ti) End With
''add the tooltip structure SendMessage m_lTTHwnd, TTM_ADDTOOLA, 0&, ti
''if we want a title or we want an icon If mvarTitle <> vbNullString Or mvarIcon <> TTNoIcon Then SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle End If
If mvarForeColor <> Empty Then SendMessage m_lTTHwnd, TTM_SETTIPTEXTCOLOR, mvarForeColor, 0& End If
If mvarBackColor <> Empty Then SendMessage m_lTTHwnd, TTM_SETTIPBKCOLOR, mvarBackColor, 0& End If
SendMessageLong m_lTTHwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, mvarVisibleTime SendMessageLong m_lTTHwnd, TTM_SETDELAYTIME, TTDT_INITIAL, mvarDelayTime
End Function
Public Sub Destroy() If m_lTTHwnd <> 0 Then DestroyWindow m_lTTHwnd End If End Sub
|
|
|
Macaubal
não registrado
|
|
ENUNCIADA !
|
|
|
Postada em 06/03/2008 11:46 hs
Treze ficou bacana, não era bem isso o que estava esperando mas vou tentar adaptar ao sistema. Nao sei se entendeu o que eu quiz dizer, mas eu estava tentando deixar o ToolTipText de maneira que eu consiga escrever em várias linhas, igual do WinXP, mas enquanto nao encontro vou me virando por aqui Obrigado
|
|
|
Treze
|
SÃO VICENTE SP - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 06/03/2008 13:04 hs
Macaubal veja este código que desenvolvi para teste primeiro inseri um label em meu form e um textbox nomei o label de ToolTip e fiz o seguinte codigo Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Sub Form_Load() SetCapture Me.hwnd With ToolTip .Appearance = 0 .AutoSize = True .BackColor = &HC0FFFF .BorderStyle = 1 .Visible = False End With End Sub Private Sub Command1_Click() ReleaseCapture End Sub Private Sub Form_MouseMove(Button As Integer, Shift _ As Integer, X As Single, Y As Single) If Y > Text1.Top And Y < (Text1.Top + Text1.Height) And X > Text1.Left And X < (Text1.Left + Text1.Width) Then ToolTip.Visible = True ToolTip.Top = Text1.Top + Text1.Height + 50 ToolTip.Left = Text1.Left ToolTip.Caption = "LINHA 1" ToolTip.Caption = ToolTip.Caption & Chr(13) + Chr(10) & "LINHA 2" ToolTip.Caption = ToolTip.Caption & Chr(13) + Chr(10) & "LINHA 3" ToolTip.Caption = ToolTip.Caption & Chr(13) + Chr(10) & "LINHA 4" ToolTip.Caption = ToolTip.Caption & Chr(13) + Chr(10) & "LINHA 5" ToolTip.Caption = ToolTip.Caption & Chr(13) + Chr(10) & "LINHA 6" Else ToolTip.Visible = False End If End Sub o código & Chr(13) + Chr(10) & quebra alinha do label em paragrafos
teste faça suas adptações e veja se serve valeu até
|
|
|
Macaubal
não registrado
|
|
ENUNCIADA !
|
|
|
Postada em 06/03/2008 17:10 hs
Treze era isso mesmo que eu estava precisando
Pode acrescentar esse tópico nas novas dicas
Ficou muito bom...
Valew
|
|
|
Treze
|
SÃO VICENTE SP - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 07/03/2008 12:24 hs
Macaubal, fiz uma lteração par utilizr o mesmo com uma picture ficou um pouco melhor pois fica sobre todos os outro objetos, se te interessar envio a alteração. abraço até
|
|
|
|