Jump to content

tooltip info


Recommended Posts

Here an example (proof of concept) using GDI+ to create a tooltip arrow position at the bottom.

 

;coded by UEZ build 2013-08-21
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPISys.au3>


If @AutoItVersion < "3.3.9.18" Then Exit MsgBox(16, "Error", "AutoIt version 3.3.9.18 or higher needed!")

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172
Global $iW = 400, $iH = 25, $iBGColor = 0xFFFFFF
Global Const $hGUI = GUICreate("Strip Progressbar", 600, 100, -1, -1, Default, $WS_EX_TOPMOST)
GUISetBkColor(0x404040)
Global Const $iPic = GUICtrlCreatePic("", 150, 37, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $iBtn = GUICtrlCreateButton("Start", 40, 20, 60, 60)
GUISetState()
Global $hB, $iSleep = 30
Global $fPerc, $fPercPrev, $iLoop, $aPos, $iPosX, $iPosY
Global $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xFFE8E5D9]]
Global $iRandom, $iColorTP, $hTooltip

Global $hImage = _GDIPlus_ImageLoadFromFile("c:\Program Files (x86)\AutoIt3\Examples\GUI\Merlin.gif")
Global $aTooltip = _Init(100, 50)

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_TIMER, "")
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_Shutdown()
            Exit
        Case $iBtn
            $fPerc = 0
            $iRandom = Random(0, UBound($aColors) - 1, 1)
            $iColorTP = $aColors[$iRandom][1]
            _WinAPI_SetLayeredWindowAttributes($aTooltip[0], $aTooltip[6], 255)
            GUIRegisterMsg($WM_TIMER, "PlayAnim")
            DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0)
    EndSwitch
Until False

Func _Init($iWidth = 70, $iHeight = 50, $iBGTColor = 0xFEDCBA)
    $hHBmp_BG = _GDIPlus_StripProgressbar(0, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], "")
    $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    Local $hGUI_ToolTip = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP + $WS_DISABLED, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW, $hGUI)
    GUISetBkColor($iBGTColor, $hGUI_ToolTip) ;set GUI background color
    Local $iPic = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)
    GUISetState(@SW_HIDE, $hGUI_ToolTip)
    _WinAPI_SetLayeredWindowAttributes($hGUI_ToolTip, $iBGTColor, 0xFF)
    Local $aResult[7] = [$hGUI_ToolTip, $iPic, $iWidth, $iHeight, _WinAPI_GetSystemMetrics(7), _WinAPI_GetSystemMetrics(4) + _WinAPI_GetSystemMetrics(33), $iBGTColor]
    Return $aResult
EndFunc   ;==>_Init

Func PlayAnim()
    Local $sText = "Loading...", $i, $iCalc1, $iCalc2, $hHBmp_TP
    $fPerc += 0.25
    If $fPerc >= 100.5 Then
        GUIRegisterMsg($WM_TIMER, "")
        $sText = "Done"
    EndIf
    $iLoop = $fPerc - $fPercPrev
    $fPercPrev = $fPerc

    For $i = $iLoop To 0 Step - 1
        $iCalc1 = ($fPerc - $i)
        $hHBmp_BG = _GDIPlus_StripProgressbar($iCalc1, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], $sText)
        $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG)
        If $hB Then _WinAPI_DeleteObject($hB)
        _WinAPI_DeleteObject($hHBmp_BG)
        $aPosCtrl = ControlGetPos($hGUI, 0, $iPic)
        $aPosGUI = WinGetPos($hGUI)
        $iPosX = $aPosCtrl[0] + $aPosGUI[0] + $aTooltip[4] - $aTooltip[2] / 2
        $iPosY = $aPosCtrl[1] + $aPosGUI[1] - $aPosCtrl[3] - 2
        If $iCalc1 >= 100.5 Then $iCalc1 = 100
        $iCalc2 = $iPosX + ($fPerc - $i) / 100 * $iW - 1
        If $iCalc2 >= $iPosX + $iW Then $iCalc2 = $iPosX + $iW
        $hHBmp_TP = _GDIPlus_CreateToolTipBitmap(StringFormat("%02d%", $iCalc1), $aTooltip[2], $aTooltip[3], "Arial", 11, 0xFFFFFFFF, 0xFF000000, 12, $hImage, 8, 6, 20, 22)
        _WinAPI_DeleteObject(GUICtrlSendMsg($aTooltip[1], $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_TP))
        _WinAPI_DeleteObject($hHBmp_TP)
        If WinGetState($aTooltip[0]) <> 3 Then WinSetState($aTooltip[0], "", @SW_SHOWNA)
        WinMove($aTooltip[0], "", $iCalc2, $iPosY)
    Next
    If $fPerc >= 100.5 Then
        For $i = 255 To 0 Step - 2
            _WinAPI_SetLayeredWindowAttributes($aTooltip[0], $aTooltip[6], $i)
            Sleep(10)
        Next
        WinSetState($aTooltip[0], "", @SW_HIDE)
    EndIf
