Jump to content

ToolTip set style - (Moved)


Anatoly
 Share

Recommended Posts

Hello. I'm looking for a way to set the background color, text color, size font in ToolTip.

Json.au3

Spoiler
Quote


#include "Json.au3" ; (by @AspirinJunkie)
#include <Misc.au3>

Global $sRead1 = ""
Global $sRead_mem = ""

; ------------ Function : ---------------
Func _GoogleAPITranslate($sMytext, $sFrom, $sTo)
    Local $sUrl, $oHTTP, $sResponse, $JSONData, $sOutput = "", $aData
    $sUrl  = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & $sMytext
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("POST", $sUrl, False)
    $oHTTP.Send()
    $sResponse = $oHTTP.ResponseText
    $JSONData = _JSON_Parse($sResponse)
    If VarGetType($JSONData) = 'Array' Then
        $aData = $JSONData[0]
        If VarGetType($aData) = 'Array' Then
            For $i = 0 To UBound($aData) -1 Step 1
                $sOutput &= ($aData[$i])[0] ;*** & @CRLF
            Next
        EndIf
    EndIf
    Return $sOutput
 EndFunc  ;==>_GoogleAPITranslate

 While 1
   Sleep(200)
   ToolTip("")
   ConsoleWrite(5)

   While _IsPressed("11")
      ConsoleWrite("C")
      Sleep(200)
   WEnd

   While _IsPressed("01")

      Send("^c")
      $sRead_mem = ClipGet()
      Sleep(200)

      if $sRead1==$sRead_mem Then
         Sleep(100)
         ConsoleWrite("Ш")
      Else
         ConsoleWrite(0)
         $sRead1 = ClipGet()
         ToolTip(_GoogleAPITranslate($sRead1, "en", "ru"), Default, Default, "", 0, 1)
         Sleep(200)
      EndIf

   WEnd


WEnd

 

 

Link to comment
Share on other sites

  • Developers

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

43 minutes ago, Anatoly said:

I'm looking for a way to set the background color, text color, size font in ToolTip.

Then you might want to take a look at the help ;):

_GUIToolTip_SetTipTextColor , _GUIToolTip_SetTipBkColor

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

You do not need to create a GUI :

#include <GUIToolTip.au3>
#include <WinAPITheme.au3>

HotKeySet("{ESC}", _Exit)

Example()

Func Example()
  ToolTip("Tooltip Test", 300, 300)
  Local $hWnd = WinWait("Tooltip Test")
  ConsoleWrite ($hWnd & @CRLF)
  _WinAPI_SetWindowTheme($hWnd, "0", "0")
  _GUIToolTip_SetTipTextColor($hWnd, 0xFF)
  _GUIToolTip_SetTipBkColor($hWnd,0xFF0000)
  While Sleep(100)
  WEnd
EndFunc   ;==>Example

Func _Exit()
  Exit
EndFunc

Remember that color are expressed in COLORREF (BGR)

Link to comment
Share on other sites

#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include "Json.au3" ; (by @AspirinJunkie)
#include <Misc.au3>


Global $sRead1 = ""
Global $sRead_mem = ""


; ------------ Function : ---------------
Func _GoogleAPITranslate($sMytext, $sFrom, $sTo)
    Local $sUrl, $oHTTP, $sResponse, $JSONData, $sOutput = "", $aData
    $sUrl  = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & $sMytext
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("POST", $sUrl, False)
    $oHTTP.Send()
    $sResponse = $oHTTP.ResponseText
    $JSONData = _JSON_Parse($sResponse)
    If VarGetType($JSONData) = 'Array' Then
        $aData = $JSONData[0]
        If VarGetType($aData) = 'Array' Then
            For $i = 0 To UBound($aData) -1 Step 1
                $sOutput &= ($aData[$i])[0] ;*** & @CRLF
            Next
        EndIf
    EndIf
    Return $sOutput
 EndFunc  ;==>_GoogleAPITranslate


Func Prepare_text($clip_get='')

   $v = StringLeft($clip_get, 1000)
   $v = StringRegExpReplace($v, '([^a-zA-Z]+)', ' ')
   If $v==' ' Then $v = ''
   return $v

 EndFunc


Func Tool_tip_draw($v='')

   ToolTip($v, Default, Default, Default, 0, 1)
  _WinAPI_SetWindowTheme(WinGetHandle($v), "0", "0")
  _GUIToolTip_SetTipTextColor(WinGetHandle($v), 0xFFFFFF)
  _GUIToolTip_SetTipBkColor(WinGetHandle($v),0x000000)
  _GUIToolTip_SetMaxTipWidth(WinGetHandle($v), 500)

 EndFunc


