Resiak1811 Posted Thursday at 02:38 AM Share Posted Thursday at 02:38 AM (edited) Hi, I include 2 examples of what I have.. and what I want/need, I show the result in a tooltip .. Long story short, the number before the word "replace" is different length (part number) and the number after "replace" can be another part number.. I want the 2nd, 3th line etc. to be align with the 1st line (1st letter of the part number after the replace) ... hard to explain so I have include a picture And here what I have for now : expandcollapse popup#include <String.au3> ;~ --------- Example #1 --------- $List = "" $gText = "987654" $aRow = "1 2 3" $Split = StringSplit($aRow, " ") For $i = 1 To $Split[0] $List &= $Split[$i] $len = StringLen($gText & " replace ") If $i <> $Split[0] Then $List &= @CRLF & _StringRepeat(" ", $len) Next ToolTip($gText & " replace " & $List) Sleep(5000) ToolTip("") ;~ --------- Example #2 --------- $List = "" $gText = "5432" $aRow = "789 456" $Split = StringSplit($aRow, " ") For $i = 1 To $Split[0] $List &= $Split[$i] $len = StringLen($gText & " replace ") If $i <> $Split[0] Then $List &= @CRLF & _StringRepeat(" ", $len) Next ToolTip($gText & " replace " & $List) Sleep(5000) ToolTip("") The problem is the space is not the same width as a caracter so something it align perfectly but pure luck.. If someone have a idea thank you Edited Thursday at 10:01 AM by Resiak1811 Link to comment Share on other sites More sharing options...
ioa747 Posted Thursday at 03:03 AM Share Posted Thursday at 03:03 AM Musashi 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Nine Posted Thursday at 07:59 AM Share Posted Thursday at 07:59 AM Easiest way is to use $MB_RIGHT. Not exactly what you want but it is as close as it could get. MsgBox($MB_RIGHT, "Test", "987654 replace 1" & @CRLF & "2" & @CRLF & "3") “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Resiak1811 Posted Thursday at 10:02 AM Author Share Posted Thursday at 10:02 AM (edited) thanks both of you but I have edit my 1st post to put the result in the tooltip like is supposed to be... so any idea for the tooltip is welcome Edited Thursday at 10:03 AM by Resiak1811 Link to comment Share on other sites More sharing options...
ioa747 Posted Thursday at 02:17 PM Share Posted Thursday at 02:17 PM (edited) expandcollapse popup#include <String.au3> #include <FontConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> ;~ --------- Example #1 --------- $List = "" $gText = "987654" $aRow = "1 2 3" $Split = StringSplit($aRow, " ") For $i = 1 To $Split[0] $List &= $Split[$i] $len = StringLen($gText & " replace ") If $i <> $Split[0] Then $List &= @CRLF & _StringRepeat(" ", $len) Next _ToolTip($gText & " replace " & $List) ;~ --------- Example #2 --------- $List = "" $gText = "5432" $aRow = "789 456" $Split = StringSplit($aRow, " ") For $i = 1 To $Split[0] $List &= $Split[$i] $len = StringLen($gText & " replace ") If $i <> $Split[0] Then $List &= @CRLF & _StringRepeat(" ", $len) Next _ToolTip($gText & " replace " & $List) Func _ToolTip($sText, $iX = Default, $iY = Default, $sTitle = Default, $iIcon = Default, $iOptions = Default, $iSeconds = 5) ;🏆 https://www.autoitscript.com/forum/topic/205225-tooltip-set-style-moved/#comment-1476250 Local Static $hFont = _WinAPI_CreateFont(20, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "DejaVu Sans Mono") ToolTip($sText, -100, -100, $sTitle, $iIcon, $iOptions) ; hide it from view Local $hWnd = WinWait($sText) _WinAPI_SetFont($hWnd, $hFont) ToolTip($sText, $iX, $iY, $sTitle, $iIcon, $iOptions) For $i = 1 To $iSeconds Sleep(1000) Next ToolTip("") EndFunc ;==>Example Edited Friday at 02:29 AM by ioa747 add ToolTip("") I know that I know nothing Link to comment Share on other sites More sharing options...
pixelsearch Posted Thursday at 02:22 PM Share Posted Thursday at 02:22 PM (edited) For tooltips, I would do it like this, using @Melba23 StringSize UDF (found in his signature) #include "StringSize.au3" ; Melba23's Local $aLine = ["987654 replace drfghdfhxdfghfgh 1", "2", "hello 34"] Local $iW0, $iW, $sText = $aLine[0] $iW0 = _StringSize($aLine[0], 9, 400, 0, "Tahoma")[2] ; [2] => width in pixels For $i = 1 To Ubound($aLine) - 1 While True $aLine[$i] = " " & $aLine[$i] $iW = _StringSize($aLine[$i], 9, 400, 0, "Tahoma")[2] If ($iW0 - $iW < 4) Or ($iW >= $iW0) Then ExitLoop WEnd $sText &= @LF & $aLine[$i] Next ToolTip($sText, Default, Default, Default, Default, 1) ; 1 = balloon Sleep(5000) But this is only a part of the script, it may display differently depending on the OS, because to retrieve these 3 values... 9, 400, "Tahoma" ...I used a function from Yashied to retrieve the font attributes of a window based on its handle (a tooltip handle in this case) Edited Thursday at 02:54 PM by pixelsearch less lines in code Link to comment Share on other sites More sharing options...
Resiak1811 Posted Thursday at 08:09 PM Author Share Posted Thursday at 08:09 PM (edited) again .. thanks to both of you ... I try both solution and both are not working ... but #1 : ioa747 currently I use a modified version of the StringSize script so I will test with the original file later...same prob. with the original file thanks but #2 : pixelsearch the problem is probably the font attributes as you say I though it was easier than this lol thank you for your time Edited Thursday at 10:02 PM by Resiak1811 Link to comment Share on other sites More sharing options...
Nine Posted Thursday at 08:58 PM Share Posted Thursday at 08:58 PM I was aiming at the same solution as @ioa747. The problem you have is probably because you do not own the DejaVu Sans Mono font. Try with Courier or Terminal font. It should work. ioa747 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Resiak1811 Posted Thursday at 10:14 PM Author Share Posted Thursday at 10:14 PM ok with $font = "Terminal" .. its working (sort of) its right alignment.. but I will play with that later to see if I can achive what I want, thank you Link to comment Share on other sites More sharing options...
pixelsearch Posted Thursday at 11:59 PM Share Posted Thursday at 11:59 PM (edited) 3 hours ago, Resiak1811 said: but #2 : pixelsearch the problem is probably the font attributes as you say Yes I guessed it won't work correctly on other OS's, so... To the people who commented on this thread (and other volunteers too !) could you please run the script below, which is a more complete version as it first retrieves the font attributes of a tooltip window on your OS. Is the final tooltip correctly right-justified now ? Thanks & finger crossed expandcollapse popup#include "StringSize.au3" ; Melba23's #Include <FontConstants.au3> #include <SendMessage.au3> #include <WinAPIGdiDC.au3> #Include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Local $aToolText = ["987654 replace drfghdfhxdfghfgh 1", "2", "hello 34"] Local $sToolText = _ToolTipRightJustify($aToolText) ToolTip($sToolText, Default, Default, Default, Default, 1) ; 1 = balloon Sleep(5000) ;============================================== Func _ToolTipRightJustify($aToolText) ; Get the tooltip font attributes from a temporary hidden tooltip Local $sHiddenText, $hWnd, $aFont $sHiddenText = "Hidden tooltip to get its font" ToolTip($sHiddenText, -300, 0) $hWnd = WinGetHandle($sHiddenText) $aFont = _GetFont($hWnd) ToolTip("") ; Compute each tooltip line to have nearly the same number of pixels as the 1st tooltip line Local $iW0, $iW, $sLine, $sToolText = $aToolText[0] $iW0 = _StringSize($aToolText[0], $aFont[0], $aFont[1], 0, $aFont[3])[2] ; [2] => width in pixels For $i = 1 To Ubound($aToolText) - 1 $sLine = $aToolText[$i] While True $sLine = " " & $sLine $iW = _StringSize($sLine, $aFont[0], $aFont[1], 0, $aFont[3])[2] If ($iW0 - $iW < 4) Or ($iW >= $iW0) Then ExitLoop WEnd $sToolText &= @LF & $sLine Next Return $sToolText EndFunc ;==>_ToolTipRightJustify ;============================================== Func _GetFont($hWnd) Local $hDC, $hFont, $tFont, $aFont[5] $hDC = _WinAPI_GetDC($hWnd) $hFont = _SendMessage($hWnd, $WM_GETFONT) $tFont = DllStructCreate($tagLOGFONT) _WinAPI_GetObject($hFont, DllStructGetSize($tFont), DllStructGetPtr($tFont)) $aFont[0] = -Round(DllStructGetData($tFont, 'Height') / _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * 72, 1) $aFont[1] = DllStructGetData($tFont, 'Weight') ; $aFont[2] = BitOR(2 * (DllStructGetData($tFont, 'Italic') <> 0), 4 * (DllStructGetData($tFont, 'Underline') <> 0), 8 * (DllStructGetData($tFont, 'Strikeout') <> 0)) $aFont[3] = DllStructGetData($tFont, 'FaceName') ; $aFont[4] = DllStructGetData($tFont, 'Quality') _WinAPI_ReleaseDC($hWnd, $hDC) Return $aFont EndFunc ;==>_GetFont Edited Friday at 12:01 AM by pixelsearch typo Link to comment Share on other sites More sharing options...
Resiak1811 Posted Friday at 12:09 AM Author Share Posted Friday at 12:09 AM for a right-alignment .. look ok on my PC (windows 11) nice you have found a solution for a right alignment (even if its not what I want haha) Link to comment Share on other sites More sharing options...
pixelsearch Posted Friday at 12:10 AM Share Posted Friday at 12:10 AM Great news Link to comment Share on other sites More sharing options...
Solution pixelsearch Posted Friday at 12:49 AM Solution Share Posted Friday at 12:49 AM With a small change in the script, you get this : expandcollapse popup#include "StringSize.au3" ; Melba23's #Include <FontConstants.au3> #include <SendMessage.au3> #include <WinAPIGdiDC.au3> #Include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Local $aToolText = ["987654 replace 17", "234", "5678", "9"] Local $sToolText = _ToolTipJustify($aToolText, "replace") ToolTip($sToolText, Default, Default, Default, Default, 1) ; 1 = balloon Sleep(5000) ;============================================== Func _ToolTipJustify($aToolText, $sAlignAfterThis) ; Get the tooltip font attributes from a temporary hidden tooltip Local $sHiddenText, $hWnd, $aFont $sHiddenText = "Hidden tooltip to get its font" ToolTip($sHiddenText, -300, 0) $hWnd = WinGetHandle($sHiddenText) $aFont = _GetFont($hWnd) ToolTip("") Local $iPos, $sLeft, $iW0, $iW, $sSpaces, $sToolText = $aToolText[0] $iPos = StringInStr($aToolText[0], $sAlignAfterThis) + StringLen($sAlignAfterThis) $sLeft = StringLeft($aToolText[0], $iPos) $iW0 = _StringSize($sLeft, $aFont[0], $aFont[1], 0, $aFont[3])[2] ; [2] => width in pixels While True $sSpaces = " " & $sSpaces $iW = _StringSize($sSpaces, $aFont[0], $aFont[1], 0, $aFont[3])[2] If ($iW0 - $iW < 4) Or ($iW >= $iW0) Then ExitLoop WEnd For $i = 1 To Ubound($aToolText) - 1 $sToolText &= @LF & $sSpaces & $aToolText[$i] Next Return $sToolText EndFunc ;==>_ToolTipJustify ;============================================== Func _GetFont($hWnd) Local $hDC, $hFont, $tFont, $aFont[5] $hDC = _WinAPI_GetDC($hWnd) $hFont = _SendMessage($hWnd, $WM_GETFONT) $tFont = DllStructCreate($tagLOGFONT) _WinAPI_GetObject($hFont, DllStructGetSize($tFont), DllStructGetPtr($tFont)) $aFont[0] = -Round(DllStructGetData($tFont, 'Height') / _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * 72, 1) $aFont[1] = DllStructGetData($tFont, 'Weight') ; $aFont[2] = BitOR(2 * (DllStructGetData($tFont, 'Italic') <> 0), 4 * (DllStructGetData($tFont, 'Underline') <> 0), 8 * (DllStructGetData($tFont, 'Strikeout') <> 0)) $aFont[3] = DllStructGetData($tFont, 'FaceName') ; $aFont[4] = DllStructGetData($tFont, 'Quality') _WinAPI_ReleaseDC($hWnd, $hDC) Return $aFont EndFunc ;==>_GetFont Link to comment Share on other sites More sharing options...
Resiak1811 Posted Friday at 12:56 AM Author Share Posted Friday at 12:56 AM Jackpot pixelsearch that's what I'm looking for !! 😀 Wow I was so far of that solution THANK !! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now