Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/01/2018 in all areas

  1. jguinch

    Printers Management UDF

    Hello. I did create these few functions several months ago. I post here, if it can interest someone. These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code. Here is the list of the available functions : _PrintMgr_AddLocalPort _PrintMgr_AddLPRPort _PrintMgr_AddPrinter _PrintMgr_AddPrinterDriver _PrintMgr_AddTCPIPPrinterPort _PrintMgr_AddWindowsPrinterConnection _PrintMgr_CancelAllJobs _PrintMgr_CancelPrintJob _PrintMgr_EnumPorts _PrintMgr_EnumPrinter _PrintMgr_EnumPrinterConfiguration _PrintMgr_EnumPrinterDriver _PrintMgr_EnumPrinterProperties _PrintMgr_EnumPrintJobs _PrintMgr_EnumTCPIPPrinterPort _PrintMgr_Pause _PrintMgr_PortExists _PrintMgr_PrinterExists _PrintMgr_PrinterSetComment _PrintMgr_PrinterSetDriver _PrintMgr_PrinterSetPort _PrintMgr_PrinterShare _PrintMgr_PrintTestPage _PrintMgr_RemoveLocalPort _PrintMgr_RemoveLPRPort _PrintMgr_RemovePrinter _PrintMgr_RemovePrinterDriver _PrintMgr_RemoveTCPIPPrinterPort _PrintMgr_RenamePrinter _PrintMgr_Resume _PrintMgr_SetDefaultPrinter And some examples : #include <Array.au3> #include "PrintMgr.au3" _Example() Func _Example() ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @ScriptDir & "\Samsung5010", @ScriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers Local $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration Local $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers Local $aDriverList = _PrintMgr_EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _PrintMgr_AddLocalPort("c:\temp\output.pcl") ; Remove the local port _PrintMgr_RemoveLocalPort("c:\temp\output.pcl") ; Enum a print job Local $aJobList = _PrintMgr_EnumPrintJobs() _ArrayDisplay($aJobList) EndFunc ;==>_Example Download link : PrintMgr_Example.au3 PrintMgr.au3
    1 point
  2. In my opinion, I posted a previous version years ago, but I could not find anything. So here for you: With GroupEx.au3 you can create another kind of group controls. It is a collection of labels, which is returned as a structure, consisting of the following elements: .Text = title text .Left = left side of border .TopL = top side of border - left from title .TopR = top side of border - right from title .Right = right side of border .Bottom = bottom side of border .Background = area inside the borders Functions: _GuiCtrlGroup_Create - Creates a group control as collection of labels _GuiCtrlGroup_Close - Closes a group (new in v0.10) _GuiCtrlGroup_Set - Changes values of a _GuiCtrlGroup_Create() created control. _GuiCtrlGroup_SetState - Changes the state of a _GuiCtrlGroup_Create() created control. - Style The title text can have normal or italic style. I did not use style bold, font and size because it would destroy the arithmetic of the group. Underlined or striked style is not usefull for title. - Colors For each element of the structure you can set different colors. The title has by default as back color $GUI_BKCOLOR_TRANSPARENT. You can change this color too, but it looks not so nice. - Movement You can move the group (absolute or relative to the parent) and the controls inside too (passed as array of ID). - State You can change the state of a group ($GUI_SHOW, $GUI_HIDE, $GUI_ENABLE, $GUI_DISABLE) and the state for all controls inside too (passed as array of ID). If setting to DISABLE, you can set the title and background colors for this state. The previous colors will returned as structure. You can use them for ENABLE again. If you use DISABLE without colors, the defaults will used (see constants on top of the script). EDIT 02.06.2018 NEW: - Now non-native controls (e.g. _GUICtrlComboBox_Create) are also taken into account when moving and setting the status. - Function _GuiCtrlGroup_Close to close a group. FIXED: Error after disabling / enabling - controls inside was'nt clickable EDIT 12.06.2018 v0.13 Some little changes: - The current used color for title and group area will stored in the group-structure in the moment, you set to disable. Therefore are the color parameters in the function _GuiCtrlGroup_SetState() optional. - The default disable/enable state uses the system colors. - In functions _GuiCtrlGroup_Set() and _GuiCtrlGroup_SetState() you can pass an array of ID or a single ID variable. GroupEx.au3 v0.13 ;-- TIME_STAMP 2018-06-12 09:01:34 v 0.13 #include-once #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> #include <WinAPI.au3> ; == border color settings Global Const $_GROUPBORDER_LEFT = 0x000001 ; == left border Global Const $_GROUPBORDER_TOPL = 0x000002 ; == top border left from title Global Const $_GROUPBORDER_TOPR = 0x000004 ; == top border right from title Global Const $_GROUPBORDER_TOP = BitOR($_GROUPBORDER_TOPL,$_GROUPBORDER_TOPR) ; == top border Global Const $_GROUPBORDER_RIGHT = 0x000008 ; == right border Global Const $_GROUPBORDER_BOTTOM = 0x000010 ; == bottom border Global Const $_GROUPBORDER_ALL = BitOR($_GROUPBORDER_LEFT,$_GROUPBORDER_TOP,$_GROUPBORDER_RIGHT,$_GROUPBORDER_BOTTOM) ; == full border ; == text settings Global Const $_GROUPTEXT_FORE = 0x000020 ; == sets text fore color Global Const $_GROUPTEXT_BACK = 0x000040 ; == sets text BG-color, should be $GUI_BKCOLOR_TRANSPARENT (default), if Group BG-color is diffent to GUI BG-color or same as Group BG-color Global Const $_GROUPTEXT_TRANS = 0x000080 ; == sets text BG-color to $GUI_BKCOLOR_TRANSPARENT Global Const $_GROUPTEXT_TEXT = 0x000100 ; == sets the title text Global Const $_GROUPTEXT_ITALIC = 0x000200 ; == sets text style to italic Global Const $_GROUPTEXT_DEFAULT = 0x000400 ; == sets text style back to normal Global Const $_GROUPTEXT_LEFT = 0x000800 ; == sets text position to left side (default) Global Const $_GROUPTEXT_CENTER = 0x001000 ; == sets text position centered Global Const $_GROUPTEXT_RIGHT = 0x002000 ; == sets text position to right side ; == background color group Global Const $_GROUPBACKGROUND = 0x004000 ; == sets BG-color inside border area ; == move the whole control Global Const $_GROUP_MOVE_ABS = 0x008000 ; == give param as array [x,y,width,height], values that should not change set to "*" ; you can also give values as comma seperated string: "x,y,width,height" ; y,width,height by default has value "*", so you can omit them if not need to change Global Const $_GROUP_MOVE_REL = 0x010000 ; == same as before, but given values relative to current position/size ; == default disabling colors Global Const $_GROUP_DISABLE_BGDEF = 0xFAFAFA ; == the default background color value, if disabling the group Global Const $_GROUP_DISABLE_TXTDEF = _WinAPI_GetSysColor($COLOR_GRAYTEXT) ; == the default title color value, if disabling the group ; == get system metrics Global $_giTop, $_giSide __SystemGetWindowBorder($_giTop, $_giSide) ; == get system colors Global Const $_giActiveWindowBG = _WinAPI_GetSysColor($COLOR_WINDOW) Global Const $_giEnabledText = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) Global Const $_giActiveBorder = _WinAPI_GetSysColor($COLOR_ACTIVEBORDER) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GuiCtrlGroup_Create ; Description ...: Creates a group control as collection of labels ; Syntax ........: _GuiCtrlGroup_Create($_sText, $_iX, $_iY, $_iWidth, $_iHeight[, $_iBorderCol = -1[, $_iForeCol = -1[, ; $_iBackCol = -1[, $_iTitleParam=$_GROUPTEXT_LEFT]]]]) ; Parameters ....: $_hGui - GUI, where the group is still create ; $_sText - Titel ; $_iX - x position ; $_iY - y position, its the value for top of the title - border starts at: y +7 ; $_iWidth - width ; $_iHeight - height, its the height from top of title to bottom border ; $_iBorderCol - [optional] Color for all border elements. Keyword Default = $COLOR_ACTIVEBORDER, -1 = System (invisible) ; $_iForeCol - [optional] Title text color. Default is -1 (System). ; $_iBackCol - [optional] Group area background color. Default is -1 (System). ; $_iTitleParam - [optional] Title align left (default), centered or right or combined with italic style: BitOr($_CONST_ALIGN_, $_GROUPTEXT_ITALIC) ; Because $_GROUPTEXT_LEFT is the default alignment, you can use $_GROUPTEXT_ITALIC alone, to set italic style left aligned. ; Return values .: Structure with IDs of all group elements ; Author ........: BugFix ; =============================================================================================================================== Func _GuiCtrlGroup_Create($_hGui, $_sText, $_iX, $_iY, $_iWidth, $_iHeight, $_iBorderCol=Default, $_iForeCol=-1, $_iBackCol=-1, $_iTitleParam=$_GROUPTEXT_LEFT) $_iY += 7 Local $guiTmp = GUICreate('TEMP') Local $idText, $aSize[1] If $_sText <> '' Then $idText = GUICtrlCreateLabel(' ' & $_sText, 0, 0) $aSize = ControlGetPos($guiTmp, '', $idText) GUICtrlDelete($idText) Else ReDim $aSize[3] $aSize[2] = 0 EndIf GUISwitch($_hGui) GUIDelete($guiTmp) If $aSize[2] > $_iWidth -12 Then $aSize[2] = $_iWidth -12 Local $dLeft = 10 If $aSize[2] > 0 Then Switch $_iTitleParam Case $_GROUPTEXT_CENTER $dLeft = Int(($_iWidth-$aSize[2])/2) Case $_GROUPTEXT_RIGHT $dLeft = $_iWidth-10-$aSize[2] EndSwitch EndIf Local $idBG = GUICtrlCreateLabel('', $_iX+1, $_iY+1, $_iWidth-2, $_iHeight-2-7) If $_iBackCol > -1 Then GUICtrlSetBkColor($idBG, $_iBackCol) GUICtrlSetState($idBG, $GUI_DISABLE) Local $idLeft = GUICtrlCreateLabel('', $_iX, $_iY, 1, $_iHeight-7) Local $idTopL = GUICtrlCreateLabel('', $_iX+1, $_iY, $dLeft-1, 1) Local $idTopR = GUICtrlCreateLabel('', $_iX+$dLeft+$aSize[2], $_iY, $_iWidth-$aSize[2]-$dLeft, 1) Local $idRight = GUICtrlCreateLabel('', $_iX+$_iWidth, $_iY, 1, $_iHeight-7) Local $idBottom = GUICtrlCreateLabel('', $_iX+1, $_iY+$_iHeight-7, $_iWidth, 1) If IsKeyword($_iBorderCol) Then $_iBorderCol = $_giActiveBorder If $_iBorderCol > -1 Then GUICtrlSetBkColor($idLeft, $_iBorderCol) GUICtrlSetBkColor($idTopL, $_iBorderCol) GUICtrlSetBkColor($idTopR, $_iBorderCol) GUICtrlSetBkColor($idRight, $_iBorderCol) GUICtrlSetBkColor($idBottom, $_iBorderCol) EndIf If $_sText <> '' Then $_sText = ' ' & $_sText $idText = GUICtrlCreateLabel($_sText, $_iX+$dLeft, $_iY-7, $aSize[2], 17) GUICtrlSetBkColor($idText, $GUI_BKCOLOR_TRANSPARENT) If BitAND($_iTitleParam, $_GROUPTEXT_ITALIC) Then GUICtrlSetFont($idText, Default, Default, 2) EndIf If $_iForeCol > -1 Then GUICtrlSetColor($idText, $_iForeCol) Local $tagGROUP = "int Text;int Left;int TopL;int TopR;int Right;int Bottom;int Background;int Align;int BGPrev;int TextPrev;" Local $tGROUP = DllStructCreate($tagGROUP) $tGROUP.Text = $idText $tGROUP.Left = $idLeft $tGROUP.TopL = $idTopL $tGROUP.TopR = $idTopR $tGROUP.Right = $idRight $tGROUP.Bottom = $idBottom $tGROUP.Background = $idBG $tGROUP.Align = BitXOR($_iTitleParam, $_GROUPTEXT_ITALIC) $tGROUP.BGPrev = ($_iBackCol = -1 ? $_giActiveWindowBG : $_iBackCol) $tGROUP.TextPrev = ($_iForeCol = -1 ? $_giEnabledText : $_iForeCol) GUIStartGroup() Return $tGROUP EndFunc ;==>_GuiCtrlGroup_Create ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GuiCtrlGroup_Close ; Description ...: Starts a new group and so the previous group will closed ; Syntax ........: _GuiCtrlGroup_Close() ; Return values .: None ; Note ..........: Only required, if outside the group radio buttons following. But it can used to close each group. ; Author ........: BugFix ; =============================================================================================================================== Func _GuiCtrlGroup_Close() GUIStartGroup() EndFunc ;==>_GuiCtrlGroup_Close ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GuiCtrlGroup_Set ; Description ...: Changes values of a _GuiCtrlGroup_Create() created control. ; Syntax ........: _GuiCtrlGroup_Set(ByRef $_structGroup, $_vValue, $_constFlag, $_aCtrlInside) ; Parameters ....: $_structGroup - Return value from _GuiCtrlGroup_Create() ; $_vValue - The new value, maybe an empty string with some flag. ; $_constFlag - The const to identify the action (see constants at top) ; $_aCtrlInside - [optional] With action flag $_GROUP_MOVE_ABS/$_GROUP_MOVE_REL you can give an array of controls ; (or a single control variable) inside this group. This controls will moved too with the delta x/y values. ; Return values .: None ; Author ........: BugFix ; =============================================================================================================================== Func _GuiCtrlGroup_Set(ByRef $_structGroup, $_vValue, $_constFlag, $_aCtrlInside= Null) Local $hWndGui = _WinAPI_GetParent(GUICtrlGetHandle($_structGroup.Background)) Local $idText = $_structGroup.Text Local $idLeft = $_structGroup.Left Local $idTopL = $_structGroup.TopL Local $idTopR = $_structGroup.TopR Local $idRight = $_structGroup.Right Local $idBottom = $_structGroup.Bottom Local $idBackground = $_structGroup.Background Local $iAlign = $_structGroup.Align Local $aSize, $aBott, $sTitle If BitAND($_constFlag, $_GROUPBORDER_LEFT) Then GUICtrlSetBkColor($idLeft, $_vValue) If BitAND($_constFlag, $_GROUPBORDER_TOPL) Then GUICtrlSetBkColor($idTopL, $_vValue) If BitAND($_constFlag, $_GROUPBORDER_TOPR) Then GUICtrlSetBkColor($idTopR, $_vValue) If BitAND($_constFlag, $_GROUPBORDER_RIGHT) Then GUICtrlSetBkColor($idRight, $_vValue) If BitAND($_constFlag, $_GROUPBORDER_BOTTOM) Then GUICtrlSetBkColor($idBottom, $_vValue) If BitAND($_constFlag, $_GROUPBACKGROUND) Then GUICtrlSetBkColor($idBackground, $_vValue) $_structGroup.BGPrev = $_vValue EndIf If BitAND($_constFlag, $_GROUPTEXT_FORE) Then GUICtrlSetColor($idText, $_vValue) $_structGroup.TextPrev = $_vValue EndIf If BitAND($_constFlag, $_GROUPTEXT_BACK) Then GUICtrlSetBkColor($idText, $_vValue) If BitAND($_constFlag, $_GROUPTEXT_TRANS) Then GUICtrlSetBkColor($idText, $GUI_BKCOLOR_TRANSPARENT) If BitAND($_constFlag, $_GROUPTEXT_ITALIC) Then GUICtrlSetFont ($idText, Default, Default, 2) If BitAND($_constFlag, $_GROUPTEXT_DEFAULT) Then GUICtrlSetFont ($idText, Default, Default, Default) If BitAND($_constFlag, BitOR($_GROUPTEXT_LEFT,$_GROUPTEXT_CENTER,$_GROUPTEXT_RIGHT,$_GROUPTEXT_TEXT)) Then $aSize = ControlGetPos($hWndGui, '', $idLeft) $aBott = ControlGetPos($hWndGui, '', $idBottom) Local $x = $aSize[0], $y = $aSize[1] If $_vValue = '' Then If BitAND($_constFlag, BitOR($_GROUPTEXT_LEFT,$_GROUPTEXT_CENTER,$_GROUPTEXT_RIGHT)) Then $aSize = ControlGetPos($hWndGui, '', $idText) Else $aSize[2] = 0 EndIf Else Local $guiTmp = GUICreate('') GUISwitch($guiTmp) Local $idTmp = GUICtrlCreateLabel(' ' & $_vValue, 0, 0) $aSize = ControlGetPos($guiTmp, '', $idTmp) GUICtrlDelete($idTmp) GUISwitch($hWndGui) GUIDelete($guiTmp) EndIf Local $dLeft = 10 If $aSize[2] > $aBott[2] -12 Then $aSize[2] = $aBott[2] -12 If $aSize[2] > 0 Then If BitAND($_constFlag, $_GROUPTEXT_CENTER) Then $dLeft = Int(($aBott[2]-$aSize[2])/2) If BitAND($_constFlag, $_GROUPTEXT_RIGHT) Then $dLeft = $aBott[2]-10-$aSize[2] EndIf GUICtrlSetPos($idTopL, $x+1, $y, $dLeft-1, 1) GUICtrlSetPos($idTopR, $x+$dLeft+$aSize[2], $y, $aBott[2]+2-$aSize[2]-$dLeft, 1) GUICtrlSetPos($idText, $x+$dLeft, $y-7, $aSize[2], 17) If BitAND($_constFlag, $_GROUPTEXT_TEXT) Then If $_vValue <> '' Then $_vValue = ' ' & $_vValue GUICtrlSetData($idText, $_vValue) EndIf EndIf If BitAND($_constFlag, BitOR($_GROUP_MOVE_ABS,$_GROUP_MOVE_REL)) Then If Not IsArray($_vValue) Then $_vValue = StringSplit($_vValue, ',', 2) If UBound($_vValue) < 4 Then ReDim $_vValue[4] For $i = 1 To 3 If $_vValue[$i] = '' Then $_vValue[$i] = '*' Next EndIf Local $bRel = False If BitAND($_constFlag, $_GROUP_MOVE_REL) Then $bRel = True GUISetState(@SW_LOCK, $hWndGui) Local $aDelta = __SubCtrlMove($hWndGui, $_structGroup, $_vValue, $bRel, $iAlign) ; if an array with controls from inside the group is given - move them too If $_aCtrlInside <> Null Then If Not IsArray($_aCtrlInside) Then Local $aTmp[1] = [$_aCtrlInside] $_aCtrlInside = $aTmp EndIf Local $aSize, $dX = $aDelta[0], $dY = $aDelta[1], $bhWnd, $opt = AutoitSetOption('GUICoordMode', 1) For $i = 0 To UBound($_aCtrlInside) -1 $bhWnd = False If IsHWnd($_aCtrlInside[$i]) Then $bhWnd = True $aSize = WinGetPos($_aCtrlInside[$i]) Else $aSize = ControlGetPos($hWndGui, '', $_aCtrlInside[$i]) EndIf __ControlMove($hWndGui, $bhWnd, $_aCtrlInside[$i], $aSize, $dX, $dY) Next AutoitSetOption('GUICoordMode', $opt) EndIf GUISetState(@SW_UNLOCK, $hWndGui) EndIf DllCall("user32.dll", "bool", "RedrawWindow", "hwnd", $hWndGui, "struct*", 0, "handle", 0, "uint", 5) EndFunc ;==>_GuiCtrlGroup_Set ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GuiCtrlGroup_SetState ; Description ...: Changes the state of a _GuiCtrlGroup_Create() created control. ; Syntax ........: _GuiCtrlGroup_SetState(ByRef $_structGroup, $_iState, $_aCtrlInside, $_iTxtColor, $_iBGColor) ; Parameters ....: $_structGroup - Return value from _GuiCtrlGroup_Create() ; $_iState - The new state ($GUI_SHOW, $GUI_HIDE, $GUI_ENABLE, $GUI_DISABLE) ; $_aCtrlInside - [optional] When you pass an array of controls (or a single control variable), they are set to the same state as the group itself. ; $_iTxtColor - [optional] The title color if set to disable/enable. With 'Null' the default/previous color will used. "-1" uses the system color. ; $_iBGColor - [optional] The background color if set to disable/enable. With 'Null' the default/previous color will used. "-1" uses the system color. ; Return values .: Failure - returns -1, sets @error = 1 (Wrong state value) ; Author ........: BugFix ; =============================================================================================================================== Func _GuiCtrlGroup_SetState(ByRef $_structGroup, $_iState, $_aCtrlInside=Null, $_iTxtColor=Null, $_iBGColor=Null) If Not BitAND(BitOR($GUI_SHOW, $GUI_HIDE, $GUI_ENABLE, $GUI_DISABLE), $_iState) Then Return SetError(1,0,-1) Local Static $aState[4][2] = [[$GUI_SHOW, @SW_SHOW], [$GUI_HIDE, @SW_HIDE], [$GUI_ENABLE, @SW_ENABLE], [$GUI_DISABLE, @SW_DISABLE]] Local $hWndGui = _WinAPI_GetParent(GUICtrlGetHandle($_structGroup.Background)) Switch $_iState ; select the colors to set in the new state Case $GUI_DISABLE If $_iTxtColor = Null Then $_iTxtColor = $_GROUP_DISABLE_TXTDEF If $_iBGColor = Null Then $_iBGColor = $_GROUP_DISABLE_BGDEF Case $GUI_ENABLE If $_iTxtColor = Null Then $_iTxtColor = $_structGroup.TextPrev If $_iBGColor = Null Then $_iBGColor = $_structGroup.BGPrev $_structGroup.TextPrev = ($_iTxtColor = -1 ? $_giEnabledText : $_iTxtColor) $_structGroup.BGPrev = ($_iBGColor = -1 ? $_giActiveWindowBG : $_iBGColor) EndSwitch GUISetState(@SW_LOCK, $hWndGui) GuiCtrlSetState($_structGroup.Text, $_iState) If $_iState = $GUI_SHOW Or $_iState = $GUI_HIDE Then GuiCtrlSetState($_structGroup.Left, $_iState) GuiCtrlSetState($_structGroup.TopL, $_iState) GuiCtrlSetState($_structGroup.TopR, $_iState) GuiCtrlSetState($_structGroup.Right, $_iState) GuiCtrlSetState($_structGroup.Bottom, $_iState) GuiCtrlSetState($_structGroup.Background, $_iState) EndIf If $_aCtrlInside <> Null Then If Not IsArray($_aCtrlInside) Then Local $aTmp[1] = [$_aCtrlInside] $_aCtrlInside = $aTmp EndIf Local $iWinState For $i = 0 To UBound($aState) -1 If $aState[$i][0] = $_iState Then $iWinState = $aState[$i][1] ExitLoop EndIf Next For $i = 0 To UBound($_aCtrlInside) -1 If IsHWnd($_aCtrlInside[$i]) Then WinSetState($_aCtrlInside[$i], '', $iWinState) Else GuiCtrlSetState($_aCtrlInside[$i], $_iState) EndIf Next EndIf If $_iTxtColor <> Null Then GUICtrlSetColor($_structGroup.Text, $_iTxtColor) If $_iBGColor <> Null Then GUICtrlSetBkColor($_structGroup.Background, $_iBGColor) GUISetState(@SW_UNLOCK, $hWndGui) DllCall("user32.dll", "bool", "RedrawWindow", "hwnd", $hWndGui, "struct*", 0, "handle", 0, "uint", 5) EndFunc ;==>_GuiCtrlGroup_SetState ; == for internal use Func __SubCtrlMove($_hGui, ByRef $_structGroup, $_aVal, $_bRel=False, $_iAlign=$_GROUPTEXT_LEFT) Local $idText = $_structGroup.Text Local $idLeft = $_structGroup.Left Local $idTopL = $_structGroup.TopL Local $idTopR = $_structGroup.TopR Local $idRight = $_structGroup.Right Local $idBottom = $_structGroup.Bottom Local $idBackground = $_structGroup.Background Local $dX, $dY, $dW, $dH Local $aSize = ControlGetPos($_hGui, '', $idLeft) Local $aBott = ControlGetPos($_hGui, '', $idBottom) If $_bRel Then $dX = $_aVal[0] $dY = $_aVal[1] $dW = $_aVal[2] $dH = $_aVal[3] If $dX = '*' Then $dX = 0 If $dY = '*' Then $dY = 0 If $dW = '*' Then $dW = 0 If $dH = '*' Then $dH = 0 Else Local $x = $_aVal[0] Local $y = $_aVal[1] Local $width = $_aVal[2] Local $height = $_aVal[3] Local $x0 = $aSize[0] Local $y0 = $aSize[1] -7 Local $width0 = $aBott[2] Local $height0 = $aSize[3] +7 If $x = '*' Then $x = $x0 If $y = '*' Then $y = $y0 If $width = '*' Then $width = $width0 If $height = '*' Then $height = $height0 $dX = $x - $x0 $dY = $y - $y0 $dW = $width - $width0 $dH = $height - $height0 EndIf GUICtrlSetPos($idLeft, $aSize[0]+($dX), $aSize[1]+($dY), 1, $aSize[3]+($dH)) GUICtrlSetPos($idBottom, $aBott[0]+($dX), $aBott[1]+($dY)+($dH), $aBott[2]+($dW)) $aSize = ControlGetPos($_hGui, '', $idTopL) GUICtrlSetPos($idTopL, $aSize[0]+($dX), $aSize[1]+($dY)) $aSize = ControlGetPos($_hGui, '', $idTopR) GUICtrlSetPos($idTopR, $aSize[0]+($dX), $aSize[1]+($dY), $aSize[2]+($dW)) $aSize = ControlGetPos($_hGui, '', $idRight) GUICtrlSetPos($idRight, $aSize[0]+($dX)+($dW), $aSize[1]+($dY), 1, $aSize[3]+($dH)) $aSize = ControlGetPos($_hGui, '', $idBackground) GUICtrlSetPos($idBackground, $aSize[0]+($dX), $aSize[1]+($dY), $aSize[2]+($dW), $aSize[3]+($dH)) $aSize = ControlGetPos($_hGui, '', $idText) If ($dX <> 0) Or ($dY <> 0) Then GUICtrlSetPos($idText, $aSize[0]+($dX), $aSize[1]+($dY)) If $dW <> 0 Then _GuiCtrlGroup_Set($_structGroup, '', $_structGroup.Align) Local $aDelta[] = [$dX,$dY] Return $aDelta EndFunc ;==>__SubCtrlMove Func __ControlMove($_hWnd, $_bhWnd, $_vCtrl, $_aSize, $_dX, $_dY) Local $aParent If Not $_bhWnd Then GUICtrlSetPos($_vCtrl, $_aSize[0]+($_dX), $_aSize[1]+($_dY)) Else $aParent = WinGetPos($_hWnd) WinMove($_vCtrl, '', $_aSize[0]-$aParent[0]-$_giSide+($_dX), $_aSize[1]-$aParent[1]-$_giTop+($_dY)) EndIf EndFunc ;==>__ControlMove ;=============================================================================== ; Function Name....: __SystemGetWindowBorder ; Description......: Calculates side and top border of window ; Author(s)........: BugFix ;=============================================================================== Func __SystemGetWindowBorder(ByRef $_iTopBorder, ByRef $_iSideBorder) Local Const $SM_CYCAPTION = 4, $SM_CYEDGE = 46, $SM_CYBORDER = 6, $SM_CXBORDER = 5, $SM_CXEDGE = 45 Local $aMetrics[5][2] = [[$SM_CYCAPTION], [$SM_CYEDGE], [$SM_CYBORDER], [$SM_CXBORDER], [$SM_CXEDGE]] Local $dll = DllOpen("user32.dll"), $aRet For $i = 0 To 4 $aRet = DllCall($dll, "int", "GetSystemMetrics", "int", $aMetrics[$i][0]) If IsArray($aRet) Then $aMetrics[$i][1] = $aRet[0] Next DllClose($dll) $_iTopBorder = $aMetrics[0][1] + $aMetrics[1][1] + $aMetrics[2][1] $_iSideBorder = $aMetrics[3][1] + $aMetrics[4][1] EndFunc ;==>__SystemGetWindowBorder Example #include 'GroupEx.au3' #include <GuiComboBox.au3> Global $iGUIColor = 0xFFF9E5 Global $iBGColor = 0xE0F9FF, $iBorderColor = 0x00008B, $iTextColor = 0xC60707 Enum $lbName, $inName, $lbStatus, $inStatus, $lbOrt, $inOrt, $cbNormal, $lbNormal, $combo, $radio1, $radio2, $iCount Global $aID[$iCount] Global $radio3, $radio4 Global $hGui = GUICreate('Example GroupEx', 900, 700) GUISetBkColor($iGUIColor) ; create group with title style italic, default align left Global $tGroup1 = _GuiCtrlGroup_Create($hGui, 'Device Information', 10, 55, 880, 155, $iBorderColor, $iTextColor, $iBGColor, $_GROUPTEXT_ITALIC) $aID[$lbName] = GUICtrlCreateLabel('Title', 25, 83, 70) _BKTrans(-1) $aID[$inName] = GUICtrlCreateInput('', 100, 80, 200, 21) $aID[$lbStatus] = GUICtrlCreateLabel('State', 310, 83, 40) _BKTrans(-1) $aID[$inStatus] = GUICtrlCreateInput('', 355, 80, 115, 21) $aID[$lbOrt] = GUICtrlCreateLabel('Location', 485, 83, 50) _BKTrans(-1) $aID[$inOrt] = GUICtrlCreateInput('', 535, 80, 100, 21) $aID[$cbNormal] = GUICtrlCreateCheckbox(' ', 655, 83, 13, 13) $aID[$lbNormal] = GUICtrlCreateLabel(' Current Sample', 670, 83) _BKTrans(-1) $aID[$combo] = _GUICtrlComboBox_Create($hGui, '', 100, 110, 200, 30) $aID[$radio1] = GUICtrlCreateRadio(' ', 320, 113, 13, 13) GUICtrlSetState(-1, $GUI_CHECKED) $aID[$radio2] = GUICtrlCreateRadio(' ', 340, 113, 13, 13) _GuiCtrlGroup_Close() $radio3 = GUICtrlCreateRadio(' ', 100, 350, 13, 13) GUICtrlSetState(-1, $GUI_CHECKED) $radio4 = GUICtrlCreateRadio(' ', 120, 350, 13, 13) GUISetState() _Msg('Move group downward by 100px with all internal controls ($aID)') _GuiCtrlGroup_Set($tGroup1, '*,100', $_GROUP_MOVE_REL, $aID) _Msg('Group title - set default style') _GuiCtrlGroup_Set($tGroup1, '', $_GROUPTEXT_DEFAULT) _Msg('Group title - set background color - feasible, but not so nice') _GuiCtrlGroup_Set($tGroup1, 0xAAAAFF, $_GROUPTEXT_BACK) _Msg('Group title - set background again transparency') _GuiCtrlGroup_Set($tGroup1, '', $_GROUPTEXT_TRANS) _Msg('Group title - set text color') _GuiCtrlGroup_Set($tGroup1, 0x000080, $_GROUPTEXT_FORE) _Msg('Group border - top and right - change color') _GuiCtrlGroup_Set($tGroup1, 0xFF1234, BitOR($_GROUPBORDER_TOP,$_GROUPBORDER_RIGHT)) _Msg('Group title - centered') _GuiCtrlGroup_Set($tGroup1, '', $_GROUPTEXT_CENTER) _Msg('Group title - right') _GuiCtrlGroup_Set($tGroup1, '', $_GROUPTEXT_RIGHT) ConsoleWrite('CREATION BG: ' & $tGroup1.BGPrev & ', hex: 0x' & Hex($tGroup1.BGPrev,6) & @CRLF) _Msg('Group area - change color') _GuiCtrlGroup_Set($tGroup1, 0xAAFFAA, $_GROUPBACKGROUND) _Msg('Group DISABLE (with all controls inside), border color and title BGColor stay unchanged') ; _GuiCtrlGroup_SetState(ByRef $_structGroup, $_iState, $_aCtrlInside=Null, $_iTxtColor=Null, $_iBGColor=Null) ; Here, the current color of title text and group area is stored before the disable color is set. ; With Null for colors, the defaults will used. _GuiCtrlGroup_SetState($tGroup1, $GUI_DISABLE, $aID) _Msg('Group ENABLE (with all controls inside)') _GuiCtrlGroup_SetState($tGroup1, $GUI_ENABLE, $aID) ; without color parameter, the previous colors will used ;~ _GuiCtrlGroup_SetState($tGroup1, $GUI_ENABLE, $aID, Null, 0xAAAAFF) ; you can change the title and group area (BG) color (to omit one, use Null) _Msg('Group HIDE (with all controls inside)') _GuiCtrlGroup_SetState($tGroup1, $GUI_HIDE, $aID) _Msg('Group SHOW (with all controls inside)') _GuiCtrlGroup_SetState($tGroup1, $GUI_SHOW, $aID) Do Until GUIGetMsg() = -3 Func _BKTrans($_iID) GUICtrlSetBkColor($_iID, $GUI_BKCOLOR_TRANSPARENT) EndFunc Func _Msg($_sMsg) MsgBox(262208, 'Action', $_sMsg, 5) EndFunc GroupEx[0.13].au3
    1 point
  3. Also beware that extensions may be present or not and aren't limited to 3 chars.
    1 point
  4. Well, that brings up the question of what you're trying to accomplish. Where possible, you do not want to mix languages. It would be best to convert the vbscript to autoit. As far as the executable, is this a system exe or a compiled script? The more you can share about your end goal, the more assistance we can provide
    1 point
  5. So then yes, _FileWriteFromArray would be the simplest way to go.
    1 point
  6. @nacerbaaziz When posting code, use the code tag (<>) in the format bar. It makes it much easier to read and provides links to the help file for recognized commands. if $CMDLine[0] = 0 then msgBox(16, "error", "you don't selecte any files") exit else for $i = 1 to $CMDLine[0] msgBox(0, "files", $CMDLine[$i] next endIf exit
    1 point
  7. What format do you want it in (excel, notepad, etc?). $path is an Array, so you can't write it to the console.
    1 point
  8. jchd

    StringRegExp Question

    Another way, scanning the subject string only once: Local $s = "fhui +17 to Charisma -25 to fhkl +43 to me +51 to Charisma +16 to Charisma" Local $max = 0 $max = Int(Execute(StringRegExpReplace($s, "(?:.*?)\+(\d\d) to Charisma", "($1 > $max ? - $max + Assign('max', $1) - 1 + $max : 0) + ") & "0")) ConsoleWrite($max & @LF) A rare use of Assign().
    1 point
  9. A comment to your code: You cannot use GUICtrlRead() in a Case statement in the message loop. You can only use control IDs and the 11 system events. So you want incremental search. That's more complicated. You need a WM_COMMAND message handler. See this section in the Wiki. I've used ConsoleWrites in the code, so run the code in SciTE with F5: #RequireAdmin #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <File.au3> local Const $Path = @ScriptDir Dim $Parent[3] Dim $Child[15] local $Count = 0 ;Create GUI local $GUI = GUICreate("TreeView") GUISetState(@SW_SHOW) ; Create InputBox local $Input = GUICtrlCreateInput("",100,25) Local $idInputChange = GUICtrlCreateDummy() ; Crete TreeViewObject local $TreeObject = GUICtrlCreateTreeView(100,70,200,250) ;Create Tree Parent for $i = 0 to UBound($Parent) - 1 $Parent[$i] = GUICtrlCreateTreeViewItem("Parent " & $i, $TreeObject) ConsoleWrite( "Parent " & $i & @CRLF ) ;Add Child to Parents for $j = 0 to 4 $Child[$Count] = GUICtrlCreateTreeViewItem("Child " & $Count, $Parent[$i]) ConsoleWrite( " Child " & $Count & @CRLF ) $Count += 1 Next ConsoleWrite( @CRLF ) Next ConsoleWrite( "Search for 0 - 14" & @CRLF & @CRLF ) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") while 1 Switch GUIGetMsg() ; Search in InputBox ; Search for 0 - 14 Case $idInputChange $InputText = GUICtrlRead($Input) if $InputText <> "" Then ConsoleWrite( "$InputText = [" & $InputText & "]" & @CRLF ) Local $iMatches = 0, $sMatches = "" for $i = 0 to UBound($Child) - 1 if StringInStr(GUICtrlRead($Child[$i],1), $InputText) <> 0 Then $iMatches += 1 $sMatches &= GUICtrlRead($Child[$i],1) & @CRLF EndIf Next ConsoleWrite( "Number of matches = " & $iMatches & @CRLF ) If $sMatches Then ConsoleWrite( $sMatches ) ConsoleWrite( @CRLF ) EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF) ; LoWord - this gives the control which sent the message Local $iCode = BitShift($wParam, 16) ; HiWord - this gives the message that was sent If $iCode = $EN_CHANGE Then ; If we have the correct message Switch $iIDFrom ; See if it comes from one of the inputs Case $Input GUICtrlSendToDummy( $idInputChange ) EndSwitch EndIf EndFunc ;==>MY_WM_COMMAND
    1 point
  10. See faq 31. Post also information of au3inf or other spy tools. Check functions like winwait instead of sleep. First test the basics on calc or notepad in help file examples so then you can apply same on your window.
    1 point
  11. Maybe you'd rather use a fixed string format else leading zeroes will evaporate: ConsoleWrite(StringFormat("%02i0308%02i", @HOUR + 1, @MIN + 1) & @LF)
    1 point
  12. RunWait pauses your script until fsplit.exe has finished, so i suggest using the style Marquee for the progressbar. Here a small example: #include <GUIConstantsEx.au3> #include <SendMessage.au3> #include <ProgressConstants.au3> $Form1 = GUICreate("Form1", 545, 125, 5, 5);, $WS_POPUP, $WS_EX_TOOLWINDOW) $Button1 = GUICtrlCreateButton('&STOP Marquee', 5, 5, 200) $Timer = GUICtrlCreateLabel('Zeit: ', 470, 5, 70) $Progress1 = GUICtrlCreateProgress(0, 95, 545, 25, $PBS_MARQUEE) $hProgress = GUICtrlGetHandle($Progress1) _SendMessage($hProgress, $PBM_SETMARQUEE, True, 10) GUISetState(@SW_SHOW) $dtStart = TimerInit() AdlibRegister('Timer', 1000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 If GUICtrlRead($Button1) = '&STOP Marquee' Then _SendMessage($hProgress, $PBM_SETMARQUEE, False, 10) GUICtrlSetData($Button1, '&Resume Marquee') Else _SendMessage($hProgress, $PBM_SETMARQUEE, True, 10) GUICtrlSetData($Button1, '&STOP Marquee') EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Timer() Local $Time = TimerDiff($dtStart) / 1000 Local $HOUR = Int($Time / 3600) Local $MIN = Int(($Time - $HOUR * 3600) / 60) Local $SEC = $Time - $HOUR * 3600 - $MIN * 60 GUICtrlSetData($Timer, StringFormat("%02i:%02i:%02i", $HOUR, $MIN, $SEC)) EndFunc ;==>Timer If fsplit in console mode is writing progress to console you can use Run and StdoutRead for updating the real progress.
    1 point
  13. Not sure if I understand but do you mean something like: #include <Timers.au3> While 1 Sleep(10) $idleTimer = _Timer_GetIdleTime() If $idleTimer > 60000 And Not ProcessExists("process.exe") Then ProcessClose("otherprocess.exe") ProcessWaitClose("otherprocess.exe") Run("process.exe") ElseIf $idleTimer < 60001 And Not ProcessExists("otherprocess.exe" Then ProcessClose("process.exe") ProcessWaitClose("process.exe") Run("otherprocess.exe") EndIf WEnd
    1 point
×
×
  • Create New...