Func mouse_event()

   Do
      $x_mouse_pos = MouseGetPos(0)
      $y_mouse_pos = MouseGetPos(1)
      Sleep(350)
      Until Abs($x_mouse_pos-MouseGetPos(0)) < 2 and Abs($y_mouse_pos-MouseGetPos(1)) < 2
      Return True

 EndFunc


While 1

   $trans = 0
   $trans_text = ""
   Sleep(50)

   While _IsPressed('11')
      ToolTip("")
      ConsoleWrite(@CRLF)
      Sleep(100)
    WEnd

   While _IsPressed('01') and mouse_event()

      Sleep(100)
      Send("^{INSERT}")
      $time = TimerInit()

      While _IsPressed('01')
;~       ConsoleWrite(Int(StringLen(Prepare_text(ClipGet()))))
         If $trans == 0 and Int(StringLen(Prepare_text(ClipGet()))) > 1 Then
            Beep(700, 40)
            ConsoleWrite('G')
            $trans_text = _GoogleAPITranslate(Prepare_text(ClipGet()), "en", "ru")
            $time = TimerInit()
            $trans = 1
            EndIf

         Tool_tip_draw($trans_text)
         Sleep(50)
      WEnd

      Sleep(50)
   WEnd

   ToolTip('')
   Sleep(50)
WEnd

Json.au3

Here is my idea. I would like to increase the font size in ToolTip. Thank you all

 

Link to comment
Share on other sites

I did not find a way to modify font with built-in tooltip but I made it work witn UDF :

#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include <SendMessage.au3>
#include <WinAPIGdiDC.au3>
#include <FontConstants.au3>
#include <WindowsConstants.au3>

Global $bShow = True

HotKeySet("{ESC}", _Exit)

Local $hToolTip = _GUIToolTip_Create(0)
Local $hDC = _WinAPI_GetDC(0)
_WinAPI_SetWindowTheme($hToolTip, "0", "0")
_GUIToolTip_SetTipTextColor($hToolTip, 0xFF)
_GUIToolTip_SetTipBkColor($hToolTip,0xFF0000)

Local $hFont = _WinAPI_CreateFont(32, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Tahoma')
_WinAPI_SelectObject($hDC, $hFont)
_SendMessage($hToolTip, $WM_SETFONT, $hFont, True)
_GUIToolTip_AddTool($hToolTip, 0, "This is a ToolTip Test", 0, 0, 0, 0, 0, BitOR($TTF_TRACK, $TTF_ABSOLUTE))
_GUIToolTip_TrackActivate($hToolTip)

While $bShow
  Sleep(10)
  _GUIToolTip_TrackPosition($hToolTip,MouseGetPos(0), MouseGetPos(1))
WEnd

_GUIToolTip_Destroy($hToolTip)
_WinAPI_DeleteObject($hFont)
_WinAPI_ReleaseDC(0, $hDC)

Func _Exit()
  $bShow = False
EndFunc

 

Link to comment
Share on other sites

Hi everybody :)
I tried what follows to change the font of a built-in tooltip, it seems to work :

#include <FontConstants.au3>
#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include <WinAPIGdiInternals.au3>

HotKeySet("{ESC}", _Exit)

