Leaderboard
Popular Content
Showing content with the highest reputation on 09/25/2020 in all areas
-
It's not that hard. Here is an example with the context menu in Notepad. Run the code in SciTE with F5. Only tested in Windows 7. Should also work in Windows 10. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <Misc.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> Example() Func Example() ; Open Notepad Run( "notepad.exe" ) WinWait( "[CLASS:Notepad]" ) ; Open context menu Send( "{APPSKEY}" ) WinWait( "[CLASS:#32768]" ) ; Get menu handle Local $hMenu = GetMenuHandle() If Not $hMenu Then Return ConsoleWrite( "$hMenu ERR" & @CRLF ) ConsoleWrite( "$hMenu OK" & @CRLF ) ; Add new menu item Local $iItem = _GUICtrlMenu_AddMenuItem( $hMenu, "My new menu item" ) If Not $iItem Then Return ConsoleWrite( "$iItem ERR" & @CRLF ) ConsoleWrite( "$iItem OK" & @CRLF ) ; Show all menu items Local $iCount = _GUICtrlMenu_GetItemCount( $hMenu ), $sText For $i = 0 To $iCount - 1 $sText = _GUICtrlMenu_GetItemText( $hMenu, $i ) If $sText <> "" Then ConsoleWrite( "$sText = " & $sText & @CRLF ) ConsoleWrite( "$iIndex = " & $i & @CRLF ) EndIf Next ; Detect menu item click While Sleep(10) And Not _IsPressed( "01", "user32.dll" ) WEnd $iItem = _GUICtrlMenu_MenuItemFromPointEx( 0, $hMenu ) ; Works in both 32 and 64 bit code ConsoleWrite( "Clicked item = " & $iItem & @CRLF ) If $iItem <> $iCount - 1 Then Return ConsoleWrite( "My new menu item NOT clicked" & @CRLF ) ConsoleWrite( "My new menu item clicked" & @CRLF ) EndFunc Func GetMenuHandle() Local $hDesktop = _WinAPI_GetDesktopWindow(), $i = 0 Local $hChild = _WinAPI_GetWindow( $hDesktop, $GW_CHILD ) While $hChild And $i < 50 If _WinAPI_GetClassName( $hChild ) = "#32768" Then ExitLoop $hChild = _WinAPI_GetWindow( $hChild, $GW_HWNDNEXT ) $i += 1 WEnd If $i = 50 Then Return 0 Local $hMenu = _SendMessage( $hChild, $MN_GETHMENU ) If $hMenu > 0 Then Return $hMenu Return 0 EndFunc Func _GUICtrlMenu_MenuItemFromPointEx( $hWnd, $hMenu, $iX = -1, $iY = -1 ) If $iX = -1 Then $iX = _WinAPI_GetMousePosX() If $iY = -1 Then $iY = _WinAPI_GetMousePosY() Local $tPOINT = DllStructCreate( "long;long" ) DllStructSetData( $tPOINT, 1, $iX ) DllStructSetData( $tPOINT, 2, $iY ) Local $tPOINT64 = DllStructCreate( "int64", DllStructGetPtr( $tPOINT ) ) Local $aResult = DllCall("user32.dll", "int", "MenuItemFromPoint", "hwnd", $hWnd, "handle", $hMenu, "int64", DllStructGetData( $tPOINT64, 1 ) ) If @error Then Return SetError(@error, @extended, -1) Return $aResult[0] EndFunc SciTE output: $hMenu OK $iItem OK $sText = &Undo $iIndex = 0 $sText = Cu&t $iIndex = 2 $sText = &Copy $iIndex = 3 $sText = &Paste $iIndex = 4 $sText = &Delete $iIndex = 5 $sText = Select &All $iIndex = 7 $sText = &Right to left Reading order $iIndex = 9 $sText = &Show Unicode control characters $iIndex = 10 $sText = &Insert Unicode control character $iIndex = 11 $sText = &Open IME $iIndex = 13 $sText = &Reconversion $iIndex = 14 $sText = My new menu item ; <<<<<<<< $iIndex = 15 Clicked item = 15 My new menu item clicked ; <<<<<<<< Once the new menu item is clicked, you can either execute a menu function directly, or you can open your own context menu with several items and possibly submenus. Both with straightforward AutoIt code.2 points
-
[BUGFIX VERSION] - 6 Apr 24 Fixed: UDF failed if header colours were initialised but not specifically set. New UDF in the zip below. -------------------------------------------------------------------------------------- Note: This is a new recoded and expanded version of my earlier UDF of the same name. If you move to this new version there might well be several script-breaking changes, particularly when setting which columns are to be editable. Please read the "Beginner's Guide" and look at the included example scripts to see where things have changed. -------------------------------------------------------------------------------------- This UDF allows you to do much more with ListView controls (either native or UDF created): Edit the content with plain text, combos or date-time pickers - and edit the headers too Move rows within the ListView Drag rows both within the ListView and to other ListViews in the same GUI (or not as required) Insert and delete columns and rows Sort columns by simply clicking the header Colour individual ListView items and headers Only select a single cell rather then the entire row Save and load entire ListViews For the advanced user: If you use certain Windows message handlers (In particular WM_NOTIFY) in your script, please read the function headers for the equivalent handlers within the UDF. Here is the UDF, with 6 examples and the guide, in zip format: GUIListViewEx.zip Credit to: martin (basic drag code), Array.au3 authors (array functions), KaFu and ProgAndy (font function), LarsJ (colouring code) Happy to take compliments or criticism - preferably the former! M231 point
-
You can probably even omit " at the beginning and end of the string, and just search for status":"Offline Local $sSearch = 'status":"Offline' or : Local $sSearch = 'status' & Chr(34) & ':' & Chr(34) & 'Offline'1 point
-
Why don't you use: '"status":"Offline"' That's your target string wrapped in single quotes. Unless using a regular expression is a requirement, that should work in a simple StringInStr also. Look at the "Strings" section under the data types topic for an explanation: https://www.autoitscript.com/autoit3/docs/intro/lang_datatypes.htm1 point
-
yeah.., thanks anyway! guess I need to fiddle around with the clipboard or geta scanner with software which replaces [GS].1 point
-
I don't have a barcode scanner so I'm trying to manually reproduce the issue in AutoIt. Unfortunately, I can't recreate it. Using the example below, when the form is shown, the input has a value of "one[GS]two". You can't see the [GS], because it is unprintable, but it is there as you can see by the console output. If I used a different font, like a raster font, I probably could get it to display in the input control like it does in the console output. #include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Form1 = GUICreate("Form1", 304, 63, 298, 143) Global $Input1 = GUICtrlCreateInput("Input1", 16, 16, 185, 21) GUICtrlSetData($Input1, "one" & Chr(29) & "two") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ConsoleWrite(StringFormat("Text value of $Input1 = %s", GUICtrlRead($Input1)) & @CRLF) ConsoleWrite(StringFormat("Binary value of $Input1 = %s", Binary(GUICtrlRead($Input1))) & @CRLF) Console output:1 point
-
After WM_Command is triggered, _ArrayDisplay locks up script
pixelsearch reacted to abberration for a topic
You have been extremely helpful. I finished the script and my code is extremely similar to yours. Exactly what it does is organizes TV episodes into folders and sub-folders (the way I prefer them). The show must have something like S01E14 in it (or 1x14, which I added code to convert it). It will create a folder for that show if it doen't exist and create a sub-folder like S01. Finally, it moves the file to that folder. If anyone is interested in the final code, here it is (hey, maybe someone else might be able to use it): #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Custom-Icon-Design-Pretty-Office-5-Folder-Add.ico #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <WinAPI.au3> #include <WinAPIConstants.au3> #include <WinAPISys.au3> #include <GuiButton.au3> #include <File.au3> #include <String.au3> $strSupportedFormats = "*.avi;*.mpg;*.mpeg;*.mp4;*.mkv;*.wmv" $guiForm1 = GUICreate("Create Folders And Organize", 305, 356) GUISetState(@SW_SHOW) $guiDummy = GUICtrlCreateDummy() $arrWinList = _GetListOfOpenExplorerWindows(1, 3) ; creates an array of windows that are open _ArraySort($arrWinList, 0, 1) If IsArray($arrWinList) Then ; List the open If $arrWinList[0][0] > 12 Then WinMove($guiForm1, "", @DesktopWidth/2 - 305, Default, 610, 378) EndIf For $i = 1 To $arrWinList[0][0] If $i < 13 Then $y = (($i - 1) * 28) + 8 Assign("guiButton" & $i, GUICtrlCreateButton($arrWinList[$i][0], 8, $y , 283, 25, $WS_GROUP)) ElseIf $i > 12 Then $y = (($i - 13) * 28) + 8 Assign("guiButton" & $i, GUICtrlCreateButton($arrWinList[$i][0], 305, $y, 283, 25, $WS_GROUP)) If $i = 24 Then ExitLoop EndIf EndIf Next EndIf GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $guiDummy $strText = GUICtrlRead($guiDummy) GUICtrlSendToDummy($strText) $arrPos = _ArraySearch($arrWinList, $strText) _OrganizeFolder($arrWinList[$arrPos][1]) EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ; if button is clicked, give popup confirming it. Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) If $iCode = $BN_CLICKED Then $text = _GUICtrlButton_GetText ($hWndFrom) GUICtrlSendToDummy($guiDummy, $text) EndIf EndFunc Func _GetListOfOpenExplorerWindows($vIncludeArrayCount = 0, $vColumnReturn = 3) ; (0 = No, 1 = Yes), (1 = Short Names Only, 2 = Long Addresses, 3 or 1 + 2 = Return Both) Local $aWinList, $sGetText, $aWinText, $varStrLen, $sFormat, $i, $j, $k, $vRowsToDel $aWinList = WinList() Local $aOutput[0][2] $k = 0 For $i = 1 To $aWinList[0][0] $sGetText = WinGetText($aWinList[$i][0]) $aWinText = StringSplit($sGetText, @LF) For $j = 1 To $aWinText[0] If StringInStr($aWinText[$j], "Address:") Then $sFormat = StringReplace($aWinText[$j], "Address: ", "") If DirGetSize($sFormat) > -1 Then ReDim $aOutput[UBound($aOutput) + 1][2] $aOutput[$k][0] = $aWinList[$i][0] $aOutput[$k][1] = $sFormat $k += 1 EndIf EndIf Next Next For $i = 1 To UBound($aOutput) $varStrLen = StringLen($aOutput[$i - 1][0]) If $varStrLen = 0 Then $vRowsToDel = $vRowsToDel & $i - 1 & ";" EndIf Next $vRowsToDel = StringTrimRight($vRowsToDel, 1) _ArrayDelete($aOutput, $vRowsToDel) If $vIncludeArrayCount = 1 Then _ArrayInsert($aOutput, 0, UBound($aOutput)) EndIf If $vColumnReturn = 1 Then _ArrayColDelete($aOutput, 1) ElseIf $vColumnReturn = 2 Then If $vIncludeArrayCount = 1 Then If UBound($aOutput) > 0 Then $aOutput[0][1] = UBound($aOutput) EndIf EndIf _ArrayColDelete($aOutput, 0) EndIf If UBound($aOutput) = 0 Then Return -1 Else Return $aOutput EndIf EndFunc Func _OrganizeFolder($strFolderName) ; code to organize the content of the folder $arrFileList = _FileListToArrayRec($strFolderName & "\", $strSupportedFormats, 1, 0) For $i = 1 To $arrFileList[0] $strFileName = $arrFileList[$i] $arrSeason = StringRegExp($strFileName, "[S|s]\d\d[E|e]\d\d", 1) $arrSeasonx = StringRegExp($strFileName, "\d{1,2}[x|X]\d{1,2}", 1) ; If the show is formatted as 1x13 then convert to S01E14 If IsArray($arrSeasonx) Then Dim $arrSeason[1] $arrSeason[0] = StringRegExpReplace($arrSeasonx[0], "\d{1,2}[x|X]\d{1,2}", _ConvertXToS($arrSeasonx[0])) $strFileNameOrig = $strFileName $strFileName = StringRegExpReplace($strFileName, "\d{1,2}[x|X]\d{1,2}", $arrSeason[0]) ; going back to the original file name, substitute 1x13 for S01E14. FileMove($strFolderName & "\" & $strFileNameOrig, $strFolderName & "\" & $strFileName) EndIf If IsArray($arrSeason) Then $arrShowName = StringRegExp($strFileName, ".+?(?=.[S]\d\d[E]\d\d)", 1) $strShowName = StringRegExpReplace($arrShowName[0], "\.", " ") $strFullPath = $strFolderName & "\" & _StringProper($strShowName) & "\" & _StringProper(StringLeft($arrSeason[0], 3)) If FileExists($strFullPath) = 0 Then DirCreate($strFullPath) EndIf FileMove($strFolderName & "\" & $strFileName, $strFullPath & "\" & $strFileName) Endif Next Exit EndFunc Func _ConvertXToS($varExp) $varExp = StringLower($varExp) ; Force the x to be lowercase becasue stringsplit is case sensitive $arrStrBreakdown = StringSplit($varExp, "x", 2) $varStrReconstructed = "S" & StringFormat("%02d", $arrStrBreakdown[0]) & "E" & StringFormat("%02d", $arrStrBreakdown[1]) Return $varStrReconstructed EndFunc I didn't put any safeguards because I only wrote it for myself and if a file doesn't match the season/episode specific expression, it ignores files. I didn't un-register the WM_Command because for this specific program, I will only ever run it one time and automatically quit. In the future (and for older programs that I keep running), I will make that change. Thanks for your help once again!1 point -
After WM_Command is triggered, _ArrayDisplay locks up script
abberration reacted to pixelsearch for a topic
Hi abberration Just like you, I didn't use dummy controls when I started to learn AutoIt (2.5 years now) But they really can be useful at times and your script is a perfect example for using them, because you don't get specific controls (in the While... Wend loop) corresponding to each button created dynamically by your script. Applied to your script, here are the 3 steps to create, activate, then check the dummy control : $guiForm1 = GUICreate("Form1", 305, 356) $idDummy = GUICtrlCreateDummy() ; <========== 1) Create the dummy control GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ... Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) If $iCode = $BN_CLICKED Then $text = _GUICtrlButton_GetText ( $hWndFrom ) GUICtrlSendToDummy($idDummy, $text) ; <========== 2) Activate the dummy control EndIf EndFunc ... While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idDummy ; <========== 3) Check the dummy control GUIRegisterMsg($WM_COMMAND, "") $text_read = GUICtrlRead($idDummy) $arrPos = _ArraySearch($arrWinList, $text_read) _OrganizeFolder($arrWinList[$arrPos][1]) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") EndSwitch WEnd See how easy it is ? Even the important string "button text" has been sent to the main loop with that single line, avoiding a global variable. GUICtrlSendToDummy($idDummy, $text) Also, there's no need to use _ArraySearch() within the WM_COMMAND function, because _ArraySearch() takes time too (in case of a big array) and it may freeze the script when used within a registered message (as we discussed earlier). It's now moved to the main loop too. As you seemed to like the unregistration/re-registration phase, I added it to the script above. Now you can click on any button in the GUI (while ArrayDisplay is active), nothing will happen after ArrayDisplay is ended (tested) GUIRegisterMsg($WM_COMMAND, "") ... GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") By the way, I succeeded to create dynamically 12 buttons (it fits the original GUI) then a 13th => 24th button would appear in your enlarged GUI, well done abberration1 point -
Here you find a good desription on how to set the follow up flag.1 point
-
Events should be used to act on arriving mails. Please check this thread:1 point
-
Search strinmg in console window - impossible?
TheXman reacted to JockoDundee for a topic
asked and answered. but if you really, really need to use putty, you can try something* like this Local $BadIdea = WinWaitActive("[TITLE:PuTTY]") Local $GettingIt = False While Not $GettingIt ControlSend($BadIdea, “”, “”, “^a^c {PGDN} {ESC}”) $GarbageOut=ClipGet() If $GarbageIn=$GarbageOut Then $GettingIt=True Else $GarbageIn=$GarbageOut $ScreenScrapage&=$GarbageOut EndIf WEnd ConsoleWrite($ScreenScrapage) *Not tested1 point -
Not at the moment. The function returns all records it finds. Why do you want to limit the number of records returned? Performance reasons?1 point
-
New version: @jguinch please check when you will have some spare time. PrintMgr.au3 PrintMgr_Example.au31 point
-
Read the content of a TcxGrid cell from AutoIt
Earthshine reacted to LarsJ for a topic
I've been looking at the TcxGrid control in QuantumGrid.exe. It only supports MSAA (MS Active Accessibility) automation. But it's apparently not possible to get an overview of the entire Grid control. Only a single cell at a time if you click it. With AutoIt Window Info tool you can also get info about a single cell if you click it. By far the easiest way of automation for your purpose is to use an OCR program eg. Tesseract which is already available in AutoIt. Ie. take one or more screenshots of the Grid control (it can be fully automated) and extract the text in the images with Tesseract. Then you have all the Grid text in a file. Then it's easy to solve the task described in first post.1 point -
maniootek, You could determine the size of the new content with my StringSize UDF and adjust the ListView and GUI accordingly - something like this perhaps: #include <GUIConstantsEx.au3> #include <GuiListViewEx_Test.au3> #include <Array.au3> #include "StringSize.au3" $iWidth = 200 Example() Func Example() $hGUI = GUICreate("listview items", $iWidth + 20, 250, 100, 200, -1) Local $idListview = GUICtrlCreateListView("col1|col2|col3 ", 10, 10, $iWidth, 150) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) _GUICtrlListView_SetExtendedListViewStyle($idListview, $iExListViewStyle) GUICtrlSetFont($idListview, 10, 0, 0) Local $aArray[6] for $i=0 to 5 $aArray[$i] = $i & "|name|1" GUICtrlCreateListViewItem($i & "|name|1" , $idListview) Next $cButton = GUICtrlCreateButton("Read ListView", 10, 200, 80, 30) GUISetState(@SW_SHOW) $iLV_Index = _GUIListViewEx_Init($idListview, $aArray, 0, 0, True, 2) _GUIListViewEx_SetEditStatus($iLV_Index, "2") _GUIListViewEx_MsgRegister(True, False, False) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cButton $aRead = _GUIListViewEx_ReturnArray($iLV_Index) _ArrayDisplay($aRead, "Content", Default, 8) $aRead = _GUIListViewEx_ReturnArray($iLV_Index, 1) _ArrayDisplay($aRead, "Checkboxes", Default, 8) EndSwitch $vRet = _GUIListViewEx_EventMonitor() ; Check there was a valid edit return If @extended = 1 And IsArray($vRet) Then ; Get the size of the inserted string $aRet = _StringSize($vRet[1][3], 10) ; Gte the present column width $iColWidth = _GUICtrlListView_GetColumnWidth($idListview, 2) ; Now see if we need to expand the column and GUI If $aRet[2] > $iColWidth - 15 Then _GUICtrlListView_SetColumnWidth($idListview, 2, $aRet[2] + 15) ; You need a margin $iDiff = $aRet[2] + 5 - $iColWidth $aWinPos = WinGetPos($hGUI) WinMove($hGUI, "", Default, Default, $aWinPos[2] + $iDiff) EndIf EndIf WEnd EndFunc M231 point
-
Here are two functions to provide pixel-accurate height and width dimensions for a given string. The more commonly-used _GDIPlus_GraphicsMeasureString built-in UDF is problematic because it returns the width padded by roughly one en-space (for reasons related to the various ways Windows produces anti-aliased fonts). These are AutoIt translations of Pierre Arnaud's C# functions, described in his CodeProject article "Bypass Graphics.MeasureString limitations" The first is an all-purpose version that takes a window handle, string, font family, font size (in points), style, and (optionally) width of the layout column (in pixels) as parameters. The second, more efficient version is intended for applications where GDI+ fonts are already in use, and takes handles to the existing graphics context, string, font, layout and format as parameters. Both functions return a two-row array with the exact width [0] and height [1] of the string (in pixels). EDIT: (Note that some of the same anti-aliasing measurement issues still apply. I did my best to work around them, but the output of the function may still be off by a pixel or two. Buyer beware.) #include <GDIPlus.au3> #include <GUIConstantsEx.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringInPixels ; Description ...: Returns a pixel-accurate height and width for a given string using a given font, style and size. ; Syntax ........: _StringInPixels($hGUI, $sString, $sFontFamily, $fSize, $iStyle[, $iColWidth = 0]) ; Parameters ....: $hGUI - Handle to the window. ; $sString - The string to be measured. ; $sFontFamily - Full name of the font to use. ; $fSize - Font size in points (half-point increments). ; $iStyle - Combination of 0-normal, 1-bold, 2-italic, 4-underline, 8-strikethrough ; $iColWidth - [optional] If word-wrap is desired, column width in pixels ; Return values .: 2-row array. [0] is width in pixels; [1] is height in pixels. ; Author ........: Tim Curran; adapted from Pierre Arnaud's C# function ; Modified ......: ; Remarks .......: This version is longer and less efficient but works for all purposes. ; Related .......: <https://www.codeproject.com/Articles/2118/Bypass-Graphics-MeasureString-limitations> ; Link ..........: ; Example .......: Example-StringInPixels.au3 ; =============================================================================================================================== #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Func _StringInPixels($hGUI, $sString, $sFontFamily, $fSize, $iStyle, $iColWidth = 0) _GDIPlus_Startup() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle Local $aRanges[2][2] = [[1]] $aRanges[1][0] = 0 ;Measure first char (0-based) $aRanges[1][1] = StringLen($sString) ;Region = String length Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFontFamily) Local $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle) _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ;Set ranges Local $aWinClient = WinGetClientSize($hGUI) If $iColWidth = 0 Then $iColWidth = $aWinClient[0] Local $tLayout = _GDIPlus_RectFCreate(10, 10, $iColWidth, $aWinClient[1]) Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ;get array of regions Local $aBounds = _GDIPlus_RegionGetBounds($aRegions[1], $hGraphic) Local $aWidthHeight[2] = [$aBounds[2], $aBounds[3]] ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_RegionDispose($aRegions[1]) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Return $aWidthHeight EndFunc ;==>_StringInPixels ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringInPixels_gdip ; Description ...: Returns a pixel-accurate height and width for a given string using a GDI+ font, layout and format ; Syntax ........: _StringInPixels_gdip($hGraphic, $sString, $hFont, $tLayout, $hFormat) ; Parameters ....: $hGraphic - Handle to a GDI+ graphics object. ; $sString - The string to be measured. ; $hFont - Handle to a GDI+ font. ; $tLayout - A $tagGDIPRECTF structure that bounds the string. ; $hFormat - Handle to a GDI+ string format. ; Return values .: 2-row array. [0] is width in pixels; [1] is height in pixels. ; Author ........: Tim Curran; adapted from Pierre Arnaud's C# function ; Modified ......: ; Remarks .......: This much more efficient version is for use with GDI+ fonts ; Related .......: ; Link ..........: <https://www.codeproject.com/Articles/2118/Bypass-Graphics-MeasureString-limitations> ; Example .......: Example-StringInPixels.au3 ; =============================================================================================================================== #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Func _StringInPixels_gdip($hGraphic, $sString, $hFont, $tLayout, $hFormat) Local $aRanges[2][2] = [[1]] $aRanges[1][0] = 0 ;Measure first char (0-based) $aRanges[1][1] = StringLen($sString) ;Region = String length _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_CLEARTYPEGRIDFIT) _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ;Set ranges Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ;get array of regions Local $aBounds = _GDIPlus_RegionGetBounds($aRegions[1], $hGraphic) Local $aWidthHeight[2] = [$aBounds[2], $aBounds[3]] _GDIPlus_RegionDispose($aRegions[1]) Return $aWidthHeight EndFunc ;==>_StringInPixels_gdip _StringInPixels.au3 Example-StringInPixels.au31 point
-
Printer Tool
auto-it-tous reacted to kpu for a topic
I'm sure there are tools that do what I've done, maybe even better. I just thought some green horn like myself might find useful. WHAT IT DOES 1. Reads "printer.ini" and creates a *.vbs (windows scripting) file to create the ports needed. You will need sscreen.gif to see a splash screen. Edit $destination = "sscreen.gif" to point to the correct graphic. This is composed of 2 tools: 1. Is the INI_Writer 2. Is the tool that reads the printer.ini file. Make sure you name it "printer.ini" THE INI WRITER CODE: #include <file.au3> ; Writing INI for Printer Information $ini = inputBox("Printer INI","What is the name of the ini you want to create","printer.ini") IF @error = 1 then MsgBox(0, "Closing", "Good Bye") Exit Endif _FileCreate($ini) ;Ask for the Printer Que name $printer = InputBox("Print Que","What is the printer que name?","PRINTER_2_HP4050TN_Q") IF @error = 1 then MsgBox(0, "Closing", "Good Bye") Exit Endif ;Ask for Printer IP $ip = InputBox("Printer IP","What is the printer IP?","10.20.70.256") IF @error = 1 then MsgBox(0, "Closing", "Good Bye") Exit Endif ;Ask for Drive location $driver = InputBox("Printer Drivers","Where is the location of the printer?" & @CR & _ "Press 1 for HP5M" & @CR & "Press 2 for HP4000TN" & @CR & "Press 3 for HP4050TN" & @CR _ & "Press 4 for HP4100TN" & @CR & "Press 5 for HP4200 Series","") IF @error = 1 then MsgBox(0, "Closing", "Good Bye") Exit Endif ;Carry out task IF $driver = "1" Then;HP5M $drv = "\\XP-W2k\lj456p5.inf";put the network path to the drivers here. $dis = "HP LaserJet 5M" ElseIf $driver = "2" Then; HP4000TN $drv = "\\WINXP-2K\PCL 5e driver\HP4000P5.INF" $dis = "HP LaserJet 4000 Series PCL 5e" ElseIf $driver = "3" Then;HP4050TN $drv = "\\\HP\HP 4050tn\W2K\HP001Ip5.inf" $dis = "HP LaserJet 4050 Series PCL 5e" ElseIf $driver = "4" Then;HP4100TN $drv = "\\2K_XP PCL5e\hp4100p5.inf" $dis = "HP LaserJet 4100 PCL 5e" ElseIf $driver = "5" Then;HP4250TN $drv = "\\HP\HP 4250-4350\hpc4200b.inf" $dis = "hp LaserJet 4200 Series PCL 5e" EndIf IniWrite ( $ini, "PRINTER QUE", "Printer", $printer ) IniWrite ( $ini, "PRINTER IP", "IP", $ip) IniWrite ( $ini, "PRINTER DRIVERS", "Driver", $drv ) IniWrite ( $ini, "PRINTER DISCRIPTION", "Discription", $dis ) MsgBox( 64, "Ini Creation", $ini & " has been created successfully") THE PRINTER CODE #include <file.au3> ;Read INI File $que = IniRead( "printer.ini", "PRINTER QUE", "Printer", "") $ip = iniread("printer.ini", "PRINTER IP", "IP" ,"") $driver = IniRead( "printer.ini", "PRINTER DRIVERS", "Driver", "") $description = IniRead("printer.ini", "PRINTER DISCRIPTION", "Discription","") ;Command string to run from INI file $info = 'rundll32 printui.dll,PrintUIEntry /if /b ' & '"' & $que & '" /f "' & $driver & '" /r "' & "IP_" & $ip & '" /m "' & $description & '" /z' ;Create *.vbs File From INI _FileCreate(@TempDir & "\" & $que & ".vbs") ;name of the file to open $file = @TempDir & "\" & $que & ".vbs" $open = FileOpen($file, 0) ; Check if file opened for writing OK If $open = -1 Then MsgBox(0, "Error", "Unable to open file from Temp directory.") Else FileWriteLine($file,'Set objWMIService = GetObject("winmgmts:")') FileWriteLine($file, 'Set objNewPort = objWMIService.Get _') FileWriteLine($file, '("Win32_TCPIPPrinterPort").SpawnInstance_') FileWriteLine($file, 'objNewPort.Name = ' & '"IP_' & $ip & '"') FileWriteLine($file, 'objNewPort.Protocol = 1') FileWriteLine($file, 'objNewPort.HostAddress = ' & '"' & $ip & '"' ) FileWriteLine($file, 'objNewPort.PortNumber = "9100"') FileWriteLine($file, 'objNewPort.SNMPEnabled = False') FileWriteLine($file, 'objNewPort.Put_') ;Run Install $destination = "sscreen.gif" SplashImageOn("Installing printer " & $que, $destination, 272, 167,300,100,16) RunWait(@ComSpec & " /c " & $file,"", @SW_HIDE) RunWait(@ComSpec & " /c " & $info,"", @SW_HIDE) Sleep(500) SplashOff() MsgBox(64,"Printer", "Printer has installed correctly") Exit EndIf There is some more I want to do to this. I need some kind of error control to verify that the printer was installed correctly. Any ideas or thoughts on this would greatly be appreciated. Let me know if anyone has any questions.1 point