Leaderboard
Popular Content
Showing content with the highest reputation on 05/25/2015 in all areas
-
This script demonstrate how to save the web page, or just the specified element to an image file. Two COM interface were used in the script (IViewObject2 for entire page, and IHTMLElementRender for an element) Some code was modified from IECapt. This script needs (Thanks to trancexx, she help me to solve a problem.) #Include <IE.au3> #Include <WinAPI.au3> #Include <ScreenCapture.au3> #Include <WindowsConstants.au3> #Include "AutoItObject.au3" _AutoItObject_StartUp() OnAutoItExitRegister('OnExit') WebCaptureTest("http://en.wikipedia.org/wiki/AutoIt", "Test1.png") ElementCaptureTest("http://en.wikipedia.org/wiki/AutoIt", "Test2.png") Func OnExit() _AutoItObject_Shutdown() EndFunc Func WebCaptureTest($Url, $ImageName) Local $hBmp = WebCapture($Url, 1280) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1280 Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 768, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 768) _IENavigate($oIE, $Url) Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc Func WebCapture($Url, $WebWidth = 1024) Local Const $DVASPECT_CONTENT = 1 Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}") Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);" Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", $WebWidth, 768, -1, -1) GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 768) _IENavigate($oIE, $url) Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $oIViewObject2 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2) If @Error Then Return SetError(1, 0, 0) Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject($hMemDc, $hBmp) Local $sRECT = DllStructCreate($tagRECT) DllStructSetData($sRECT, "Top", 0) DllStructSetData($sRECT, "Left", 0) DllStructSetData($sRECT, "Right", $Width) DllStructSetData($sRECT, "Bottom", $Height) $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) Return $hBmp EndFunc Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}") Local $dtagIHTMLElementRender = $dtagIUnknown & "DrawToDC hresult(hwnd);" Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = _AutoItObject_WarpInterface($oElement, $tIID_IHTMLElementRender, $dtagIHTMLElementRender) Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDc, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False) If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID) If Not IsObj($Obj) Then Return SetError(1, 0, 0) Local $pObj = _AutoItObject_IDispatchToPtr($Obj) If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0) Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown) Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0) If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0) Local $pInterface = $aCall[2] Return _AutoItObject_WrapperCreate($pInterface, $Tag) EndFunc1 point
-
I did this meanwhile: #include <GDIPlus.au3> #include <GUIConstantsEx.au3> _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test.jpg") ;create an image object based on a file Local $hGUI = GUICreate("GDI+ Example", 320, 320) GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a Graphics object from a window handle _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) ; $GDIP_SMOOTHINGMODE_HIGHQUALITY ;sets the graphics object rendering quality (antialiasing) Local $hBitmap = _GDIPlus_BitmapCreateEllipseFilled($hImage) Do _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, Random(1, 200), Random(1, 200), Random(1, 200), Random(1, 200)) ;draw ellipse with texture as a brush Sleep(200) Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup resources _GDIPlus_ImageDispose($hImage) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) Func _GDIPlus_BitmapCreateEllipseFilled($hBitmap, $iW = -1, $iH = -1, $iWrapMode = 0) If $iW = -1 Or $iH = -1 Then $iW = _GDIPlus_ImageGetWidth($hBitmap) $iH = _GDIPlus_ImageGetHeight($hBitmap) EndIf Local Const $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp) Local Const $hTexture = _GDIPlus_TextureCreate($hBitmap, $iWrapMode) _GDIPlus_GraphicsSetInterpolationMode($hCtxt, 7) _GDIPlus_GraphicsSetCompositingQuality($hCtxt, 2) _GDIPlus_GraphicsFillEllipse($hCtxt, 0, 0, $iW, $iH, $hTexture) _GDIPlus_BrushDispose($hTexture) _GDIPlus_GraphicsDispose($hCtxt) Return $hBmp EndFunc1 point
-
and an example to start the shell and just get an ls directory overview. #include <MsgBoxConstants.au3> ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "127.0.0.1" ;"localhost" ; "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 5037 ; Port used for the connection. Example() Func Example() TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified. Local $iSocket = TCPConnect($sIPAddress, $iPort) ; If an error occurred display the error code and return False. If @error Then ; The server is probably offline/port is not opened on the server. Local $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError) Return False Else Consolewrite("Connection successful" & @CRLF) EndIf ;Connect over usb TCPSend($iSocket, adbData("host:transport-usb")) $data=TCPRecv($iSocket,4096,0) consolewrite($data & @CRLF) ;Connect to the shell TCPSend($iSocket, adbData("shell:")) $data=TCPRecv($iSocket,4096,0) consolewrite($data & @CRLF) ;See the shell line $data=TCPRecv($iSocket,4096,0) consolewrite($data & @CRLF) ;Give the LS Command (do not forget CR) TCPSend($iSocket, "ls" & @CR) sleep(2000) $data=TCPRecv($iSocket,4096,0) consolewrite($data & @CRLF) ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>Example Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit ;Put hexLengthIn front of the data Func adbData($s) return hex(stringlen($s),4) & $s EndFunc1 point
-
Don't think this is a problem for AutoIt. The coder of the script might get confused and hence he might see unexpected results.1 point
-
It's good coding practice to close an open file before any other operation. When deleting the file this might not be a problem. But when copying the file there still might be some data in the cache not written to the file.1 point
-
1 point
-
Arik, I have no idea if it would be slower or faster - although I suspect that the difference would be minor. I suggest you run some comparisons between the code I posted above and this new version: #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <Array.au3> $sIniFile = @ScriptDir & "\Test.ini" $aSections = IniReadSectionNames($sIniFile) _ArrayColInsert($aSections, 1) ; Make into 2D array $sEntries = "" For $i = 1 To $aSections[0][0] ; Add app name alongside section name $aSections[$i][1] = IniRead($sIniFile, $aSections[$i][0], "AppName", "Error") $sEntries &= "|" & $aSections[$i][1] ; A leading "|" just replaces the current content so no need to exclude it from the first entry Next GUICreate("Test Program", 190, 40) $cComboBox = GUICtrlCreateCombo("", 10, 10, 170, 20, $CBS_DROPDOWNLIST) GUICtrlSetData($cComboBox, $sEntries) _GUICtrlComboBox_SetCueBanner($cComboBox, "Please select an application...") ; This way you do not get the text as an item in the combo GUISetState() While 1 Switch GUIGetMsg() Case $cComboBox $sAppName = GUICtrlRead($cComboBox) For $i = 1 To $aSections[0][0] If $sAppName = $aSections[$i][1] Then $aSectionRead = IniReadSection($sIniFile, $aSections[$i][0]) ; Read whole section in one go $sTargetFolder = $aSectionRead[_ArraySearch($aSectionRead, "TargetFolder")][1] ; Could replace _ArraySearch with hardcoded index if always in same order $sVersion = $aSectionRead[_ArraySearch($aSectionRead, "Version")][1] $iAppID = $i ; No point in looking any further ExitLoop EndIf Next MsgBox(0, $iAppID, "Application: " & $sAppName & @CRLF & "Target Folder: " & $sTargetFolder & @CRLF & "Version: " & $sVersion) Case $GUI_EVENT_CLOSE Exit EndSwitch WEndTo speed up the above, if you always have the items inside each section in the same order, you could skip the _ArraySearch and just hardcode the index value. Please let me know which version you find to be faster. M231 point
-
Click on item of a standard context menu
mycloutier reacted to LarsJ for a topic
If you see the context menu opens, then the most likely error is that 100 ms is too short waiting time on a network drive. This means that the subsequent code is executed before the context menu is open, and therefore fails. You can try to change the 100 ms to 1000 ms. If it works, you can gradually reduce the waiting time until it fails again. The waiting time should be as small as possible but large enough for the context menu to open.1 point -
Because you use AutoIt. The examples you are glued to are for development inside Visual Studio through MFC. Completely irrelevant and non-applicable for you. Considering you can't get answers from their dev team on how to use ActiveX controls, the best would be to drop the case. Btw, this is rather typical example of projects made by "modern" developers when they use super intelligent IDE and ultimately, as a result, fail to comprehend all the aspects of their project. I call that "check box development".1 point
-
Nice . How about the clean-up I perform at the end of the function? GUICtrlDelete($cObj) GUIDelete($hGUI) $oIViewObject2 = 0 $oIE = 0 When I set the GUI to visible I see it still exists after the function has finished, thus I assume a GUIDelete is appropriate. Is it advisable to delete the controls manually? And also the Objects, are those cleaned by the garbage collector? #include <IE.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> ; Runs fine with Beta 3.3.9.5+ If Int(StringReplace(@AutoItVersion, ".", "")) <= 3381 Then MsgBox(0, "Exit", "Requires AutoIt version > 3.3.8.1, try with Beta") Exit EndIf _WebCaptureTest("http://funk.eu", "Test1.png") Func _WebCaptureTest($Url, $ImageName) Local $hBmp = _WebCapture($Url, 1280) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc ;==>_WebCaptureTest Func _WebCapture($Url, $WebWidth = 1024) Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 768, -1, -1) Local $cObj = GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 768) _IELoadWaitTimeout(20000) ; 20 sec _IENavigate($oIE, $Url) _IELoadWait($oIE) Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $oIViewObject2 = ObjCreateInterface($oDocument, "{00000127-0000-0000-C000-000000000046}", "Draw hresult(dword;long;ptr;ptr;handle;handle;struct*;struct*;bool;ulong_ptr);") If @error Then Return SetError(1, 0, 0) Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject($hMemDC, $hBmp) Local $sRECT = DllStructCreate($tagRECT) DllStructSetData($sRECT, "Top", 0) DllStructSetData($sRECT, "Left", 0) DllStructSetData($sRECT, "Right", $Width) DllStructSetData($sRECT, "Bottom", $Height) $oIViewObject2.Draw(1, -1, 0, 0, $hDC, $hMemDC, $sRECT, 0, 0, 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) GUIDelete($hGUI) Return $hBmp EndFunc ;==>_WebCapture Edit: Added trancexx remarks from the next post, thanks a lot ...1 point
-
The Control Panel
argumentum reacted to LarsJ for a topic
The files and folders of the Control Panel can be enumerated with the IShellFolder and IEnumIDList interfaces. In this example (run cpGui.au3) the files and folders are shown in a GUI with a TreeView and a ListView. Double click an item (or press Enter) in the ListView to execute. Right click to show the context menu. Executing a program and showing the context menu are implemented with the IContextMenu interface. If you are running a 64 bit OS you must run this script (cpGui.au3) as a 64 bit program. Exceptions The Control Panel isn't as easy to enumerate as a normal file system folder. Especially on Vista and 7. Some containers or pages appears as folders but must be treated as files. Some items appears as both files and folders. And there can be some "empty" items without a display name that have to be removed. You have to do some exceptions to make everything look properly. cpPrint.au3 is a script to print the files and folders of the Control Panel in the Scite console. By comparing the output from the script with the real Control Panel you can figure out the exceptions. If you are running a 64 bit OS you must run this script (cpPrint.au3) as a 64 bit program. Here are some of the exceptions on my Windows 7 64 bit PC. Containers or pages that appears as folders but must be treated as files: Control Panel = ::{26EE0668-A00A-44D7-9371-BEB064C98683} --[\System and Security] = ::{26EE0668-A00A-44D7-9371-BEB064C98683}\5 ----[\Power Options] = ::{26EE0668-A00A-44D7-9371-BEB064C98683}\5\::{025A5937-A6BE-4686-A844-36FE4BEC8B6D} ----[\Windows Update] = ::{26EE0668-A00A-44D7-9371-BEB064C98683}\5\::{36EEF7DB-88AD-4E81-AD49-0E313F0C35F8} ----[\Windows Firewall] = ::{26EE0668-A00A-44D7-9371-BEB064C98683}\5\::{4026492F-2F69-46B8-B9BF-5654FC07E423} Empty item: Control Panel = ::{26EE0668-A00A-44D7-9371-BEB064C98683} --[\System and Security] = ::{26EE0668-A00A-44D7-9371-BEB064C98683}\5 ----[] = ::{26EE0668-A00A-44D7-9371-BEB064C98683}\5\::{25C64847-B900-48AD-A164-1B4F9B774650}The empty items (no display name, only parsing name) are probably caused by failed program installations or updates. And some exceptions on my Windows XP SP3. Items that appears as both files and folders: Control Panel = ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D} --[\Network Connections] = ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E} ----[\Local Area Connection] = {BA126ADB-2166-11D1-B1D0-00805FC1270E} ----[\Internet Connection] = {BA126AE2-2166-11D1-B1D0-00805FC1270E} ----[Local Area Connection] = {BA126ADB-2166-11D1-B1D0-00805FC1270E} ----[Internet Connection] = {BA126AE2-2166-11D1-B1D0-00805FC1270E} These exceptions are handled in the functions EnumTreeViewObjects() and EnumListViewObjects() in cpFuncs.au3. Remark that the Fonts folder is skipped in cpPrint.au3. Zipfile The zipfile below contains a number of files: cpGui.au3 - the GUI, run this filecpConsts.au3 - constants and globalscpFuncs.au3 - functions for the GUIContextMenu.au3 - context menucpPrint.au3 - print files and foldersCommon.au3 - common functionsFunctions.au3 - utilitiesGetIcon.au3 - icon functionsHourglassOff.au3 - turn hourglass offres\WSP.dll - NM_RETURN notifications in the ListViewIf the script fails for some reason and you are left with an hourglass cursor, then run HourglassOff.au3 to get the normal cursor back. For WSP.dll by Yashied see http://www.autoitscript.com/forum/index.php?showtopic=83621 post #16. You need APIConstants.au3 and WinAPIEx.au3 v3.8 by Yashied. Testet on Windows XP SP3 and Windows 7 64 bit. ControlPanel.7z1 point -
1 point