Local $iToolFontSize = 25
Global $hFont = _WinAPI_CreateFont($iToolFontSize, 0, 0, 0, 400, False, False, False, _
    $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Tahoma')

Example()

Func Example()
    ToolTip("Tooltip Test", 300, 300)

    Local $hWnd = WinWait("Tooltip Test") ; look at the 2 alternative scripts below

    _WinAPI_SetWindowTheme($hWnd, "0", "0")
    _GUIToolTip_SetTipTextColor($hWnd, 0xFF)
    _GUIToolTip_SetTipBkColor($hWnd,0xFF0000)
    _WinAPI_SetFont($hWnd, $hFont)
    While Sleep(100)
    WEnd
EndFunc   ;==>Example

Func _Exit()
  _WinAPI_DeleteObject($hFont)
  Exit
EndFunc

Due to Winwait, there is a little moment (250ms) showing the initial tooltip (normal colors & font) then the final tooltip (new colors & new font). If these 250ms are a problem for the user, then the 1st alternative script below should display the final tooltip much quicker :

#include <FontConstants.au3>
#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include <WinAPIGdiInternals.au3>

HotKeySet("{ESC}", _Exit)

Local $iToolFontSize = 25
Global $hFont = _WinAPI_CreateFont($iToolFontSize, 0, 0, 0, 400, False, False, False, _
    $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Tahoma')

Example()

Func Example()
    ToolTip("Tooltip Test", 300, 300)

    Local $hWnd = 0, $aToolTip = WinList("[CLASS:tooltips_class32]")
    If IsArray($aToolTip) And $aToolTip[0][0] <> 0 Then
        For $i = 1 To $aToolTip[0][0]
            If $aToolTip[$i][0] = "Tooltip Test" Then
                $hWnd = $aToolTip[$i][1]
                ExitLoop
            EndIf
        Next
    EndIf
    If $hWnd = 0 Then $hWnd = WinWait("Tooltip Test")

    _WinAPI_SetWindowTheme($hWnd, "0", "0")
    _GUIToolTip_SetTipTextColor($hWnd, 0xFF)
    _GUIToolTip_SetTipBkColor($hWnd,0xFF0000)
    _WinAPI_SetFont($hWnd, $hFont)
    While Sleep(100)
    WEnd
EndFunc   ;==>Example

Func _Exit()
  _WinAPI_DeleteObject($hFont)
  Exit
EndFunc

And the 2nd alternative script below should display the tooltip even faster :

#include <FontConstants.au3>
#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include <WinAPIGdiInternals.au3>

HotKeySet("{ESC}", _Exit)

Local $iToolFontSize = 25
Global $hFont = _WinAPI_CreateFont($iToolFontSize, 0, 0, 0, 400, False, False, False, _
    $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Tahoma')

Example()

Func Example()
    ToolTip("Tooltip Test", 300, 300)

    Local $hWnd = 0, $aToolTip = WinList("[TITLE:Tooltip Test; CLASS:tooltips_class32]")
    If IsArray($aToolTip) And $aToolTip[0][0] = 1 Then
        $hWnd = $aToolTip[1][1]
    Else
        $hWnd = WinWait("Tooltip Test")
    EndIf

    _WinAPI_SetWindowTheme($hWnd, "0", "0")
    _GUIToolTip_SetTipTextColor($hWnd, 0xFF)
    _GUIToolTip_SetTipBkColor($hWnd,0xFF0000)
    _WinAPI_SetFont($hWnd, $hFont)
    While Sleep(100)
    WEnd
EndFunc   ;==>Example

Func _Exit()
  _WinAPI_DeleteObject($hFont)
  Exit
EndFunc

 

Edited by pixelsearch
added a 2nd alternative
Link to comment
Share on other sites

It doesn't seem to work on Win7.  The tooltip appears normal for a fraction of a sec, and then disappears.  That is what I was experimenting in my first attempts.

@pixelsearch There is a way to reduce delay of WinWait : 

Opt("WinWaitDelay", 10)

Or in case anyone would be interested...

Edited by Nine
Link to comment
Share on other sites

 

#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include <WinAPIGdiInternals.au3>

HotKeySet("{ESC}", _Exit)
Global $hFont =  _WinAPI_CreateFont(40, 0)
Example()

Func Example()

   ToolTip("Tooltip Test", Default, Default, Default, 0, 1)
   Local $hWnd = WinWait("Tooltip Test")
   _WinAPI_SetWindowTheme($hWnd, "", "")
   _GUIToolTip_SetTipTextColor($hWnd, 0xFFFFFF)
   _GUIToolTip_SetTipBkColor($hWnd,0x000000)
   _WinAPI_SetFont(WinGetHandle('Tooltip Test'), $hFont)
   ToolTip("Tooltip Test", Default, Default, Default, 0, 1)

   While Sleep(50)
      $pos = MouseGetPos(0)
      $pos2 = MouseGetPos(1)
      WinMove($hWnd, "", $pos, $pos2+20)
   WEnd

EndFunc   ;==>Example

Func _Exit()
    _WinAPI_DeleteObject($hFont)
    Exit
EndFunc

I figured out how to do. Thank you all.

JSON.au3

translate.au3

Edited by Anatoly
Link to comment
Share on other sites

@Anatoly Congrats.  By recalling Tooltip, it is now working also on Win7.  Who would have thought...hmm I guess you did ;)

Don't forget to delete the font after usage with  _WinAPI_DeleteObject()

Edited by Nine
Link to comment
Share on other sites

#include <GUIToolTip.au3>
#include <WinAPITheme.au3>
#include <WinAPIGdiInternals.au3>

HotKeySet("{ESC}", _Exit)
Global $hFont = _WinAPI_CreateFont(40, 0)
Example()

Func Example()
    ToolTip("Tooltip Test", -100, -100, Default, 0, 1) ; hide it from view
    Local $pos, $hWnd = WinWait("Tooltip Test")
    _WinAPI_SetWindowTheme($hWnd, "", "")
    _GUIToolTip_SetTipTextColor($hWnd, 0xFFFFFF)
    _GUIToolTip_SetTipBkColor($hWnd, 0x000000)
    _WinAPI_SetFont($hWnd, $hFont)
    ToolTip("Tooltip Test", Default, Default, Default, 0, 1)
    While Sleep(50)
        $pos = MouseGetPos() ; this is faster
        WinMove($hWnd, "", $pos[0], $pos[1] + 20)
    WEnd
EndFunc   ;==>Example

Func _Exit()
    _WinAPI_DeleteObject($hFont) ; this is needed
    Exit
EndFunc   ;==>_Exit

 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...