EndFunc   ;==>PlayAnim

Func _GDIPlus_CreateToolTipBitmap($sText, $iW = 70, $iH = 50, $sFont = "Arial", $fFontSize = 11, $iBGColor = 0xFFFFFFFF, $iFontColor = 0xFF000000, $iRadius = 8, $hImage = 0, $iImgPosX = 8, $iImgPosY = 4, $iImgW = 16, $iImgH = 16, $bGDIBmp = 1)
    Local $iX = 0, $iY = 0, $iPenSize = 1, $iSize = 12, $iSize2 = $iSize / 2,   $iDX = $iW / 2
    Local $iWidth = $iW - $iPenSize, $iHeight = $iH - $iPenSize - $iSize
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT)
    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)
    _GDIPlus_PathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_PathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iDX + $iSize2, $iY + $iHeight)
    _GDIPlus_PathAddLine($hPath, $iDX + $iSize2, $iY + $iHeight, $iX + $iDX, $iY + $iHeight + $iSize)
    _GDIPlus_PathAddLine($hPath, $iX + $iDX, $iY + $iHeight + $iSize, $iX + $iDX - $iSize2, $iY + $iHeight)
    _GDIPlus_PathAddArc($hPath,  $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
    _GDIPlus_PathAddArc($hPath,  $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)
    _GDIPlus_PathCloseFigure($hPath)

    Local $hBrush = _GDIPlus_BrushCreateSolid($iBGColor)
    _GDIPlus_GraphicsFillPath($hCtxt, $hPath, $hBrush)
    Local $hPen = _GDIPlus_PenCreate(0xFF000000, $iPenSize)
    _GDIPlus_GraphicsDrawPath($hCtxt, $hPath, $hPen)

    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $fFontSize)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    Local $aMeasure = _GDIPlus_GraphicsMeasureString($hCtxt, $sText, $hFont, $tLayout, $hFormat)
    DllStructSetData($tLayout, "Y", ($iHeight - DllStructGetData($aMeasure[0], "Height")) / 2)
    _GDIPlus_BrushSetSolidColor($hBrush, $iFontColor)
    _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)

    If $hImage Then
        _GDIPlus_GraphicsSetInterpolationMode($hCtxt, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC)
        _GDIPlus_GraphicsDrawImageRectRect($hCtxt, $hImage, 0, 0, _GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage), $iImgPosX, $iImgPosY, $iImgW, $iImgH)
    EndIf

    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hCtxt)
    If $bGDIBmp Then
        Local $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hGDIBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_CreateToolTipBitmap

Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0x000000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True)
    If $fPerc < 0 Then $fPerc = 0
    If $fPerc > 100 Then $fPerc = 100

    Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBitmap = $hBitmap[6]
    Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui)

    Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY
    Local $hBmp = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iH, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBmp = $hBmp[6]
    Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp)
    Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12)
    Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize)

    _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor)
    Local Static $iX = 0
    For $iY = 0 To $iH - 1
        Switch $iDir
            Case 1
                _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen)
                _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen)
            Case Else
                _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen)
                _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen)
        EndSwitch
    Next
    Local $tPoint1 = DllStructCreate("float;float")
    Local $tPoint2 = DllStructCreate("float;float")
    DllStructSetData($tPoint1, 1, $iW / 2) ;x1
    DllStructSetData($tPoint2, 1, $iW / 2) ;x2
    Local $hLineBrush

    If $bFlip Then
        _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2)
        DllStructSetData($tPoint1, 2, $iH / 3) ;y1
        DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2
        $hLineBrush = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0)
        $hLineBrush = $hLineBrush[6]
        _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush)
    Else
        _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2)
        DllStructSetData($tPoint1, 2, 0) ;y1
        DllStructSetData($tPoint2, 2, $iH / 3) ;y2
        $hLineBrush = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0)
        $hLineBrush = $hLineBrush[6]
        _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush)
    EndIf
    $iX = Mod($iX + $iSpeed, $iWidth)

    Local $hTextureBrush = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "handle", $hBmp, "int", 0, "int*", 0)
    $hTextureBrush = $hTextureBrush[3]

    _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush)
    If $bFlip Then DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "handle", $hBitmap, "int", 6)

    DllCall($ghGDIPDll, "int", "GdipSetTextRenderingHint", "handle", $hCtxt, "int", $GDIP_TEXTRENDERINGHINT_CLEARTYPEGRIDFIT)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0x40000000 + $iTextColor)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 5, 2)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_GraphicsDispose($hCtxt_Bmp)
    _GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_BrushDispose($hLineBrush)
    If $bHBitmap Then
        Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBITMAP
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_StripProgressbar

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...