Leaderboard
Popular Content
Showing content with the highest reputation on 10/01/2011 in all areas
-
Yea, so did you compare the files when downloaded this way and normally? Are they different? For me they are an exact binary match.1 point
-
Try: InetGet("http://download1487.mediafire.com/cv288h1t41xg/e8ua3pjaac65x4t/FletchingCalc.exe" , @DesktopDir & "\FletchingCalc.exe")1 point
-
Could not stop playing around with your code ... ...1 point
-
The following 5 members have been promoted to MVPs. See, this forum isn't all about negative things: KaFuwraithduUEZwaterMat1 point
-
Variables should always be declared in the smallest scope possible in any language (for languages that support it). For example, don't front-load your functions with all the variable declarations. Declare variables right before they are used. If a variable doesn't need to exist in global scope then use it in local scope. Prefer function return values and function parameters to pass data around rather than global variables. Keep variables in existence no more than necessary.1 point
-
That's really not an API. An API would be more like this: #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Enum $GUI_HWND, $GUI_CLOSEBUTTON, $GUI_MAX Global $g_aGUI[$GUI_MAX] CreateGUI() GUISetState(@SW_SHOW, GUI_GetHWND()) WaitForClose() Func CreateGUI() GUI_SetHWnd(GUICreate("GUI")) GUI_SetCloseButton(GUICtrlCreateButton("Close", 5, 5, 50, 25)) GUICtrlSetOnEvent(GUI_GetCloseButton(), "OnClose") GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose") EndFunc ; CreateGUI() Func WaitForClose() While WinExists(GUI_GetHWND()) Sleep(50) WEnd EndFunc ; WaitForClose() Func OnClose() GUIDelete($g_aGUI[$GUI_HWND]) EndFunc ; OnClose() #Region API Func GUI_SetHWND($hWnd) $g_aGUI[$GUI_HWND] = $hWnd EndFunc ; GUI_SetHWnd() Func GUI_GetHWND() Return $g_aGUI[$GUI_HWND] EndFunc ; GUI_GetHWND() Func GUI_SetCloseButton($id) $g_aGUI[$GUI_CLOSEBUTTON] = $id EndFunc ; GUI_SetCloseButton() Func GUI_GetCloseButton() Return $g_aGUI[$GUI_CLOSEBUTTON] EndFunc ; GUI_GetCloseButton() #EndRegion API The idea is to provide an interface to call into. The interface is all the user should interact with. The fact that the implementation uses a global variable is irrelevant. Here's a better example of an interface and implementation that are separate that doesn't use global variables: ; =================================================================== ; Project: DocLib Library ; Description: Functions for building the AutoIt documentation. ; Author: Jason Boggs <vampire DOT valik AT gmail DOT com> ; =================================================================== #include-once #Region Members Exported #cs Exported Functions SciTE_Create() - Creates a SciTE object that can be used with SciTE_* functions. The handle returned must be destroyed with SciTE_Destroy(). SciTE_Destroy(ByRef $vHandle) - Destroys a SciTE handle created by SciTE_Create(). SciTE_OpenFile($vHandle, $sFile) - Opens the specified file in the SciTE instance. SciTE_ExportAsHtml($vHandle, $sFile) - Exports the active file to the specified destination. SciTE_CloseFile($vHandle) - Closes the active file. SciTE_SendCommand($vHandle, $sCmd, $hResponse = 0) - Sends the specified command to the SciTE instance. _FileListToArraySorted($sPath, $sFilter = "*", $iFlag = 0) - Returns a file list in a sorted array. #ce Exported Functions #EndRegion Members Exported #Region Includes #include <Array.au3> #include <File.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #EndRegion Includes #Region Global Variables Global Enum $SCITE_MAINHWND, $SCITE_DIRECTORHWND, $SCITE_MAX #EndRegion Global Variables #Region Library Initialization #EndRegion Library Initialization #Region Public Members #Region SciTE Functions #Region SciTE_Create() ; =================================================================== ; SciTE_Create() ; ; Creates a SciTE object that can be used with SciTE_* functions. The handle returned must ; be destroyed with SciTE_Destroy(). ; Parameters: ; None. ; Returns: ; Success: A handle for use in other SciTE_* functions. ; Failure: 0, sets @error to non-zero as follows: ; 1 - SciTE could not be found. ; 2 - The required properties file could not be found. ; =================================================================== Func SciTE_Create() ; Get the ptah to the required files. Local $sSciTE = __SciTE_FindFile("SciTE.exe") Local $sPropertiesFile = __SciTE_FindFile("au3.keywords.properties") If Not $sSciTE Then Return SetError(1, 0, 0) If Not $sPropertiesFile Then Return SetError(2, 0, 0) ; The -import command requires the .properties extenstion to be stripped. $sPropertiesFile = StringTrimRight($sPropertiesFile, 11) ; Set SciTE_HOME to a directory that doesn't contain global/user properties ; files. This ensures the import statement works correctly. EnvSet("SciTE_HOME", @TempDir) ; Build the full command to start SciTE. $sSciTE = StringFormat('"%s" "-import %s" -check.if.already.open=0', $sSciTE, $sPropertiesFile) ; Run SciTE hidden and store the PID. Local $pid = Run($sSciTE) ; Build the handle to return. Local $vHandle[$SCITE_MAX] $vHandle[$SCITE_MAINHWND] = __SciTE_MainHWNDFromPID($pid) $vHandle[$SCITE_DIRECTORHWND] = __SciTE_DirectorHWNDFromPID($pid) ; Hide the SciTE window because it ignores @SW_HIDE. WinSetState($vHandle[$SCITE_MAINHWND], "", @SW_HIDE) ; Return the handle. Return $vHandle EndFunc ; SciTE_Create() #EndRegion SciTE_Create() #Region SciTE_Destroy() ; =================================================================== ; SciTE_Destroy(ByRef $vHandle) ; ; Destroys a SciTE handle created by SciTE_Create(). ; Parameters: ; $vHandle - IN/OUT - The handle to SciTE. ; Returns: ; Sets @error to non-zero if the handle was invalid. ; =================================================================== Func SciTE_Destroy(ByRef $vHandle) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) SciTE_SendCommand($vHandle, "quit:") $vHandle = 0 EndFunc ; SciTE_Destroy() #EndRegion SciTE_Destroy() #Region SciTE_OpenFile() ; =================================================================== ; SciTE_OpenFile($vHandle, $sFile) ; ; Opens the specified file in the SciTE instance. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; $sFile - IN - The file to open. ; Returns: ; Sets @error to non-zero if the handle was invalid. ; =================================================================== Func SciTE_OpenFile($vHandle, $sFile) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) Return SciTE_SendCommand($vHandle, "open:" & StringReplace($sFile, "\", "\\")) EndFunc ; SciTE_OpenFile() #EndRegion SciTE_OpenFile() #Region SciTE_ExportAsHtml() ; =================================================================== ; SciTE_ExportAsHtml($vHandle, $sFile) ; ; Exports the active file to the specified destination. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; $sFile - IN - The destination file to save to. ; Returns: ; Sets @error to non-zero if the handle was invalid. ; =================================================================== Func SciTE_ExportAsHtml($vHandle, $sFile) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) Return SciTE_SendCommand($vHandle, "exportashtml:" & StringReplace($sFile, "\", "\\")) EndFunc ; SciTE_ExportAsHtml() #EndRegion SciTE_ExportAsHtml() #Region SciTE_CloseFile() ; =================================================================== ; SciTE_CloseFile($vHandle) ; ; Closes the active file. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; Returns: ; Sets @error to non-zero if the handle was invalid. ; =================================================================== Func SciTE_CloseFile($vHandle) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) Return SciTE_SendCommand($vHandle, "close:") EndFunc ; SciTE_CloseFile() #EndRegion SciTE_CloseFile() #Region SciTE_SendCommand() ; =================================================================== ; SciTE_SendCommand($vHandle, $sCmd, $hResponse = 0) ; ; Sends the specified command to the SciTE instance. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; $sCmd - IN - The command to send. ; $hResponse - IN/OPTIONAL - The optional HWND to a window that will receive a response. ; Returns: ; Sets @error to non-zero if the handle was invalid. ; =================================================================== Func SciTE_SendCommand($vHandle, $sCmd, $hResponse = 0) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) ; Create a string to hold the command. Local $tCmd = DllStructCreate(StringFormat("char[%d]", StringLen($sCmd) + 1)) DllStructSetData($tCmd, 1, $sCmd) ; Create the COPYDATA structure. Local $tCopyDataStruct = DllStructCreate("ULONG_PTR dwData; DWORD cbData; ptr lpData;") DllStructSetData($tCopyDataStruct, "dwData", 1) DllStructSetData($tCopyDataStruct, "cbData", StringLen($sCmd) + 1) DllStructSetData($tCopyDataStruct, "lpData", DllStructGetPtr($tCmd)) ; Send the command. Return _SendMessageA(__SciTE_GetDirectorHWND($vHandle), $WM_COPYDATA, $hResponse, DllStructGetPtr($tCopyDataStruct), 0, "hwnd", "ptr") EndFunc ; SciTE_SendCommand() #EndRegion SciTE_SendCommand() #EndRegion SciTE Functions #Region _FileListToArraySorted() ; =================================================================== ; _FileListToArraySorted($sPath, $sFilter = "*", $iFlag = 0) ; ; Returns a file list in a sorted array. ; Parameters: ; $sPath - IN - The root path to search. ; $sFilter - IN/OPTIONAL - The file filter to search for. ; $iFlag - IN/OPTIONAL - Specifies whether to return files folders or both: ; 0 - Return both files and folders (Default). ; 1 - Return files only. ; 2 - Return Folders only ; Returns: ; Sucess: A sorted array. ; Failure: 0, sets @error to non-zero. ; =================================================================== Func _FileListToArraySorted($sPath, $sFilter = "*", $iFlag = 0) Local $aFiles = _FileListToArray($sPath, $sFilter, $iFlag) Local Const $nError = @error, $nExtended = @extended _ArraySort($aFiles, 0, 1) Return SetError($nError, $nExtended, $aFiles) EndFunc ; _FileListToArraySorted() #EndRegion _FileListToArraySorted() #EndRegion Public Members #Region Private Members #Region SciTE Private Functions #Region __SciTE_FindFile() ; =================================================================== ; __SciTE_FindFile($sFile) ; ; Searches for the specified file in the standard SciTE locations. ; Parameters: ; $sFile - IN - The filename to search for. ; Returns: ; Success - The path to the specified file. ; Failure - An empty string. ; =================================================================== Func __SciTE_FindFile($sFile) ; Look for the file relative to docs\build. Local $sLocation = "..\..\install\SciTE\" & $sFile If Not FileExists($sLocation) Then ; Look for the file in the AutoIt SciTE directory. $sLocation = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\SciTE\" & $sFile ; Return an empty string if the file was not found. If Not FileExists($sLocation) Then Return "" EndIf ; Return the location if the file was found. Return $sLocation EndFunc ; __SciTE_FindFile() #EndRegion __SciTE_FindFile() #Region __SciTE_GetMainHWND() ; =================================================================== ; __SciTE_GetMainHWND($vHandle) ; ; Retrieves the SciTE window handle. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; Returns: ; Success - The SciTE window handle. ; Failure - 0, sets @error to non-zero. ; =================================================================== Func __SciTE_GetMainHWND($vHandle) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) Return $vHandle[$SCITE_MAINHWND] EndFunc ; __SciTE_GetMainHWND() #EndRegion __SciTE_GetMainHWND() #Region __SciTE_GetDirectorHWND() ; =================================================================== ; __SciTE_GetDirectorHWND($vHandle) ; ; Retrieves the SciTE Director window handle. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; Returns: ; Success - The SciTE Director window handle. ; Failure - 0, sets @error to non-zero. ; =================================================================== Func __SciTE_GetDirectorHWND($vHandle) If Not __SciTE_IsValid($vHandle) Then Return SetError(-1, 0, 0) Return $vHandle[$SCITE_DIRECTORHWND] EndFunc ; __SciTE_GetDirectorHWND() #EndRegion __SciTE_GetDirectorHWND() #Region __SciTE_MainHWNDFromPID() ; =================================================================== ; __SciTE_MainHWNDFromPID($pid) ; ; Retrieves the SciTE window from the specified PID. ; Parameters: ; $pid - IN - The PID to get the SciTE window from. ; Returns: ; Success - The handle to the SciTE window. ; Failure - 0. ; =================================================================== Func __SciTE_MainHWNDFromPID($pid) Return __SciTE_HWNDFromPID($pid, "[CLASS:SciTEWindow]") EndFunc ; __SciTE_MainHWNDFromPID() #EndRegion __SciTE_MainHWNDFromPID() #Region __SciTE_DirectorHWNDFromPID() ; =================================================================== ; __SciTE_DirectorHWNDFromPID($pid) ; ; Retrieves the SciTE Director window from the specified PID. ; Parameters: ; $pid - IN - The PID to get the SciTE Director window from. ; Returns: ; Success - The handle to the SciTE Director window. ; Failure - 0. ; =================================================================== Func __SciTE_DirectorHWNDFromPID($pid) Return __SciTE_HWNDFromPID($pid, "[CLASS:DirectorExtension]") EndFunc ; __SciTE_DirectorHWNDFromPID() #EndRegion __SciTE_DirectorHWNDFromPID() #Region __SciTE_HWNDFromPID() ; =================================================================== ; __SciTE_HWNDFromPID($pid, $sWindowDescription, $nTimeout = 5000) ; ; Description. ; Parameters: ; $pid - IN - The PID to get the window from. ; $sWindowDescription - IN - An advanced window description of the window. ; $nTimeout - IN/OPTIONAL - How long to wait for the window before giving up. ; Returns: ; Success - The handle to the specified window. ; Failure - 0. ; =================================================================== Func __SciTE_HWNDFromPID($pid, $sWindowDescription, $nTimeout = 5000) Local $nStart = TimerInit() While TimerDiff($nStart) < $nTimeout Local $aList = WinList($sWindowDescription) For $i = 1 To UBound($aList) - 1 If WinGetProcess($aList[$i][1]) = $pid Then Return $aList[$i][1] Next Sleep(250) WEnd Return 0 EndFunc ; __SciTE_HWNDFromPID() #EndRegion __SciTE_HWNDFromPID() #Region __SciTE_IsValid() ; =================================================================== ; __SciTE_IsValid($vHandle) ; ; Tests if the specified handle is valid. ; Parameters: ; $vHandle - IN - The handle to SciTE. ; Returns: ; True - The handle is valid. ; False - The handle is not valid. ; =================================================================== Func __SciTE_IsValid($vHandle) Return UBound($vHandle) = $SCITE_MAX EndFunc ; __SciTE_IsValid() #EndRegion __SciTE_IsValid() #EndRegion SciTE Private Functions #EndRegion Private Members SciTE_Create() returns an opaque handle. The caller doesn't need to worry about what the handle really is, they just pass it to other SciTE_* functions. Even the SciTE_* functions aren't bound to an implementation. If SciTE had a COM interface I could easily change the code to use the COM interface and wouldn't have to touch a single line in any of the SciTE_* functions nor would the caller of the SciTE_* functions need to be changed. Only the __SciTE functions would change because they are the only parts of the code that deal with the implementation. A design like this is far more flexible and future-proof than a design using global variables. I have pushed all the nasty details far away from where things are used. Things are abstracted away into concepts. The caller only wants to automate SciTE, the caller doesn't care if it uses messages, window automation, a COM interface or command line arguments. The interface doesn't care about those details, either. It only exists to provide an access point between the caller and the raw implementation of the behavior.1 point