Leaderboard
Popular Content
Showing content with the highest reputation on 02/17/2015 in all areas
-
DDEML.au3 - DDE Client + Server
argumentum reacted to doudou for a topic
It's been frequently asked here, but no complete solution provided. Well, now it's here! With DDEML UDF one can use an AutoIt script as a DDE client or server. Version 1.5.4 DDEML: invalid struct declaration in _DdeGetData() fixed DDEML: presence of callback functions checked more thoroughly Version 1.5.3 DDEML: missing _DdeGetData() and _DdeGetDataAsStruct() added DDEML Samples: working XTYP_POKE example added Version 1.5.2 DDEML: references to @ProcessorArch updated to @OSArch DDEML Samples: Opt("OnAutoItExit") replaced with OnAutoItExitRegister() Version 1.5.1 DDEML: _DDEML_CreateDataStruct returning wrong size for UNICODE strings fixed DDEML: _DdeCallback not passing item handle to server in XTYP_ADVREQ and XTYP_REQUEST fixed DDEML Samples: working XTYP_REQUEST example added Version 1.5 (first AutoIt 3.3 compatible release) DDEML: references to @Unicode/@AutoItUnicode replaced with global $_DDEML_UNICODE DDEML: ClipboardConstants.au3 dumped in favor of Clipboard.au3 (shipped with AutoIt) DDEML Samples: obsolete includes replaced Version 1.4 DDEML: ALL global constants are now in DDEMLConstants.au3, other global declarations are checked allowing usage from within OnAutoItStart() DDEMLClient: undeclared local struct fixed Version 1.3 DDEML: Support for built-in DllCallback facilities (AutoIt v 3.2.10) added DDEML: HANDLE type made configurable (64 bit compatibility) DDEML: Constants moved to separate include DDEMLConstants.au3 DDEML: _DdeIsInitialized() added Version 1.2 (AutoIt v 3.1 compatible, disontinued) DDEML: UNICODE support improved Version 1.1 DDEML: Wokraround for server not supporting UNICODE applied DDEML Samples: StatelessDDEGetURL.au3 replaced by StatelessDDEBrowserControl.au3 (2-way communication) Download current version (1.5.4) au3_ddeml_v1.2.zip1 point -
Work_With_Two_process Second version
argumentum reacted to wolf9228 for a topic
The code has been modified ... There is an error using the Int data type where the size of some Internet files is greater than the maximum Int data type Now the UINT64 data type has been used ... Thank you. New In this version - Other method by which to read the memory of the child process without stopping the child process loops As happens when send a message to a child process ,the child process is working non-stop like thread - General improvements to the functionality of the project Two_Process_Library Two_Process_Library_Second.zip Two_Process_Library.au3 #include "Two_Process_Library_Constants.au3" Func Work_With_Two_process($WaitChildProcess = True , $Timeout = 5000) If $CmdLine[0] = 0 Then $PrProcessID = _WinAPI_GetCurrentProcessID() $PrhWnd = GUICreate("",0,0) $UntCallMsg = RegisterWindowMessage("WM_CALLMSG",String($PrhWnd & $PrProcessID),$GlobalPassword) $UntCoueMsg = RegisterWindowMessage("WM_CONTINUE",String($PrhWnd & $PrProcessID),$GlobalPassword) GUIRegisterMsg($UntCallMsg,"CallMsgFunc") GUIRegisterMsg($UntCoueMsg,"ContinueMsgFunc") $Command = "RunChildProcess " & String($PrProcessID) & " " & String($PrhWnd) if (@Compiled) Then Run(FileGetShortName(@AutoItExe) & " " & $Command) Else Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath) & " " & $Command) EndIf if ($WaitChildProcess) Then $begin = TimerInit() While Not ($ChProcessID) And TimerDiff($begin) < $Timeout WEnd EndIf $GlobalParticularProcess = "ParentProcess" Else If ($CmdLine[0] = 3 And $CmdLine[1] == "RunChildProcess") Then Opt("TrayIconHide", 1) $PrProcessID = int($CmdLine[2]) $PrhWnd = HWnd($CmdLine[3]) $ChProcessID = _WinAPI_GetCurrentProcessID() $ChhWnd = GUICreate("",0,0) $UntCallMsg = RegisterWindowMessage("WM_CALLMSG",String($PrhWnd & $PrProcessID),$GlobalPassword) $UntCoueMsg = RegisterWindowMessage("WM_CONTINUE",String($PrhWnd & $PrProcessID),$GlobalPassword) GUIRegisterMsg($UntCallMsg,"CallMsgFunc") GUIRegisterMsg($UntCoueMsg,"ContinueMsgFunc") $RT = _SendMessage($PrhWnd,$UntCoueMsg,1,$ChProcessID) if $RT <> $MsgOk Then Exit $RT = _SendMessage($PrhWnd,$UntCoueMsg,2,$ChhWnd) if $RT <> $MsgOk Then Exit $GlobalParticularProcess = "ChildProcess" Else Exit EndIf EndIf Return $GlobalParticularProcess EndFunc Func IsParentProcessWork($pTime = 5000) if (TimerDiff($pbeginA) < $pTime) Then Return SetError(0,1,True) if ($PrProcessID) And Not ProcessExists($PrProcessID) Then Return SetError(1,0,False) $pbeginA = TimerInit() Return True EndFunc Func IsChildProcessWork($pTime = 5000) if (TimerDiff($pbeginB) < $pTime) Then Return SetError(0,1,True) if ($ChProcessID) And Not ProcessExists($ChProcessID) Then Return SetError(1,0,False) $pbeginB = TimerInit() Return True EndFunc Func CloseParentProcess() Return ProcessClose($PrProcessID) EndFunc Func CloseChildProcess() Return ProcessClose($ChProcessID) EndFunc Func ContinueMsgFunc($hWnd,$Msg,$wParam,$lParam) Select Case $wParam = 1 $ChProcessID = int($lParam) Return $MsgOk Case $wParam = 2 $ChhWnd = HWnd($lParam) Return $MsgOk Case $wParam = 3 Return $MsgOk EndSelect Return 0 EndFunc Func CallFunc($FuncName,$ReturnDirectly,$Param1 = 0,$Param2 = 0 ,$Param3 = 0 , _ $Param4 = 0 ,$Param5 = 0 ,$Param6 = 0 ,$Param7 = 0 ,$Param8 = 0 ,$Param9 = 0 , _ $Param10 = 0,$Param11 = 0,$Param12 = 0,$Param13 = 0,$Param14 = 0,$Param15 = 0, _ $Param16 = 0,$Param17 = 0,$Param18 = 0,$Param19 = 0,$Param20 = 0,$Param21 = 0, _ $Param22 = 0,$Param23 = 0,$Param24 = 0,$Param25 = 0,$Param26 = 0,$Param27 = 0, _ $Param28 = 0,$Param29 = 0,$Param30 = 0,$Param31 = 0,$Param32 = 0,$Param33 = 0) ;$FuncName Name Of function that will be invoked ;BOOL $ReturnDirectly if true will return immediately ;Other parameters are parameters which function will be invoked ;Parameter data types (DllStruct,Binary,Boolean,hWnd,Int,Float,String ) ;return ;Success: results of an ReturnStruct function Or One ;Failure: zero Local $ParamsArray[1] ,$ElementNu = 0 , $TagParamStruct = "" For $i = 1 To @NumParams - 2 ReDim $ParamsArray[$i] $Param = Eval(String("Param" & $i)) Select Case IsString($Param) $ParamsArray[$i - 1] = 1 $TagParamStruct &= "INT ParamType" & $i & ";CHAR ParamData" & $i & "[" & StringLen($Param) & "];" Case IsBinary($Param) $ParamsArray[$i - 1] = 2 $TagParamStruct &= "INT ParamType" & $i & ";BYTE ParamData" & $i & "[" & BinaryLen($Param) & "];" Case IsInt($Param) $ParamsArray[$i - 1] = 3 $TagParamStruct &= "INT ParamType" & $i & ";UINT64 ParamData" & $i & ";" Case IsFloat($Param) $ParamsArray[$i - 1] = 4 $TagParamStruct &= "INT ParamType" & $i & ";DOUBLE ParamData" & $i & ";" Case IsBool($Param) $ParamsArray[$i - 1] = 5 $TagParamStruct &= "INT ParamType" & $i & ";BOOL ParamData" & $i & ";" Case IsDllStruct($Param) $ParamsArray[$i - 1] = 6 $TagParamStruct &= "INT ParamType" & $i & ";BYTE ParamData" & $i & "[" & DllStructGetSize($Param) & "];" Case IsPtr($Param) $ParamsArray[$i - 1] = 7 $TagParamStruct &= "INT ParamType" & $i & ";PTR ParamData" & $i & ";" Case Else Return SetError(1,0,0) EndSelect Next $TagParamStruct = "INT Len;CHAR TagParamStruct[];INT NumParams;" & $TagParamStruct $Len = StringLen($FuncName) + StringLen($TagParamStruct) + 1 $Len += StringLen($Len) $TagParamStruct = StringReplace($TagParamStruct,"[]","[" & $Len & "]") $GlobalParamStruct = DllStructCreate($TagParamStruct) $ElementNu += 1 DllStructSetData($GlobalParamStruct,$ElementNu,$Len) $ElementNu += 1 DllStructSetData($GlobalParamStruct,$ElementNu,$FuncName & "|" & $TagParamStruct) $ElementNu += 1 DllStructSetData($GlobalParamStruct,$ElementNu,@NumParams - 2) For $i = 1 To @NumParams - 2 $Param = Eval(String("Param" & $i)) $ElementNu += 1 DllStructSetData($GlobalParamStruct,$ElementNu,$ParamsArray[$i - 1]) $ElementNu += 1 Select Case $ParamsArray[$i - 1] = 6 $OutPtr = DllStructGetPtr($GlobalParamStruct,$ElementNu) _MemMoveMemory($Param,$OutPtr,DllStructGetSize($Param)) Case Else DllStructSetData($GlobalParamStruct,$ElementNu,$Param) EndSelect Next $ParamsPtr = DllStructGetPtr($GlobalParamStruct) Sleep(300) Local $WindowHandle = 0 Select Case $GlobalParticularProcess == "ParentProcess" $WindowHandle = $ChhWnd $ProcessID = $ChProcessID Case $GlobalParticularProcess == "ChildProcess" $WindowHandle = $PrhWnd $ProcessID = $PrProcessID EndSelect if ($ReturnDirectly) Then $RT = _SendMessage($WindowHandle,$UntCallMsg,1,$ParamsPtr) Return SetError($RT = 0,0,$RT) Else $pResultsStructPtr = _SendMessage($WindowHandle,$UntCallMsg,0,$ParamsPtr) $LenStruct = Read_Ptr($ProcessID,$pResultsStructPtr,"INT Len") if Not IsDllStruct($LenStruct) Then Return SetError(1,0,0) $jLen = DllStructGetData($LenStruct,1) $pTagResultsStruct = "INT Len;CHAR TagResultsStruct[" & $jLen & "];PTR ResultsPtr" $pResultsStruct = Read_Ptr($ProcessID,$pResultsStructPtr,$pTagResultsStruct) if Not IsDllStruct($pResultsStruct) Then Return SetError(1,0,0) $TagResultsStruct = DllStructGetData($pResultsStruct,2) $ResultsPtr = DllStructGetData($pResultsStruct,3) $ResultsStruct = Read_Ptr($ProcessID,$ResultsPtr,$TagResultsStruct) if Not IsDllStruct($ResultsStruct) Then Return SetError(1,0,0) $GlobalpResultsStruct = $pResultsStruct $GlobalResultsStruct = $ResultsStruct Return SetError(0,0,$ResultsStruct) EndIf EndFunc Func ReturnStruct($TagResultsStruct,$ResultsStruct) if Not IsDllStruct($ResultsStruct) Then Return 0 $jLen = StringLen($TagResultsStruct) $ResultsPtr = DllStructGetPtr($ResultsStruct) $pTagResultsStruct = "INT Len;CHAR TagResultsStruct[" & $jLen & "];PTR ResultsPtr" $pResultsStruct = DllStructCreate($pTagResultsStruct) if Not IsDllStruct($pResultsStruct) Then Return 0 DllStructSetData($pResultsStruct,1,$jLen) DllStructSetData($pResultsStruct,2,$TagResultsStruct) DllStructSetData($pResultsStruct,3,$ResultsPtr) $GlobalResultsStruct = $ResultsStruct $GlobalpResultsStruct = $pResultsStruct Return DllStructGetPtr($pResultsStruct) EndFunc Func CallMsgFunc($hWnd,$Msg,$wParam,$lParam) Local $NumParams = 0, $ElementNu = 0 , $TagParamStruct = "" , $Len = 0 Local $ProcessID = -1 Select Case $GlobalParticularProcess == "ParentProcess" $ProcessID = $ChProcessID Case $GlobalParticularProcess == "ChildProcess" $ProcessID = $PrProcessID EndSelect $LenStruct = Read_Ptr($ProcessID,$lParam,"INT Len") $ElementNu += 1 $Len = DllStructGetData($LenStruct,$ElementNu) $GlobalParamStruct = Read_Ptr($ProcessID,$lParam,"INT Len;CHAR TagParamStruct[" & $Len & "];") $ElementNu += 1 $TagParamStruct = DllStructGetData($GlobalParamStruct,2) $Split = StringSplit($TagParamStruct,"|") $FuncName = $Split[1] $TagParamStruct = $Split[2] $GlobalParamStruct = Read_Ptr($ProcessID,$lParam,$TagParamStruct) $ElementNu += 1 $NumParams = DllStructGetData($GlobalParamStruct,$ElementNu) ReDim $ArgsArray[$NumParams + 1] $ArgsArray[0] = "CallArgArray" For $i = 1 To $NumParams $ElementNu += 1 $ParamType = DllStructGetData($GlobalParamStruct,$ElementNu) $ElementNu += 1 Select Case $ParamType = 6 $ParamData = DllStructGetPtr($GlobalParamStruct,$ElementNu) Case Else $ParamData = DllStructGetData($GlobalParamStruct,$ElementNu) EndSelect if $ParamType = 5 Then $ParamData = $ParamData = 1 $ArgsArray[$i] = $ParamData Next Select Case $wParam = 0 Switch $NumParams Case 0 Return Call($FuncName) Case Else Return Call($FuncName,$ArgsArray) EndSwitch Case $wParam = 1 ; Return Directly) AdlibRegister("AdlibCallFunc") Return 1 EndSelect Return 0 EndFunc Func AdlibCallFunc() AdlibUnRegister("AdlibCallFunc") $GlobalResults = 0 $GlobalError = 0 $GlobalExtended = 0 Switch UBound($ArgsArray) Case 1 $GlobalResults = Call($FuncName) Case Else $GlobalResults = Call($FuncName,$ArgsArray) EndSwitch $GlobalError = @error $GlobalExtended = @extended EndFunc Func Read_Ptr($ProcessID,$Pointer,$TagStruct) Local $Struct , $iRead $Struct = DllStructCreate($TagStruct) if @error Then Return SetError(1,0,0) Switch $ProcessID Case $PrProcessID if Not $PrhProcess Then $PrhProcess = _WinAPI_OpenProcess($iPROCESS_ALL_ACCESS,False,$ProcessID) if @error Then Return SetError(2,0,0) $Return = _WinAPI_ReadProcessMemory($PrhProcess,$Pointer,DllStructGetPtr($Struct),DllStructGetSize($Struct),$iRead) if Not $Return Then Return SetError(3,0,0) Case $ChProcessID if Not $ChhProcess Then $ChhProcess = _WinAPI_OpenProcess($iPROCESS_ALL_ACCESS,False,$ProcessID) if @error Then Return SetError(2,0,0) $Return = _WinAPI_ReadProcessMemory($ChhProcess,$Pointer,DllStructGetPtr($Struct),DllStructGetSize($Struct),$iRead) if Not $Return Then Return SetError(3,0,0) Case Else Return SetError(4,0,0) EndSwitch Return SetError(0,0,$Struct) EndFunc Func RegisterWindowMessage($lpString,$Distinction,$Password) $MsgStr = $lpString & $Distinction & $Password $UINTMSG = DllCall("User32.dll","UINT","RegisterWindowMessageW","wstr",$MsgStr) $Err = _WinAPI_GetLastError() if Not $Err And Not @error Then Return SetError(0,0,$UINTMSG[0]) Return SetError(1,0,0) EndFunc ParentProcess.au3 #include "ChildProcess.au3" ;Work with two process Global $Progress = 0 , $Labe2 = 0 , $DownloadInfoPtr = 0 StartAndParticular() Func StartAndParticular() $iParticularProcess = Work_With_Two_process() ;In The Two_Process_Library.au3 File Select Case $iParticularProcess == "ParentProcess" ParentWinMain() Case $iParticularProcess == "ChildProcess" ChildWinMain() ;In the ChildProcess.au3 File EndSelect EndFunc Func ParentWinMain() Opt("GUIOnEventMode", 1) $GuiC = GUICreate("WinMain",400,400,100,10) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Button_1 = GUICtrlCreateButton("Download Microsoft Windows 7",10,10,380,40) GUICtrlSetOnEvent(-1,"Clicked_Button_1") $progressbar = GUICtrlCreateProgress(10,60,380,20) $Label = GUICtrlCreateLabel("", 10,100,380,20) $Labe2 = GUICtrlCreateLabel("", 10,130,380,20) GUISetState(@SW_SHOW,$GuiC) GUISwitch($GuiC) While 1 if Not IsChildProcessWork() Then MsgBox(0,"Error Msg","Child Process Not Working") Exit EndIf if ($Progress) Then $BOOL = Progress($progressbar,$Label,$Labe2) if @error Then $Progress = False MsgBox(0,"Error Msg","Download Error") Else if @extended Then $Progress = False MsgBox(0,"Msg","Download complete") GUICtrlSetData($progressbar,0) EndIf EndIf EndIf WEnd EndFunc Func _Exit() Exit EndFunc Func Clicked_Button_1() $DownloadInfoPtr = CallFunc("GetDownloadInfoPtr",False) ; Call function from child process $DownloadInfoPtr = DllStructGetData($DownloadInfoPtr,1) $Progress = True $Url = "https://download.microsoft.com/download/4/7/A/47A0F7B9-1F0F-41B0-AA42-00FD16337268/Windows6.1-KB947821-v34-x86.msu";"https://archive.org/download/WIN7HPLITEHUDVD/WIN7_HP_LITE_HU_DVD.iso" GUICtrlSetData($Labe2,"Connect to the server") CallFunc("Inet_Read",True,$Url,256,@ScriptDir) ;Call function from child process (Return Directly) EndFunc Func Progress($progressbar,$Label,$Labe2,$ProgressTime = 200) $InfoStruct = Read_Ptr($ChProcessID,$DownloadInfoPtr,$TagInfoStruct) ; Read $DownloadInfoPtr From child process Fast red And Loop Of child process Not Stop $FileSize = DllStructGetData($InfoStruct,1) $MovePos = DllStructGetData($InfoStruct,2) $IsComplete = DllStructGetData($InfoStruct,3) $iError = DllStructGetData($InfoStruct,4) if ($FileSize) Then GUICtrlSetData($progressbar, (($MovePos / $FileSize) * 100)) GUICtrlSetData($Label,"FileSize = " & $FileSize & " Number Of Bytes Read = " & $MovePos) GUICtrlSetData($Labe2,"Download = " & Int((($MovePos / $FileSize) * 100)) & " % Download = " & StringLeft(($MovePos / 1048576),6) & " MB") Else GUICtrlSetData($Labe2,"Waiting for the first time download") EndIf Sleep($ProgressTime) if ($IsComplete) And ($MovePos = $FileSize) Then Return SetError($iError,1,$iError == 0) Return SetError($iError,0,$iError == 0) EndFunc ChildProcess.au3 #include "Two_Process_Library.au3" Func ChildWinMain() While IsParentProcessWork() WEnd EndFunc ;-------------------------------------------------------------------------; ;They are called from the parent process Func Inet_Read($lpszUrl,$ByteAtaTime,$FileDir) $IsComplete = False if ($ByteAtaTime <= 0) Then if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,4,1) ; Error Return SetError(1,0,False) EndIf $HIntOpen = InternetOpen("OPEN") if Not ($HIntOpen) Then if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,4,2) ; Error Return SetError(2,0,False) EndIf $HIntOpenUrl = InternetOpenUrl($HIntOpen,$lpszUrl,"",0,0,0) if Not ($HIntOpenUrl) Then InternetCloseHandle($HIntOpen) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,4,3) ; Error Return SetError(3,0,False) EndIf $FileSize = HttpQueryInfo($HIntOpenUrl,5) ; HTTP_QUERY_CONTENT_LENGTH = 5 if @error Then InternetCloseHandle($HIntOpen) InternetCloseHandle($HIntOpenUrl) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,4,4) ; Error Return SetError(4,0,False) EndIf $FileSize = Abs(Number($FileSize)) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,1,$FileSize) $OriginalUrl = InternetQueryOption($HIntOpenUrl,34) ;INTERNET_OPTION_URL = 34 if @error Then InternetCloseHandle($HIntOpen) InternetCloseHandle($HIntOpenUrl) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,5,8) ; Error Return SetError(5,0,False) EndIf $OriginalUrl = StringSplit($OriginalUrl,"/") $OriginalUrl = $OriginalUrl[$OriginalUrl[0]] if StringRight($FileDir,1) == "\" Then $FileDir = StringTrimRight($FileDir,1) Local $FileName = $FileDir & "\" & $OriginalUrl $hFile = _WinAPI_CreateFile($FileName,1) if Not $hFile Then InternetCloseHandle($HIntOpen) InternetCloseHandle($HIntOpenUrl) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,4,6) ; Error Return SetError(6,0,False) EndIf Local $Buffer = DllStructCreate("BYTE Buffer[" & $ByteAtaTime & "]") , $BOOL = True Local $nBytes = 0 , $Error = False , $MovePos = 0 , $lpBuffer = DllStructGetPtr($Buffer) While IsParentProcessWork() if ($FileSize - $MovePos) < $ByteAtaTime Then $ByteAtaTime = $FileSize - $MovePos $lpdwNumberOfBytesRead = InternetReadFile($HIntOpenUrl,$lpBuffer,$ByteAtaTime) $Error = @error if $Error Then ExitLoop $MovePos += $lpdwNumberOfBytesRead if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,2,$MovePos) $BOOL = _WinAPI_WriteFile($hFile,$lpBuffer,$lpdwNumberOfBytesRead,$nBytes) if Not($BOOL) Or $FileSize = $MovePos Then ExitLoop WEnd if ($Error) Or Not($BOOL) Then _WinAPI_CloseHandle($hFile) InternetCloseHandle($HIntOpen) InternetCloseHandle($HIntOpenUrl) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,4,7) Return SetError(7,0,False) EndIf $IsComplete = True _WinAPI_CloseHandle($hFile) InternetCloseHandle($HIntOpen) InternetCloseHandle($HIntOpenUrl) if IsDllStruct($GlobalStructA) Then DllStructSetData($GlobalStructA,3,$IsComplete) Return SetError(0,0,True) EndFunc Func GetDownloadInfoPtr() $GlobalStructA = DllStructCreate($TagInfoStruct) $DownloadInfoPtrSt = DllStructCreate("PTR") DllStructSetData($DownloadInfoPtrSt,1,DllStructGetPtr($GlobalStructA)) Return ReturnStruct("PTR",$DownloadInfoPtrSt) EndFunc Func GetDownloadInfo() $InfoStruct = DllStructCreate($TagInfoStruct) DllStructSetData($InfoStruct,1,$FileSize) DllStructSetData($InfoStruct,2,$MovePos) DllStructSetData($InfoStruct,3,$IsComplete) DllStructSetData($InfoStruct,4,$GlobalError) Return ReturnStruct($TagInfoStruct,$InfoStruct) EndFunc ;They are called from the parent process ;-------------------------------------------------------------------------; Func InternetReadFile($hFile,$lpBuffer,$dwNumberOfBytesToRead) $DLLSDWORD = DllStructCreate("DWORD") $lpdwNumberOfBytesRead = DllStructGetPtr($DLLSDWORD) $BOOL = DllCall($jDll,"BOOL","InternetReadFile","HANDLE",$hFile,"ptr",$lpBuffer, _ "DWORD",$dwNumberOfBytesToRead,"ptr",$lpdwNumberOfBytesRead) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,DllStructGetData($DLLSDWORD,1)) EndFunc Func HttpQueryInfo($hRequest,$dwInfoLevel,$lpdwIndex = 0) Local $lpdwBufferLength = 1000 $DLLSDWORD = DllStructCreate("DWORD") DllStructSetData($DLLSDWORD,1,$lpdwBufferLength) $LPDWORDLENGTH = DllStructGetPtr($DLLSDWORD) $DLLSlpvBuffer = DllStructCreate("WCHAR[" & $lpdwBufferLength & "]") $lpvBuffer = DllStructGetPtr($DLLSlpvBuffer) $BOOL = DllCall($jDll,"BOOL","HttpQueryInfoW","HANDLE",$hRequest,"DWORD",$dwInfoLevel, _ "ptr",$lpvBuffer,"ptr",$LPDWORDLENGTH,"DWORD",$lpdwIndex) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,DllStructGetData($DLLSlpvBuffer,1)) EndFunc Func InternetQueryOption($hInternet,$dwOption) Local $lpdwBufferLength = 1000 $DLLSDWORD = DllStructCreate("DWORD") DllStructSetData($DLLSDWORD,1,$lpdwBufferLength) $LPDWORDLENGTH = DllStructGetPtr($DLLSDWORD) $DLLSlpvBuffer = DllStructCreate("WCHAR[" & $lpdwBufferLength & "]") $lpvBuffer = DllStructGetPtr($DLLSlpvBuffer) $BOOL = DllCall($jDll,"BOOL","InternetQueryOptionW","HANDLE",$hInternet _ ,"DWORD",$dwOption,"ptr",$lpvBuffer,"ptr",$LPDWORDLENGTH) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,DllStructGetData($DLLSlpvBuffer,1)) EndFunc Func InternetOpenUrl($hInternet,$lpszUrl,$lpszHeaders,$dwHeadersLength,$dwFlags,$dwContext) $HINTERNET = DllCall($jDll,"HANDLE","InternetOpenUrlW","HANDLE",$hInternet,"wstr",$lpszUrl, _ "wstr",$lpszHeaders,"DWORD",$dwHeadersLength,"DWORD",$dwFlags,"ptr",$dwContext) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func InternetOpen($lpszAgent,$dwAccessType = 0,$lpszProxyName = "",$lpszProxyBypass = "",$dwFlags = 0) $HINTERNET = DllCall($jDll,"HANDLE","InternetOpenW","wstr",$lpszAgent,"DWORD",$dwAccessType, _ "wstr",$lpszProxyName,"wstr",$lpszProxyBypass,"DWORD",$dwFlags) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func InternetCloseHandle($hInternet) $BOOL = DllCall($jDll,"BOOL","InternetCloseHandle","HANDLE",$hInternet) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$BOOL[0]) EndFunc Two_Process_Library_Constants.au3 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Memory.au3> #include <Math.au3> Global $MovePos , $FileSize , $jDll = DllOpen("Wininet.dll") , $Buffer , $IsComplete Global $UntCallMsg,$UntCoueMsg,$ArgsArray[1],$FuncName = "" ,$PrProcessID = 0,$ChProcessID = 0, _ $ChhWnd = 0,$PrhWnd = 0,$MsgOk = 123456789,$GlobalResultsStruct,$GlobalpResultsStruct, _ $GlobalParamStruct , $GlobalParticularProcess = "" , $GlobalResults = 0 , $GlobalError = 0 , _ $GlobalExtended = 0 , $GlobalPassword = "GlobalPassword" , $PrhProcess = 0 ,$ChhProcess = 0 Global $iSYNCHRONIZE = ( 0x00100000 ) , $iSTANDARD_RIGHTS_REQUIRED = (0x000F0000) , $pbeginA = TimerInit() Global $iPROCESS_ALL_ACCESS = ($iSTANDARD_RIGHTS_REQUIRED + $iSYNCHRONIZE + 0xFFF),$pbeginB = TimerInit() Global $TagInfoStruct = "UINT64 FileSize;UINT64 MovePos;BOOL IsComplete;INT iError" Global $GlobalStructA , $GlobalStructB , $GlobalStructC ;$GlobalStructD , ....1 point -
Purpose (MSDN - Windows Internet) The Microsoft Windows Internet (WinINet) application programming interface (API) enables applications to access standard Internet protocols, such as FTP, Gopher, and HTTP. For ease of use, WinINet abstracts these protocols into a high-level interface. Download WinINet_2010_01_02.zip - Minor tweaks WinINet_2008_09_13.zip - Added _WinINet_Shutdown - Added _WinINet_Startup - Fixed _WinINet_CreateUrlCacheGroup - Fixed _WinINet_FindFirstUrlCacheEntryEx - Fixed _WinINet_FindNextUrlCacheEntryEx - Fixed _WinINet_FtpCommand - Fixed _WinINet_InternetFindNextFile - Fixed _WinINet_SetUrlCacheEntryGroup - Changed _WinINet_GetUrlCacheGroupAttribute (returns array instead of DllStruct) - Many examples added (mostly complete for FTP functions) WinINet_2008_08_22.zip - Fixed INTERNET_CACHE_ENTRY_INFO-related functions (they return an array now rather than the raw structure) - Added examples for _WinINet_FindFirstUrlCacheEntry() and _WinINet_CreateUrlCacheEntry() WinINet_2008_08_16.zip - Fixed some string/buffer length issues WinINet_2008_08_11.zip - Added _WinINet_FindCloseUrlCache - Added _WinINet_FindFirstUrlCacheEntry - Added _WinINet_FindFirstUrlCacheEntryEx - Added _WinINet_FindFirstUrlCacheGroup - Added _WinINet_FindNextUrlCacheEntry - Added _WinINet_FindNextUrlCacheEntryEx - Added _WinINet_FindNextUrlCacheGroup - Added _WinINet_InternetCrackUrl - Added _WinINet_InternetCreateUrl WinINet.zip - Initial release Function List IMPLEMENTED =========== _WinINet_CommitUrlCacheEntry _WinINet_CreateUrlCacheEntry _WinINet_CreateUrlCacheGroup _WinINet_DeleteUrlCacheEntry _WinINet_DeleteUrlCacheGroup _WinINet_DetectAutoProxyUrl _WinINet_FindCloseUrlCache _WinINet_FindFirstUrlCacheEntry _WinINet_FindFirstUrlCacheEntryEx _WinINet_FindFirstUrlCacheGroup _WinINet_FindNextUrlCacheEntry _WinINet_FindNextUrlCacheEntryEx _WinINet_FindNextUrlCacheGroup _WinINet_FtpCommand _WinINet_FtpCreateDirectory _WinINet_FtpDeleteFile _WinINet_FtpFindFirstFile _WinINet_FtpGetCurrentDirectory _WinINet_FtpGetFile _WinINet_FtpGetFileSize _WinINet_FtpOpenFile _WinINet_FtpPutFile _WinINet_FtpRemoveDirectory _WinINet_FtpRenameFile _WinINet_FtpSetCurrentDirectory _WinINet_GetUrlCacheEntryInfo _WinINet_GetUrlCacheEntryInfoEx _WinINet_GetUrlCacheGroupAttribute _WinINet_GopherCreateLocator _WinINet_GopherFindFirstFile _WinINet_GopherGetAttribute _WinINet_GopherGetLocatorType _WinINet_GopherOpenFile _WinINet_HttpAddRequestHeaders _WinINet_HttpEndRequest _WinINet_HttpOpenRequest _WinINet_HttpQueryInfo _WinINet_HttpSendRequest _WinINet_HttpSendRequestEx _WinINet_InternetAttemptConnect _WinINet_InternetAutodial _WinINet_InternetAutodialHangup _WinINet_InternetCanonicalizeUrl _WinINet_InternetCheckConnection _WinINet_InternetClearAllPerSiteCookieDecisions _WinINet_InternetCloseHandle _WinINet_InternetCombineUrl _WinINet_InternetConfirmZoneCrossing _WinINet_InternetConnect _WinINet_InternetCrackUrl _WinINet_InternetCreateUrl _WinINet_InternetDial _WinINet_InternetEnumPerSiteCookieDecision _WinINet_InternetErrorDlg _WinINet_InternetFindNextFile _WinINet_InternetGetConnectedState _WinINet_InternetGetConnectedStateEx _WinINet_InternetGetCookie _WinINet_InternetGetCookieEx _WinINet_InternetGetLastResponseInfo _WinINet_InternetGetPerSiteCookieDecision _WinINet_InternetGoOnline _WinINet_InternetHangUp _WinINet_InternetLockRequestFile _WinINet_InternetOpen _WinINet_InternetOpenUrl _WinINet_InternetQueryDataAvailable _WinINet_InternetQueryOption _WinINet_InternetReadFile _WinINet_InternetReadFileEx _WinINet_InternetSetCookie _WinINet_InternetSetCookieEx _WinINet_InternetSetFilePointer _WinINet_InternetSetOption _WinINet_InternetSetPerSiteCookieDecision _WinINet_InternetSetStatusCallback _WinINet_InternetTimeFromSystemTime _WinINet_InternetTimeToSystemTime _WinINet_InternetUnlockRequestFile _WinINet_InternetWriteFile _WinINet_PrivacyGetZonePreferenceW _WinINet_PrivacySetZonePreferenceW _WinINet_ReadUrlCacheEntryStream _WinINet_ResumeSuspendedDownload _WinINet_RetrieveUrlCacheEntryFile _WinINet_RetrieveUrlCacheEntryStream _WinINet_SetUrlCacheEntryGroup _WinINet_SetUrlCacheEntryInfo _WinINet_SetUrlCacheGroupAttribute _WinINet_Shutdown _WinINet_Startup _WinINet_Struct_InternetCacheEntryInfo_ToArray _WinINet_Struct_InternetCacheGroupInfo_FromArray _WinINet_Struct_InternetCacheGroupInfo_ToArray _WinINet_Struct_UrlComponents_FromArray _WinINet_Struct_UrlComponents_ToArray _WinINet_UnlockUrlCacheEntryFile _WinINet_UnlockUrlCacheEntryStream NOT LIKELY TO BE IMPLEMENTED (don't seem to be relevant) ============================ _WinINet_CleanupCredentialCache _WinINet_CreateMD5SSOHash _WinINet_InternetDeInitializeAutoProxyDll _WinINet_InternetGetProxyInfo _WinINet_InternetInitializeAutoProxyDll Remarks There have been many UDFs released previously that rely on WinINet functions, but not many that are just direct wrappers around the functions (the FTP UDFs are the main ones that come to mind). The aim here is to get these functions into the standard UDFs, so that these UDFs can provide a base for other functions that rely on WinINet. I've implemented most of the functions, but I haven't tested most of them either (the important ones, like InternetOpen/Connect and various HTTP functions are mainly what I tested). Indeed, the constants file is still very disorganized (and incomplete), but I'll try getting around to that another time. In the meanwhile, I'm releasing what I currently have for wider testing and peer review of sorts. Feedback is welcome, as always Anyhow, test away! Edit: Just a note... before you use most of these functions, you'll need to call _WinINet_Startup(). Edit: And uh... I don't have example scripts for every single function at the moment. That would probably help with testing...1 point
-
Excel Grid in AutoIT For those who are interested in Excel. Helps you using Excel function and use the results of these back in AutoIT variables. Also this can be used as a replacement for the ListView, and load the data direct in the Excel Grid. Exporting to an Excel file is standard included (look at the toolbar icons). ; ; Script generated by AutoBuilder 0.5 Prototype ; Embedded Excel Object in AutoIt ; Helps you using Excelfunction and use the results of these back in AutoIT vars. ; Also this can be used as a replacement for the ListView, and load the data direct in the Excel Grid. ; PTREX 09/11/05 ; #include <GUIConstants.au3> #NoTrayIcon ;Vars Dim $oMyError Dim $i Dim $j ;Declare objects $oExcel = ObjCreate("OWC10.spreadsheet"); Default to Office XP If not IsObj($oExcel) Then $oExcel = ObjCreate("OWC11.spreadsheet"); Office 2003 EndIf IF not IsObj($oExcel) Then $oExcel = ObjCreate("OWC00.spreadsheet"); Office 2000 EndIf If IsObj($oExcel) Then with $oExcel ;.Worksheets ("Sheet1").Activate ;.activesheet.range ("A1:B10").value = "TEST INFO" for $i = 1 to 15 for $j = 1 to 15 .cells($i,$j).value = $i next next EndWith Else MsgBox(0,"Reply","Not an Object",4) EndIf ;Main Gui GuiCreate("Excel Object", 802, 590,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $GUI_ActiveX = GUICtrlCreateObj ($oExcel, 10, 10 , 780 , 550) GUICtrlSetStyle ( $GUI_ActiveX, $WS_VISIBLE ) GUICtrlSetResizing ($GUI_ActiveX,$GUI_DOCKAUTO) ; Auto Resize Object GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Exit ;This is Sven P's custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Office 2003 object added. Enjoy1 point
-
ADO: Start a section in the Wiki
13lack13lade reacted to water for a topic
ADO (ActiveX Data Objects) is a set of Component Object Model (COM) objects for accessing data sources like text files, Excel workbooks, databases (e.g. MS SQL, Oracle, MySQL), directory services (e.g. Active Directory, OpenLDAP). There are many examples on the forum but a documentation that puts it all together is missing. If you would like to see such a section in the Wiki then please answer the question in the poll and post the data source you would like to see documented (text file, MS SQL, Excel ...) (Stripped down) Example by GreenCan: $sPath_to_database = "C:\Temp\text delimited files" $connection = "DRIVER={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & $sPath_to_database & ";Extensions=asc,csv,tab,txt;" $adoCon = ObjCreate("ADODB.Connection") $adoCon.Open($connection) If @error Then Exit MsgBox(48, "Error", "error " & @error) $adoRs = ObjCreate("ADODB.Recordset") $adoSQL = "SELECT * FROM Countries.csv" $adoRs.CursorType = 2 $adoRs.LockType = 3 $adoRs.Open($adoSQL, $adoCon) With $adoRs If .RecordCount Then While Not .EOF $sResult = $sResult & "" & .Fields("Continent").Value & "|" & .Fields("alpha_2").Value & "|" & .Fields("English_Country_Name").Value & @CR .MoveNext WEnd EndIf EndWith $adoCon.Close MsgBox(0, "Result", $sResult)1 point -
A Note to Voters The entries for this challenge appear in the following two posts below this one. The purpose here is to demonstrate AutoIt to a beginner. The code should be easy to follow if you are a beginner. Speculation about the authors is expected, but remember it is the code you are voting for, not the person who wrote it. Before casting a vote please read the 7 criteria listed below. You are entitled to cast one vote for one piece of code which you think would make a good example for the wikipedia article. A Note to Participants Although it may be tempting, I would like it if you refrain from dropping hints to the voters once voting begins. Deadline for Voting Voting will last approximately 3 days until midnight GMT on 23rd of February. In the Event of a Tie If there is no clear winner after the period for voting has ended, finalists will be selected and voting will go to sudden death, whereby whichever of the the remaining contestants has the most votes at a time determined without forewarning by the arbiter, will be declared the winner. If it is still neck and neck after this period has elapsed, the winner will be selected using a formula. ; $iWinner = Mod(StringLen("JohnOne" & "Xandy"), 2) ; Now we've seen what the community can do, it's time for us MVPs to be judged by the community. What has been suggested is that a second example ought to be written to demonstrate a simple automation task to an absolute beginner. So let's show the community what we can do! You are allowed no more than 32 lines of code including comments. As before, the new example should: 1. comply to standard coding practices 2. be easy to follow 3. do something useful 4. be of interest to a wide audience 5. comply with the rules of the forum 6. not be longer than exactly 32 lines of code 7. convey the ease of use of AutoIt to beginners Names will be removed from submissions by an independant arbiter before being judged. The community will vote for the code they like best. Only current MVPs are allowed to enter, and no MVP is entitled to vote for the winner. Team efforts can also be submitted. The deadline for submissions will be 20th February 2015. The arbiter is jaberwacky once more. All submissions should be sent to the arbiter. The community will be given three days to vote for the winner, once jaberwacky has posted the examples we send to him. After voting has finished jaberwacky will reveal the name of the MVP whose code you like best. Good luck to everyone! The winning examples from both challenges will be added to the Wikipedia page.1 point
-
GUI design concepts.
argumentum reacted to guinness for a topic
This is a place to post GUI examples that other users may find interesting. Try to code clearly and concisely please for example DON'T USE MAGIC NUMBERS! Splash Screen: #include <GUIConstantsEx.au3> #include <SendMessage.au3> #include <WindowsConstants.au3> Global Const $SC_DRAGMOVE = 0xF012 Example() ; Idea by prizm1 Func Example() Local $iHeight = 250, $iWidth = 400 Local $hGUI = GUICreate('', $iWidth, $iHeight, Default, Default, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST) GUICtrlCreateGroup('', 0, -5, $iWidth, $iHeight + 5, $WS_THICKFRAME) GUICtrlCreateGroup('', -99, -99, 1, 1) Local $iClose = GUICtrlCreateButton('Close', $iWidth - 100, $iHeight - 40, 85, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iClose ExitLoop Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example1 point -
I explained why with the file:///[drive letter]:/Fullpath/etc Here's a fix if you don't want to hard code the files, you'd have to code pretty consistent with your html though: #include <IE.au3> #include <FileConstants.au3> Local $hFileOpen = FileOpen('test.html', $FO_READ + $FO_UTF8) Local $sHTML = FileRead($hFileOpen) _html_imgSrcToLocalPath($sHTML) FileClose($hFileOpen) Local $oIE = _IECreate() _IEDocWriteHTML($oIE, $sHTML) Func _html_imgSrcToLocalPath(ByRef $sHTML, $sPath = @ScriptDir) Local $aImgFiles = StringRegExp($sHTML, "(?is)(<\s*img\s+src=[""'](.+?)[""'])", 3) If @error Then ; no img files Return SetError(1, 0, 0) EndIf $sPath = StringReplace(StringRegExpReplace($sPath, "[\\/]+$", ""), "\", "/", 0, 1) Local $sRepl For $i = 0 To UBound($aImgFiles) -1 Step 2 If StringRegExp($aImgFiles[$i + 1], "^(?i)\s*(http|s?ftp|file:///)") Then ContinueLoop $sRepl = StringReplace($aImgFiles[$i], $aImgFiles[$i + 1], _ "file:///" & $sPath & "/" & $aImgFiles[$i + 1]) $sHTML = StringReplace($sHTML, $aImgFiles[$i], $sRepl, 1, 0) Next Return 1 EndFunc1 point
-
I think you are mixing up the color formats! Afaik the web color is in format RGB and you need to convert it to ARGB format. Sometimes you can code the web color in format #09C which is the same as #0099CC. RGB to ARGB: $color_hex_rgb = 0x1188AA $Blue = BitAND($color_hex_rgb, 0xFF) $Green = BitAND(BitShift($color_hex_rgb, 8), 0xFF) $Red = BitAND(BitShift($color_hex_rgb, 16), 0xFF) $color_argb = 0xFF000000 + $Red * 0x10000 + $Green * 0x100 + $Blue MsgBox(0, "Test", Hex($color_argb, 8)) Br,UEZ1 point
-
Sorry to say that but what you did is not correct. What you try to achieve is to convert a RGB value to ARGB format (and not from RGBA to ARGB!) but your conversation is not correct! Try this: #include <GDIPlus.au3> Func _Image_WriteText($text, $file, $save, $x = 0, $y = 0, $color_hex_rgb = 0x000000, $font = "Arial", $font_w = 30, $style = 0) Local $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen $Blue = BitAND($color_hex_rgb, 0xFF) $Green = BitAND(BitShift($color_hex_rgb, 8), 0xFF) $Red = BitAND(BitShift($color_hex_rgb, 16), 0xFF) $color_argb = 0xFF000000 + $Red * 0x10000 + $Green * 0x100 + $Blue _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile($file) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $hFamily = _GDIPlus_FontFamilyCreate($font) $hFont = _GDIPlus_FontCreate($hFamily, $font_w, 1) $hFormat = _GDIPlus_StringFormatCreate(0x4000) $hBrush2 = _GDIPlus_BrushCreateSolid($color_argb) $hPen = _GDIPlus_PenCreate(0xC4000000, 1) $tLayout = _GDIPlus_RectFCreate ($x, $y) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $text, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphic, $text, $hFont, $aInfo[0], $hFormat, $hBrush2) _GDIPlus_ImageSaveToFile($hImage, $save) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_ShutDown() EndFunc _Image_WriteText("AutoIt", @ProgramFilesDir & "\AutoIt3\Examples\Helpfile\Extras\AutoIt.bmp", @DesktopDir & "\text_image.bmp", 0, 0, 0x5D4CF6) Br, UEZ1 point
-
Deye, A new (and I hope better) approach. I have added a new parameter to _CFF_SetPreCheck which determines the volatility of the precheck array. By default the array is cleared after each call to _CFF_Choose/Embed but by using the new parameter the list can be retained if required. Here is the new beta code: And here is a short example to show it working: #include "ChooseFileFolder_Mod.au3" ; Register handlers _CFF_RegMsg() Global $aPreCheck_List[] = ["C:\", "D:\"], $aRet ; Set list and make it volatile (default) _CFF_SetPreCheck($aPreCheck_List) ; Run dialog $sRet = _CFF_Choose("Prechecked", -300, -500, -1, -1, "", Default, 0 + 8 + 16 + 512, -1) ; Run again and list is cleared $sRet = _CFF_Choose("Precheck cleared", -300, -500, -1, -1, "", Default, 0 + 8 + 16 + 512, -1) ; Now reset list but retain it by setting volatile parameter to False _CFF_SetPreCheck($aPreCheck_List, Default, False) ; Run dialog $sRet = _CFF_Choose("Prechecked", -300, -500, -1, -1, "", Default, 0 + 8 + 16 + 512, -1) ; Run again and prechecks still occur $sRet = _CFF_Choose("Still prechecked", -300, -500, -1, -1, "", Default, 0 + 8 + 16 + 512, -1) How is that? M231 point
-
Try this: #include <GDIPlus.au3> Func _Image_WriteText($text, $file, $save, $x = 0, $y = 0, $color_rgba = 0x000000FF, $font = "Arial", $font_w = 30, $style = 0) Local $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen $color_argb = BitAND($color_rgba, 0xFF) * 0x1000000 + BitShift($color_rgba, 8) _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile($file) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $hFamily = _GDIPlus_FontFamilyCreate($font) $hFont = _GDIPlus_FontCreate($hFamily, $font_w, 1) $hFormat = _GDIPlus_StringFormatCreate(0x4000) $hBrush2 = _GDIPlus_BrushCreateSolid($color_argb) $hPen = _GDIPlus_PenCreate(0xC4000000, 1) $tLayout = _GDIPlus_RectFCreate ($x, $y) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $text, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphic, $text, $hFont, $aInfo[0], $hFormat, $hBrush2) _GDIPlus_ImageSaveToFile($hImage, $save) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush1) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_ShutDown() EndFunc ;FF0000 is the red color code. _Image_WriteText("AutoIt", @ProgramFilesDir & "\AutoIt3\Examples\Helpfile\Extras\AutoIt.bmp", @DesktopDir & "\text_image.bmp", 0, 0, 0x000000FF) The color code has always four tuble (RGBA) -> _Image_WriteText("AutoIt", @ProgramFilesDir & "AutoIt3ExamplesHelpfileExtrasAutoIt.bmp", @DesktopDir & "text_image.bmp", 0, 0, 0x000000FF) You said that your input is in format RGBA because it is easier and that was the reason for the conversion to the ARGB format! Br, UEZ1 point
-
At the very least, it should probably be noted in the help file that the function only accepts integer types.1 point
-
You can do something like this here to convert a hex RGBA value to ARGB which is needed to create a brush color: $iHex_Input_RGBA = 0x115599FF $iHex_Input_ARGB = BitAND($iHex_Input_RGBA, 0xFF) * 0x1000000 + BitShift($iHex_Input_RGBA, 8) ConsoleWrite(Hex($iHex_Input_ARGB, 8) & @CRLF) Is this what you are looking for? Btw, what is your mother tongue? Br, UEZ1 point
-
CPU Multi-Processor Usage This is an example of getting and displaying processor usage for all processors in a system. It uses the 'undocumented' NtQuerySystemInformation function to gather processor usage information and then does calculations based on the delta of two readings. I wrote this as an alternative to using my >Performance Counters UDF - specifically, check out >Example # 4: System CPU Usage (by Processor). There is now a new interface, as well as two ways to track CPU usage. The first method tracks usage for all CPU's, and additionally produces an overall CPU usage result. The second method tracks Overall CPU usage - a combined value representing all cores as one unit. Note that this second method uses GetSystemTimes, which requires Windows XP SP1 or higher. The usage works like this for all CPU's: $aCPUsUsageTracker = _CPUsUsageTracker_Create() $iTotalCPUs = $aCPUsUsageTracker[0][0] ; Call the following repeatedly - $aCPUsUsageTracker will be updated automatically: $aPercents = _CPUsUsageTracker_GetUsage($aCPUsUsageTracker) For Overall CPU usage, either look at $aPercents[$iTotalCPUs] above, or use this interface (reliant on GetSystemTimes): $aCPUOverallTracker = _CPUOverallUsageTracker_Create() ; Call the following repeatedly - $aCPUOverallTracker will be updated automatically: $fUsage = _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) _ Need to see how CPU usage is affected? A simple tool I use to stress-test individual CPU cores is Stress Prime 2004, which can be run multiple times. P.S. All I ask is that you acknowledge me in some way if you use any of this code. updates: 2013-08-31: - Added a simple Overall and Idle CPU usage example 2013-06-18: - Changed interface for getting CPU usage. Now there's no need to juggle arrays around [obsolete version]: - fixed bound check in _CPUCalculateUsages() to look at 2nd dimension CPU_ProcessorUsage.au3 (prev downloads: ~15) ; ======================================================================================================== ; <CPU_ProcessorUsage.au3> ; ; Example of an alternative means to read individual CPU Usages for multiple CPUs, ; along with the combined overall CPU usage. (Alternative to Performance Counters) ; Readings are shown in a 'Splash' window ; ; Functions: ; _CPUGetTotalProcessorTimes() ; Gets Overall (combined CPUs) Processor Times ; _CPUGetIndividualProcessorTimes() ; Returns an array of CPU usage info for individual processors ; _CPUsUsageTracker_Create() ; Creates a CPU usage tracker for all CPUs ; _CPUsUsageTracker_GetUsage() ; Updates CPU usage tracker and returns a CPU usage array ; _CPUOverallUsageTracker_Create() ; Creates a CPU usage tracker for Overall CPU usage ; _CPUOverallUsageTracker_GetUsage(); Updates CPU usage tracker and returns CPU usage [Overall Usage] ; ; See also: ; Performance Counters UDF ; ; ; Author: Ascend4nt ; ======================================================================================================== ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; ============================================================================================== ; Func _CPUGetTotalProcessorTimes() ; ; Gets the total (combined CPUs) system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; O/S Requirements: min. Windows XP SP1+ ; ; Returns: ; Success: Array of info for total (combined CPU's) processor times: ; [0] = Idle Mode Time ; [1] = Kernel Mode Time -> NOTE This INCLUDES Idle Time ; [2] = User Mode Time ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetTotalProcessorTimes() Local $aRet, $stSystemTimes $stSystemTimes = DllStructCreate("int64 IdleTime;int64 KernelTime;int64 UserTime;") $aRet = DllCall("kernel32.dll", "bool", "GetSystemTimes", "ptr", DllStructGetPtr($stSystemTimes, 1), _ "ptr", DllStructGetPtr($stSystemTimes, 2), "ptr", DllStructGetPtr($stSystemTimes, 3) ) If @error Then Return SetError(2, @error, "") If Not $aRet[0] Then Return SetError(3, 0, "") Dim $aRet[3] = [ _ DllStructGetData($stSystemTimes, 1), _ DllStructGetData($stSystemTimes, 2), _ DllStructGetData($stSystemTimes, 3) ] Return $aRet EndFunc ; ============================================================================================== ; Func _CPUGetIndividualProcessorTimes() ; ; Gets an array of system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; Returns: ; Success: 2 Dimensional Array of info [@extended = #of CPU's]: ; [0][0] = # of CPUs (and array elements) ; [1..n][0] = Idle Mode Time for CPU # n ; [1..n][1] = Kernel Mode Time for CPU # n -> NOTE This INCLUDES Idle Time ; [1..n][2] = User Mode Time for CPU # n ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetIndividualProcessorTimes() ; DPC = Deferred Procedure Calls Local $tagSYSTEM_PROCESSOR_TIMES = "int64 IdleTime;int64 KernelTime;int64 UserTime;int64 DpcTime;int64 InterruptTime;ulong InterruptCount;" Local $aRet, $stProcessorTimes, $stBuffer Local $i, $nTotalCPUStructs, $pStructPtr ; 256 [maximum CPU's] * 48 (structure size) = 12288 $stBuffer = DllStructCreate("byte Buffer[12288];") ; SystemProcessorTimes = 8 Local $aRet=DllCall("ntdll.dll", "long", "NtQuerySystemInformation", "int", 8, "ptr", DllStructGetPtr($stBuffer), "ulong", 12288, "ulong*", 0) If @error Then Return SetError(2, @error, "") ; NTSTATUS of something OTHER than success? If $aRet[0] Then Return SetError(3, $aRet[0], "") ; Length invalid? If $aRet[4] = 0 Or $aRet[0] > 12288 Or Mod($aRet[4], 48) <> 0 Then Return SetError(4, $aRet[4], "") $nTotalCPUStructs = $aRet[4] / 48 ;~ ConsoleWrite("Returned buffer length = " & $aRet[4] & ", len/48 (struct size) = "& $nTotalCPUStructs & @CRLF) ; We are interested in Idle, Kernel, and User Times (3) Dim $aRet[$nTotalCPUStructs + 1][3] $aRet[0][0] = $nTotalCPUStructs ; Traversal Pointer for individual CPU structs $pStructPtr = DllStructGetPtr($stBuffer) For $i = 1 To $nTotalCPUStructs $stProcessorTimes = DllStructCreate($tagSYSTEM_PROCESSOR_TIMES, $pStructPtr) $aRet[$i][0] = DllStructGetData($stProcessorTimes, "IdleTime") $aRet[$i][1] = DllStructGetData($stProcessorTimes, "KernelTime") $aRet[$i][2] = DllStructGetData($stProcessorTimes, "UserTime") ; Next CPU structure $pStructPtr += 48 Next Return SetExtended($nTotalCPUStructs, $aRet) EndFunc ; ============================================================================================== ; Func _CPUsUsageTracker_Create() ; ; Creates a CPU usage tracker array for all processors. This array should be passed ; to _CPUsUsageTracker_GetUsage() to get current usage information back. ; ; Returns: ; Success: An array used to track CPU usage [@extended = # of CPU's] ; Array 'internal' format: ; $arr[0][0] = # of CPU's ; $arr[1..n][0] = Total CPU Time (Kernel + User Mode) ; $arr[1..n][1] = Total Active CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetIndividualProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUsUsageTracker_Create() Local $nTotalCPUs, $aCPUTimes, $aCPUsUsage $aCPUTimes = _CPUGetIndividualProcessorTimes() If @error Then Return SetError(@error, @extended, "") $nTotalCPUs = @extended Dim $aCPUsUsage[$nTotalCPUs + 1][2] $aCPUsUsage[0][0] = $nTotalCPUs For $i = 1 To $nTotalCPUs ; Total $aCPUsUsage[$i][0] = $aCPUTimes[$i][1] + $aCPUTimes[$i][2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[$i][1] = $aCPUTimes[$i][1] + $aCPUTimes[$i][2] - $aCPUTimes[$i][0] Next Return SetExtended($nTotalCPUs, $aCPUsUsage) EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_Create() ; ; Creates a CPU usage tracker array for Overall combined processors usage. ; This array should be passed to _CPUOverallUsageTracker_GetUsage() to get ; current usage information. ; ; Returns: ; Success: An array used to track Overall CPU usage ; Array 'internal' format: ; $arr[0] = Total Overall CPU Time (Kernel + User Mode) ; $arr[1] = Total Active Overall CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetTotalProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_Create() Local $aCPUTimes, $aCPUsUsage[2] $aCPUTimes = _CPUGetTotalProcessorTimes() If @error Then Return SetError(@error, @extended, "") ; Total $aCPUsUsage[0] = $aCPUTimes[1] + $aCPUTimes[2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[1] = $aCPUTimes[1] + $aCPUTimes[2] - $aCPUTimes[0] Return $aCPUsUsage EndFunc ; ============================================================================================== ; Func _CPUsUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns an array of CPU Usage information for all processors. ; ; Returns: ; Success: Array of CPU Usage -> 1 for each processor + 1 for Overall [@extended = # of processors] ; [0..n] = CPU Usage (Percentage) ; [#CPUs] = CPUs Overall Usage (Percentage) ; Failure: "" with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: NTSTATUS returned error code, @extended contains error code ; @error = 4: Invalid length returned, @extended is length ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUsUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage, 2) < 2 Then Return SetError(1, 0, "") Local $nTotalCPUs, $aUsage, $aCPUsCurInfo Local $nTotalActive, $nTotal Local $nOverallActive, $nOverallTotal $aCPUsCurInfo = _CPUsUsageTracker_Create() If @error Then Return SetError(@error, @extended, "") $nTotalCPUs = $aCPUsCurInfo[0][0] Dim $aUsage[$nTotalCPUs + 1] $nOverallActive = 0 $nOverallTotal = 0 For $i = 1 To $nTotalCPUs $nTotal = $aCPUsCurInfo[$i][0] - $aCPUsUsage[$i][0] $nTotalActive = $aCPUsCurInfo[$i][1] - $aCPUsUsage[$i][1] $aUsage[$i - 1] = Round($nTotalActive * 100 / $nTotal, 1) $nOverallActive += $nTotalActive $nOverallTotal += $nTotal Next $aUsage[$nTotalCPUs] = Round( ($nOverallActive / $nTotalCPUs) * 100 / ($nOverallTotal / $nTotalCPUs), 1) ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return SetExtended($nTotalCPUs, $aUsage) EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns CPU Usage information [Overall processor usage] ; ; Returns: ; Success: CPU Usage (Percentage) ; Failure: 0 with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage) < 2 Then Return SetError(1, 0, "") Local $aCPUsCurInfo, $fUsage, $nTotalActive, $nTotal $aCPUsCurInfo = _CPUOverallUsageTracker_Create() If @error Then Return SetError(@error, @extended, 0) $nTotal = $aCPUsCurInfo[0] - $aCPUsUsage[0] $nTotalActive = $aCPUsCurInfo[1] - $aCPUsUsage[1] ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return Round($nTotalActive * 100 / $nTotal, 1) EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText ; CPU Usage for all CPU's Local $iTotalCPUs, $aCPUsUsageTracker, $aPercents ; Overall CPU Usage Tracker ; (GetSystemTimes) ;~ Local $aCPUOverallTracker ; CPUs Usage Tracker $aCPUsUsageTracker = _CPUsUsageTracker_Create() If @error Then Exit ConsoleWrite("Error calling _CPUsUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) ; Overall CPU Usage tracker ;~ $aCPUOverallTracker = _CPUOverallUsageTracker_Create() ;~ If @error Then Exit ConsoleWrite("Error calling _CPUOverallUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) $iTotalCPUs = $aCPUsUsageTracker[0][0] ConsoleWrite("Total # CPU's: " & $iTotalCPUs & @CRLF) Sleep(250) $hSplash=SplashTextOn("CPU Usage Information [" & $iTotalCPUs & " total CPU's]", "", _ 240, 20 + ($iTotalCPUs + 1) * 35, Default, Default, 16, Default, 12) ; Start loop Do $aPercents = _CPUsUsageTracker_GetUsage($aCPUsUsageTracker) $sSplashText="" For $i=0 To $iTotalCPUs - 1 $sSplashText &= "CPU #"& $i+1 & ": " & $aPercents[$i] & " %" & @CRLF Next $sSplashText &= @CRLF &"[Overall CPU Usage] :" & $aPercents[$iTotalCPUs] & " %" & @CRLF ; Alternative, if all we wanted was Overall CPU Usage: ;~ $sSplashText &= @CRLF &"[Overall CPU Usage] :" & _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed _ Overall CPU Usage (and Idle calculation) example: ; ======================================================================================================== ; <CPU_ProcessorUsageOverall.au3> ; ; Example of reading combined overall CPU usage and deducing Idle CPU usage as well ; Readings are shown in a 'Splash' window ; ; Functions: ; _CPUGetTotalProcessorTimes() ; Gets Overall (combined CPUs) Processor Times ; _CPUOverallUsageTracker_Create() ; Creates a CPU usage tracker for Overall CPU usage ; _CPUOverallUsageTracker_GetUsage(); Updates CPU usage tracker and returns CPU usage [Overall Usage] ; ; External Functions: ; _CPUGetIndividualProcessorTimes() ; Returns an array of CPU usage info for individual processors ; _CPUsUsageTracker_Create() ; Creates a CPU usage tracker for all CPUs ; _CPUsUsageTracker_GetUsage() ; Updates CPU usage tracker and returns a CPU usage array ; ; See also: ; <CPU_ProcessorUsage.au3> ; Individual CPU processor usage example ; Performance Counters UDF ; ; ; Author: Ascend4nt ; ======================================================================================================== ; --- UDF's --- ; ============================================================================================== ; Func _CPUGetTotalProcessorTimes() ; ; Gets the total (combined CPUs) system processor times (as FILETIME) ; Note that Kernel Mode time includes Idle Mode time, so a proper calculation of usage time is ; Kernel + User - Idle ; And percentage (based on two readings): ; (Kernel_b - Kernel_a) + (User_b - User_a) - (Idle_b - Idle_a) * 100 ; / (Kernel_b - Kernal_a) + (User_b - User_a) ; ; O/S Requirements: min. Windows XP SP1+ ; ; Returns: ; Success: Array of info for total (combined CPU's) processor times: ; [0] = Idle Mode Time ; [1] = Kernel Mode Time -> NOTE This INCLUDES Idle Time ; [2] = User Mode Time ; ; Failure: "" with @error set: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUGetTotalProcessorTimes() Local $aRet, $aTimes $aRet = DllCall("kernel32.dll", "bool", "GetSystemTimes", "uint64*", 0, "uint64*", 0, "uint64*", 0) If @error Then Return SetError(2, @error, "") If Not $aRet[0] Then Return SetError(3, 0, "") Dim $aTimes[3] = [ $aRet[1], $aRet[2], $aRet[3] ] Return $aTimes EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_Create() ; ; Creates a CPU usage tracker array for Overall combined processors usage. ; This array should be passed to _CPUOverallUsageTracker_GetUsage() to get ; current usage information. ; ; Returns: ; Success: An array used to track Overall CPU usage ; Array 'internal' format: ; $arr[0] = Total Overall CPU Time (Kernel + User Mode) ; $arr[1] = Total Active Overall CPU Time (Kernel + User - Idle) ; ; Failure: "" with @error set [reflects _CPUGetTotalProcessorTimes codes]: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_Create() Local $aCPUTimes, $aCPUsUsage[2] $aCPUTimes = _CPUGetTotalProcessorTimes() If @error Then Return SetError(@error, @extended, "") ; Total $aCPUsUsage[0] = $aCPUTimes[1] + $aCPUTimes[2] ; TotalActive (Kernel Time includes Idle time, so we need to subtract that) $aCPUsUsage[1] = $aCPUTimes[1] + $aCPUTimes[2] - $aCPUTimes[0] Return $aCPUsUsage EndFunc ; ============================================================================================== ; Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) ; ; Updates a CPUsUsage array and returns CPU Usage information [Overall processor usage] ; ; Returns: ; Success: CPU Usage (Percentage) ; Failure: 0 with @error set to 1 for invalid parameters, or: ; @error = 2: DLLCall error, @extended = error returned from DLLCall ; @error = 3: API call returned False - call GetLastError for more info ; ; Author: Ascend4nt ; ============================================================================================== Func _CPUOverallUsageTracker_GetUsage(ByRef $aCPUsUsage) If Not IsArray($aCPUsUsage) Or UBound($aCPUsUsage) < 2 Then Return SetError(1, 0, "") Local $aCPUsCurInfo, $fUsage, $nTotalActive, $nTotal $aCPUsCurInfo = _CPUOverallUsageTracker_Create() If @error Then Return SetError(@error, @extended, 0) $nTotal = $aCPUsCurInfo[0] - $aCPUsUsage[0] $nTotalActive = $aCPUsCurInfo[1] - $aCPUsUsage[1] ; Replace current usage tracker info $aCPUsUsage = $aCPUsCurInfo Return Round($nTotalActive * 100 / $nTotal, 1) EndFunc ; -------------------- HOTKEY FUNCTION & VARIABLE -------------------- Global $bHotKeyPressed=False Func _EscPressed() $bHotKeyPressed=True EndFunc ; -------------------- MAIN PROGRAM CODE -------------------- HotKeySet("{Esc}", "_EscPressed") Local $hSplash, $sSplashText ; Overall CPU Usage Tracker ; (GetSystemTimes) Local $aCPUOverallTracker, $fPercent ; Overall CPU Usage tracker $aCPUOverallTracker = _CPUOverallUsageTracker_Create() If @error Then Exit ConsoleWrite("Error calling _CPUOverallUsageTracker_Create():" & @error & ", @extended = " & @extended & @CRLF) Sleep(250) $hSplash=SplashTextOn("CPU [Overall] Usage Information", "", _ 240, 100, Default, Default, 16, Default, 12) ; Start loop Do $fPercent = _CPUOverallUsageTracker_GetUsage($aCPUOverallTracker) $sSplashText="" $sSplashText &= "[Overall CPU Usage] :" & $fPercent & " %" & @CRLF $sSplashText &= "[Idle] : " & (100 - $fPercent) & " %" & @CRLF $sSplashText &= @CRLF & "[Esc] exits" ControlSetText($hSplash, "", "[CLASS:Static; INSTANCE:1]", $sSplashText) Sleep(500) Until $bHotKeyPressed CPU_ProcessorUsageOverall.au31 point
-
Hi, A long time ago i was looking for a way to set color/font for seperate parts inside label control. I even posted a Feature request about this issue, but back then i quickly realized (well, actualy it's Valik ho told me ) that this would be almost impossible to do (for my anyway). But today i found a tricky way to do that - I managed to build a function, that is kind of html-tag parser. It creates a label control for each text data that is wrapped with <font> tag (or not, but then the control is not formatted). Function Header: ; #FUNCTION# ==================================================================================================== ; Name...........: _GUICtrlTFLabel_Create ; Description....: Creates Text Formatted Label control(s). ; Syntax.........: _GUICtrlTFLabel_Create($sData, $iLeft, $iTop [, $iWidth = -1 [, $iHeight = -1 [, $nStyle = -1 [, $nExStyle = -1 ]]]]) ; ; Parameters.....: $sData - Formatted data. To set formatted data use <font></font> tag for data string. ; * This tag supports the following parameters (when used, they *can* be wrapped with quotes): ; Color - Text *Color* of data between the tags. ; Size - Text *Size*. ; Weight - Text *Weight* (the same values as used in GUICtrlSetFont()). ; Attrib - Text *Attributes* - The same values as used in GUICtrlSetFont(), ; or supported strings combined together: i(talic), u(nderlined), s(trike). ; Name - Text font *Name* (the same values as used in GUICtrlSetFont()). ; Style - Label control’s Style (applies for partial data between the tags). ; ExStyle - Label control’s ExStyle (applies for partial data between the tags). ; Cursor - Label control’s Cursor (can be cursor IDs, or strings, see description for MouseGetCursor). ; Top - Top position correction (relative to the global $iTop parameter). ; This is designed to avoid text corruption when using different font names/text's size. ; ; $iLeft - Left position (starting point in case when <font> tags are used) of label controls. ; $iTop - Top position of label controls. ; $iWidth - [Optional] Width of label control - Not used when <font> tags found in the data. ; $iHeight - [Optional] Height of label control - Not used when <font> tags found in the data. ; $nStyle - [Optional] (Forced) Style for entire label controls. Can be overridden by local Style parameter. ; $nExStyle - [Optional] (Forced) ExStyle for entire label controls. Can be overridden by local ExStyle parameter. ; ; Return values..: Success - Returns array of identifiers (Control IDs) of new created label controls. ; Failure - Returns 0. ; Author.........: G.Sandler (a.k.a MrCreatoR) ; Modified.......: ; Remarks........: ; Related........: ; Link...........: http://www.autoitscript.com/forum/index.php?showtopic=96986 ; Example........: Yes. ; =============================================================================================================== Example - Formatted Labels Editor: #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <ComboConstants.au3> #include <WindowsConstants.au3> #include "GUITFLabel.au3" Global $iEdit_Changed = 0, $aLabel_Ctrls $hGUI = GUICreate("Formatted Labels Editor", 650, 400) #Region Formate text panel GUICtrlCreateLabel("Size:", 10, 8, -1, 15) $nSize_Combo = GUICtrlCreateCombo("", 40, 5, 55, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|8|8.5|9|10|11|12|14|16|18|20|22|24|26|28|36|48|72", "None") GUICtrlCreateLabel("Weight:", 100, 8, -1, 15) $nWeight_Combo = GUICtrlCreateCombo("", 140, 5, 55, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|200|400|600|800|1000", "None") GUICtrlCreateLabel("Attrib:", 10, 33, -1, 15) $nAttrib_Combo = GUICtrlCreateCombo("", 40, 30, 155, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|italic|underlined|strike|italic+underlined+strike|italic+underlined|italic+strike|underlined+strike", "None") GUICtrlCreateLabel("Name:", 230, 15, 50, 15) $nName_Combo = GUICtrlCreateCombo("", 230, 30, 160, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|Arial|Comic Sans Ms|Tahoma|Times|Georgia|Lucida Sans Unicode|Verdana|Times New Roman|Courier New", "None") GUICtrlCreateLabel("Color:", 400, 15, 50, 15) $nColor_Combo = GUICtrlCreateCombo("", 400, 30, 60, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|Red|Green|Blue|Yellow|Orange|Gray|Brown|White", "None") GUICtrlCreateLabel("Bk Color:", 470, 15, 50, 15) $nBkColor_Combo = GUICtrlCreateCombo("", 470, 30, 60, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|Red|Green|Blue|Yellow|Orange|Gray|Brown|White", "None") GUICtrlCreateLabel("Cursor:", 540, 15, 50, 15) $nCursor_Combo = GUICtrlCreateCombo("", 540, 30, 100, 20, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)) GUICtrlSetData(-1, "None|POINTING|APPSTARTING|ARROW|CROSS|HELP|IBEAM|ICON|NO|SIZE|SIZEALL|SIZENESW|SIZENS|SIZENWSE|SIZEWE|UPARROW|WAIT|HAND", "None") #EndRegion Formate text panel GUICtrlCreateGroup("Select text and then select the formatting parameters from the above panel:", 10, 60, 630, 150) $nSrcText_Edit = GUICtrlCreateEdit("", 20, 80, 610, 120, $ES_NOHIDESEL) ;GUICtrlCreateLabel("Original text:", 20, 75, -1, 15) ;$nSrcText_Edit = GUICtrlCreateEdit("", 20, 90, 610, 40, $ES_NOHIDESEL) ;GUICtrlCreateLabel("Formatted text:", 20, 140, -1, 15) ;$nFormattedText_Edit = GUICtrlCreateEdit("", 20, 155, 610, 40, BitOR($ES_NOHIDESEL, $ES_READONLY)) GUICtrlCreateGroup("Preview:", 10, 230, 630, 130) GUICtrlSetFont(-1, 10, 800) $nClose_Button = GUICtrlCreateButton("Close", 10, 370, 60, 20) $nCopy_Button = GUICtrlCreateButton("Copy", 90, 370, 60, 20) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW, $hGUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $nClose_Button Exit Case $nSize_Combo, $nWeight_Combo, $nAttrib_Combo, $nName_Combo, $nColor_Combo, $nBkColor_Combo, $nCursor_Combo Local $sParam = StringLower(StringRegExpReplace(GUICtrlRead($nMsg - 1), 'h+|:', '')) Local $sValue = GUICtrlRead($nMsg) _SetFormattedText_Proc($sParam, $sValue) Case $nCopy_Button Local $sText = GUICtrlRead($nSrcText_Edit) If $sText <> "" Then ClipPut($sText) EndIf EndSwitch If $iEdit_Changed Then $iEdit_Changed = 0 For $i = 1 To UBound($aLabel_Ctrls)-1 GUICtrlDelete($aLabel_Ctrls[$i]) Next $aLabel_Ctrls = _GUICtrlCreateTFLabel(GUICtrlRead($nSrcText_Edit), 20, 245, 610, 110) EndIf WEnd Func _SetFormattedText_Proc($sParam, $sValue) If $sParam = "attrib" And Not StringRegExp($sValue, '(?i)A(None)?z') Then $aSplit = StringSplit($sValue, "+") $sValue = "" For $i = 1 To $aSplit[0] $sValue &= StringLeft($aSplit[$i], 1) If $i < $aSplit[0] Then $sValue &= "+" EndIf Next EndIf Local $sSelectionData = ControlCommand($hGUI, "", $nSrcText_Edit, "GetSelected") Local $sAddParamValue = ' ' & $sParam & '="' & $sValue & '"' If $sSelectionData = '' Then Return EndIf If StringRegExp($sSelectionData, '(?i)<font.*>.*</font>') Then $sSelectionData = StringRegExpReplace($sSelectionData, '(?i)(<font.*)( ' & $sParam & '=".*?")(.*>.*</font>)', '13') If Not StringRegExp($sValue, '(?i)A(None)?z') Then $sSelectionData = StringRegExpReplace($sSelectionData, '(?i)(<font.*)(>.*</font>)', '1' & $sAddParamValue & '2') EndIf If StringRegExp($sSelectionData, '(?i)<fonth*>.*</font>') Then $sSelectionData = StringRegExpReplace($sSelectionData, '(?i)<font.*>(.*)</font>', '1') EndIf ElseIf $sAddParamValue <> '' Then $sSelectionData = '<font' & $sAddParamValue & '>' & $sSelectionData & '</font>' EndIf _GUICtrlEdit_ReplaceSel($nSrcText_Edit, $sSelectionData) Local $iStart = StringInStr(GUICtrlRead($nSrcText_Edit), $sSelectionData)-1 Local $iEnd = $iStart + StringLen($sSelectionData) GUICtrlSendMsg($nSrcText_Edit, $EM_SETSEL, $iStart, $iEnd) EndFunc Func WM_COMMAND($hWnd, $nMsg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0xFFFF) Local $hCtrl = $lParam Switch $nID Case $nSrcText_Edit Switch $nNotifyCode Case $EN_CHANGE, $EN_UPDATE $iEdit_Changed = 1 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Screenshots: History version: Attachments: v1.5 GUITFLabel_UDF.zip v1.4 _GUICtrlCreateTFLabel_UDF.zip v1.3 _GUICtrlCreateTFLabel_UDF.zip v1.2 _GUICtrlCreateTFLabel_UDF.zip(Edited version - Previous downloads: 3 ) v1.1 _GUICtrlCreateTFLabel_UDF.zip v1.0 _GUICtrlCreateTFLabel_UDF.zip1 point
-
Just for example. Get certificate info. #include "WinINet.au3" _WinINet_Startup() ; Set variables Local $sURIScheme = "https" Local $sServerName = "mail.google.com" Local $iServerPort = 443 Local $hInternetOpen = _WinINet_InternetOpen("AutoIt/" & @AutoItVersion) If @error Then Exit ConsoleWrite("Open Internet connection: failed." & @LF) Local $hInternetOpenUrl = _WinINet_InternetOpenUrl($hInternetOpen, $sURIScheme & "://" & $sServerName, Default, $INTERNET_FLAG_SECURE) If @error Then Exit ConsoleWrite("Open Internet URL: failed." & @LF) ConsoleWrite("Query certificate info..." & @LF) Local $tBuffer = _WinINet_InternetQueryOption($hInternetOpenUrl, $INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT) Local $tINTERNET_CERTIFICATE_INFO = DllStructCreate($tagINTERNET_CERTIFICATE_INFO, DllStructGetPtr($tBuffer)) Local $tSystTime = DllStructCreate($tagSYSTEMTIME) ConsoleWrite("=====================================================" & @LF) DllCall("kernel32.dll", "bool", "FileTimeToSystemTime", "struct*", DllStructGetPtr($tINTERNET_CERTIFICATE_INFO, "StartTime"), "struct*", $tSystTime) $sResult = StringFormat("%04d-%02d-%02d %02d:%02d:%02d", _ DllStructGetData($tSystTime, "Year"), _ DllStructGetData($tSystTime, "Month"), _ DllStructGetData($tSystTime, "Day"), _ DllStructGetData($tSystTime, "Hour"), _ DllStructGetData($tSystTime, "Minute"), _ DllStructGetData($tSystTime, "Second")) ConsoleWrite("StartTime: " & $sResult & @LF) ConsoleWrite("=====================================================" & @LF) DllCall("kernel32.dll", "bool", "FileTimeToSystemTime", "struct*", DllStructGetPtr($tINTERNET_CERTIFICATE_INFO, "ExpiryTime"), "struct*", $tSystTime) $sResult = StringFormat("%04d-%02d-%02d %02d:%02d:%02d", _ DllStructGetData($tSystTime, "Year"), _ DllStructGetData($tSystTime, "Month"), _ DllStructGetData($tSystTime, "Day"), _ DllStructGetData($tSystTime, "Hour"), _ DllStructGetData($tSystTime, "Minute"), _ DllStructGetData($tSystTime, "Second")) ConsoleWrite("ExpiryTime: " & $sResult & @LF) ConsoleWrite("=====================================================" & @LF) ConsoleWrite("KeySize: " & DllStructGetData($tINTERNET_CERTIFICATE_INFO, "KeySize") & @LF) ConsoleWrite("=====================================================" & @LF) ConsoleWrite("SubjectInfo: " & DllStructGetData(DllStructCreate('char[256]', DllStructGetData($tINTERNET_CERTIFICATE_INFO, "SubjectInfo")), 1) & @LF) ConsoleWrite("=====================================================" & @LF) ConsoleWrite("IssuerInfo: " & DllStructGetData(DllStructCreate('char[256]', DllStructGetData($tINTERNET_CERTIFICATE_INFO, "IssuerInfo")), 1) & @LF) ConsoleWrite("=====================================================" & @LF) ConsoleWrite("ProtocolName: " & DllStructGetData(DllStructCreate('char[256]', DllStructGetData($tINTERNET_CERTIFICATE_INFO, "ProtocolName")), 1) & @LF) ConsoleWrite("=====================================================" & @LF) ConsoleWrite("SignatureAlgName: " & DllStructGetData(DllStructCreate('char[256]', DllStructGetData($tINTERNET_CERTIFICATE_INFO, "SignatureAlgName")), 1) & @LF) ConsoleWrite("=====================================================" & @LF) ConsoleWrite("EncryptionAlgName: " & DllStructGetData(DllStructCreate('char[256]', DllStructGetData($tINTERNET_CERTIFICATE_INFO, "EncryptionAlgName")), 1) & @LF) ConsoleWrite("=====================================================" & @LF) _WinINet_InternetCloseHandle($hInternetOpenUrl) _WinINet_InternetCloseHandle($hInternetOpen) _WinINet_Shutdown()1 point
-
Try this: #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Opt("TrayIconHide", 1) HotKeySet("{ESC}", "_Exit") Global Const $Process_All_Access = 0x1F0FFF Global $CreateTime = DllStructCreate("dword;dword") Global $ExitTime = DllStructCreate("dword;dword") Global $KernelTime = DllStructCreate("dword;dword") Global $UserTime = DllStructCreate("dword;dword") Global $FileTime = DllStructCreate("dword;dword") Global $SystemTime = DllStructCreate("ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort") Global $IdleTime = DllStructCreate("dword;dword") Global $sUserTime, $sKernelTime, $eUserTime, $eKernelTime Global $ret, $hour, $minutes, $seconds, $milliseconds Global $ProcHandle, $Process_CPU_Usage Global $PID, $CPUTime, $mem, $prg Global $logical_cpus = CPU() Global $hProc Global $GUI, $info $prg = "calc.exe" Run($prg) Sleep(500) $PID = ProcessExists($prg) If $PID = 0 Then ConsoleWrite(@CRLF & "ERROR! Process " & $prg & " not found! Aborting..." & @CRLF) Exit EndIf Global $iMemo, $hDebugGUI $GUI = GUICreate("Process Information v0.35 Beta by UEZ - Press ESC to quit! Just do some calculations...", 740, 25, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS)) $iMemo = GUICtrlCreateEdit("", -1, -1, 820) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUICtrlSetBkColor($iMemo, 0xFFFFFF) GUISetState() $ProcHandle = DllCall("kernel32.dll", "hwnd", "OpenProcess", "dword", $Process_All_Access, "int", False, "dword", $PID) $ProcHandle = $ProcHandle[0] ;~ ConsoleWrite(@CRLF & @CRLF & "Process Information v0.30 Beta by UEZ" & @CRLF) ;~ ConsoleWrite("=====================================" & @CRLF & @CRLF) ;~ ConsoleWrite("(Press ESC to exit)" & @CRLF) While 1 $CPUTime = _GetProcTime($ProcHandle) $mem = _ProcessGetMem($ProcHandle) / 1024 $hour = Int($CPUTime / 10000000 / 3600) $minutes = Int($CPUTime / 10000000 / 60) If $minutes < 10 Then $minutes = "0" & $minutes $seconds = Round((Int($CPUTime / 10000000) / 60 - Int($CPUTime / 10000000 / 60)) * 60, 0) If $seconds < 10 Then $seconds = "0" & $seconds $milliseconds = Round((Int($CPUTime / 10000) / 1000 - Int(Int($CPUTime / 10000) / 1000)) * 1000, 0) If $milliseconds < 10 Then $milliseconds = "00" & $milliseconds If $milliseconds > 9 And $milliseconds < 100 Then $milliseconds = "0" & $milliseconds $info = @CR & $prg & " | PID: " & $PID & " | CPU time: " & $hour & ":" & $minutes & ":" & $seconds & "." & $milliseconds & " (h:m:s.ms) | Mem usage: " & $mem & " KB | CPU usage: " & $Process_CPU_Usage & " % " & @CR MemoWrite($info) ;~ ConsoleWrite($prg & " | PID: " & $PID & " | CPU time: " & $hour & ":" & $minutes & ":" & $seconds & "." & $milliseconds & " (h:m:s.ms) | Mem usage: " & $mem & " KB | CPU usage: " & $Process_CPU_Usage & " % " & @CR) Sleep(1000) If Not ProcessExists($PID) Then _Exit() WEnd Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage) EndFunc ;==>MemoWrite Func _GetProcTime($ProcessHandle) $ret = DllCall("kernel32.dll", "int", "GetProcessTimes", "int", $ProcessHandle, "ptr", DllStructGetPtr($CreateTime), "ptr", DllStructGetPtr($ExitTime), "ptr", DllStructGetPtr($KernelTime), "ptr", DllStructGetPtr($UserTime)) If $ret[0] = 0 Then ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessTimes call" & @CRLF) SetError(1, 0, $ret[0]) EndIf $sKernelTime = DllStructGetData($KernelTime, 1) $sUserTime = DllStructGetData($UserTime, 1) $Process_CPU_Usage = Floor(($sKernelTime - $eKernelTime + $sUserTime - $eUserTime) / 100000 / $logical_cpus) If $Process_CPU_Usage > 100 Then $Process_CPU_Usage = "100" $eKernelTime = $sKernelTime $eUserTime = $sUserTime Return $sUserTime + $sKernelTime EndFunc ;==>_GetProcTime Func _ProcessGetMem($ProcessHandle) ;get physical memory of the process -> http://msdn.microsoft.com/en-us/library/ms683219%28VS.85%29.aspx Local $structPROCESS_MEMORY_COUNTERS, $structPROCESS_MEMORY_COUNTERS_EX, $nSize, $aRet If @OSVersion <> "WIN_7" Then $structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword cb; dword PageFaultCount; dword_ptr PeakWorkingSetSize; dword_ptr WorkingSetSize; " & _ "dword_ptr QuotaPeakPagedPoolUsage; dword_ptr QuotaPagedPoolUsage; dword_ptr QuotaPeakNonPagedPoolUsage; " & _ "dword_ptr QuotaNonPagePoolUsage; dword_ptr PagefileUsage; dword_ptr PeakPagefileUsage") ;http://msdn.microsoft.com/en-us/library/ms684877%28VS.85%29.aspx $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS) $aRet = DllCall("psapi.dll", "int", "GetProcessMemoryInfo", "hwnd", $ProcessHandle, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize) ;call GetProcessMemoryInfo If $aRet[0] = 0 Then ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessMemoryInfo call" & @LF) SetError(1, 0, $aRet[0]) EndIf Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "WorkingSetSize") Else $structPROCESS_MEMORY_COUNTERS_EX = DllStructCreate("dword cb; dword PageFaultCount; dword_ptr PeakWorkingSetSize; dword_ptr WorkingSetSize; " & _ "dword_ptr QuotaPeakPagedPoolUsage; dword_ptr QuotaPagedPoolUsage; dword_ptr QuotaPeakNonPagedPoolUsage; " & _ "dword_ptr QuotaNonPagePoolUsage; dword_ptr PagefileUsage; dword_ptr PeakPagefileUsage; " & _ "dword_ptr PrivateUsage") ;http://msdn.microsoft.com/en-us/library/ms684877%28VS.85%29.aspx $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS_EX) $aRet = DllCall("Kernel32.dll", "int", "K32GetProcessMemoryInfo", "hwnd", $ProcessHandle, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS_EX), "dword", $nSize) ;call GetProcessMemoryInfo If $aRet[0] = 0 Then ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessMemoryInfo call" & @LF) SetError(1, 0, $aRet[0]) EndIf ;~ ConsoleWrite("WorkingSetSize: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "WorkingSetSize") / 1024, 0) & @CRLF & _ ;~ "PrivateUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PrivateUsage") / 1024, 0) & @CRLF & @CRLF) Return DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PrivateUsage") EndIf EndFunc ;==>_ProcessGetMem Func CPU() ;get logical CPU(s) Local $i, $j, $x, $os, $colItems, $HW_Processor_Description, $HW_Processor_Manufacturer, $HW_Processor_MaxClockSpeed, $HW_Processor_Name, $HW_Processor_SocketDesignation Local $system = "Localhost" Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $system & "\root\cimv2") $colItems = $objWMIService.ExecQuery("SELECT Caption from Win32_OperatingSystem", "WQL", 0x30) ;get OS version If IsObj($colItems) Then For $objItem In $colItems $os = $objItem.Caption Next EndIf If StringInStr($os, "2003") > 0 Or StringInStr($os, "2000") > 0 Or StringInStr(StringUpper($os), "XP") > 0 Then $colItems = $objWMIService.ExecQuery("Select Name, Description, Manufacturer, MaxClockSpeed, SocketDesignation from Win32_Processor", "WQL", 0x30) Else $colItems = $objWMIService.ExecQuery("Select Name, Description, Manufacturer, MaxClockSpeed, SocketDesignation, NumberOfCores, NumberOfLogicalProcessors from Win32_Processor", "WQL", 0x30) EndIf If IsObj($colItems) Then $i = 0 $j = 0 $HW_Processor_SocketDesignation = "" For $objItem In $colItems ;get amount of logical CPUs If StringInStr(StringLower($HW_Processor_SocketDesignation), StringLower($objItem.SocketDesignation)) = 0 Then $HW_Processor_SocketDesignation &= $objItem.SocketDesignation & ", " EndIf $i = $i + 1 Next If StringInStr($os, "2003") > 0 Or StringInStr($os, "2000") > 0 Or StringInStr(StringUpper($os), "XP") > 0 Then $x = StringSplit(Remove_Last_Comma($HW_Processor_SocketDesignation), ",") $j = UBound($x) - 1 Else $i = $objItem.NumberOfCores $j = $objItem.NumberOfLogicalProcessors / $i EndIf If $j > $i Then $j = $i EndIf Return ($i) EndFunc ;==>CPU Func Remove_Last_Comma($str) If StringRight($str, 2) = ", " Then $str = StringMid($str, 1, StringLen($str) - 2) Return $str EndFunc ;==>Remove_Last_Comma Func _Exit() DllCall("kernel32.dll", "int", "CloseHandle", "int", $ProcHandle) DllCall("psapi.dll", "int", "CloseHandle", "hwnd", $ProcHandle) ProcessClose($pid) Exit EndFunc ;==>_Exit Just do some calculations... UEZ1 point
-
This is application that calculates π (Pi) with 2 different formulas, in first one, the calculation of the formula should perform only 1 core of your CPU, and in the other formula both cores participate in calculation, unfortunately AutoIt is limited to only 15 decimals, though you will never need more than first 4 dec. of Pi number The less time in calculation you get, the better your CPU is, you may post your results here if you like. Even if it's not working perfectly (cores ratio is not perfect), at least it has pretty gui, and it was fun building it. Many thanks to MrCreator for his ControlHover UDF LINK, many thanks to UEZ for his text on GDI+ LINK, many thanks to monoceres for sharing his knowledge on GDI+, many thanks to n3nE for help, and everyone else on General Help and Support. script requires <GUICtrlSetOnHover_UDF.au3> by MrCreator which can be downloaded here, or from his thread: LINK Edit: I forgot to add: GDI+ is working even if the user is moving window Edit2: "Please wait" on the beginning of the script is obtaining CPU name, it's slow operation, so I gave it it's own gui before main gui pops up =.= Edit3: Changed single core test pi formula to the one Super PI uses LINK previous downloads: 140 GUICtrlSetOnHover_UDF.au3 CPU_Benchmark.au31 point