Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/18/2021 in all areas

  1. hello ! just for fun simple code to call dll api in new thread ... *update 21/02/2021 -add callback for return api call -add x64 ;by celtic 88 #include <Memory.au3> #include <WinAPISys.au3> #include <WinAPIProc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIEx.au3> #include <WindowsConstants.au3> #include <WinAPIMem.au3> Global $thread_Class = 'thread_Class1' Local $hProc = DllCallbackRegister('thread_WM', 'lresult', 'hwnd;uint;wparam;lparam') Local $tClass = DllStructCreate('wchar[' & StringLen($thread_Class) + 1 & ']') DllStructSetData($tClass, 1, $thread_Class) Local $tWCEX = DllStructCreate($tagWNDCLASSEX) DllStructSetData($tWCEX, 'Size', DllStructGetSize($tWCEX)) DllStructSetData($tWCEX, 'hWndProc', DllCallbackGetPtr($hProc)) DllStructSetData($tWCEX, 'ClassName', DllStructGetPtr($tClass)) _WinAPI_RegisterClassEx($tWCEX) Global $opcode_struct = 'ptr WaitForSingleObject;' & _ 'ptr SendMessage;' & _ 'ptr GetLastError;' & _ 'ptr henvent;' & _ 'ptr hwnd;' & _ 'ptr pproc;' & _ 'ptr isprocessing;' & _ 'ptr lreturn;ptr hreturn;' & _ 'ptr LastError;' & _ 'ptr exitthread;' & _ 'ptr parm[100];ptr rsv[20];WCHAR callback[100]' Local $opcode = '0x668CC83C337449' & _ '8B7C24046AFFFF770CFF1785C07403FF47288B5F2885DB75118D772C8B0E85C97405FF348EE2FBFF571489471C895720FF570889472431C0894718535750FF7710FF570485DB74BCC3' & _ '4881EC480300004889CB4831D248FFCA488B4B18FF134885C0740448FF43504C8B7B504D85FF753A488D735848AD4885C0742C4989C64831C94883C10448AD50E2FB4983EE04493' & _ '9CE7E0E4C89F1488D7C244048AD48ABE2FA415941585A59FF53284889433848895340FF5310488943484831D2488953304D89F94989D8488B4B20FF53084D85FF74804881C448030000C3' Global $pshll = _MemVirtualAlloc(0, BinaryLen($opcode), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) DllStructSetData(DllStructCreate('byte[' & BinaryLen($opcode) & ']', $pshll), 1, $opcode) Func thread_WM($hWnd, $iMsg, $wParam, $lParam) ;window call back If $iMsg = $WM_NULL Then Local $thi = DllStructCreate($opcode_struct, $wParam) If $lParam <> 0 Then DllStructSetData($thi, 'rsv', -2, 4) DllStructSetData($thi, 'rsv', DllStructGetData($thi, 'rsv', 4) + 1, 4) Call(DllStructGetData($thi, 'callback'), $thi, DllStructGetData($thi, 'rsv', 4)) If $lParam <> 0 Then _WinAPI_DestroyWindow($hWnd) _WinAPI_CloseHandle(DllStructGetData($thi, 'henvent')) _MemGlobalFree($wParam) EndIf EndIf Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>thread_WM Func thread_create($scallback) ; create new remote api thread Local $thi = DllStructCreate($opcode_struct, _MemGlobalAlloc(DllStructGetSize(DllStructCreate($opcode_struct)), $GPTR)) DllStructSetData($thi, 'WaitForSingleObject', _WinAPI_GetProcAddress(_WinAPI_LoadLibrary('kernel32'), 'WaitForSingleObject')) DllStructSetData($thi, 'SendMessage', _WinAPI_GetProcAddress(_WinAPI_LoadLibrary('user32'), 'SendMessageW')) DllStructSetData($thi, 'GetLastError', _WinAPI_GetProcAddress(_WinAPI_LoadLibrary('kernel32'), 'GetLastError')) DllStructSetData($thi, 'henvent', _WinAPI_CreateEvent(0, 0, 0, 0)) ; DllStructSetData($thi, 'hwnd', _WinAPI_CreateWindowEx(0, $thread_Class, '', 0, 0, 0, 0, 0, 0)) Local $thid = DllCall('kernel32', 'hwnd', 'CreateThread', 'ptr', 0, 'dword', 0, 'ptr', _ $pshll, 'ptr', DllStructGetPtr($thi), 'long', 0, 'int*', 0) DllStructSetData($thi, 'rsv', $thid[0], 2) DllStructSetData($thi, 'rsv', $thid[6], 3) DllStructSetData($thi, 'callback', $scallback) Call(DllStructGetData($thi, 'callback'), $thi, DllStructGetData($thi, 'rsv', 4)) Return $thi EndFunc ;==>thread_create Func thread_close($thi) ; close remote api thread DllStructSetData($thi, 'exitthread', 1) _WinAPI_SetEvent(DllStructGetData($thi, 'henvent')) EndFunc ;==>thread_close Func thread_isrunning($thi) ; check if remote api thread is closed or no Return (DllStructGetData($thi, 'exitthread') = 0) EndFunc ;==>thread_isrunning Func thread_GetLastError($thi) ; Get Last Error in remote thread Return DllStructGetData($thi, 'LastError') EndFunc ;==>thread_GetLastError Func thread_getreturn($thi) ; get api call return Return DllStructGetData($thi, 'lreturn') EndFunc ;==>thread_getreturn Func thread_call($thi, $pproc) ; dllcall $pproc = address of api DllStructSetData($thi, 'pproc', $pproc) DllStructSetData($thi, 'isprocessing', 1) _WinAPI_SetEvent(DllStructGetData($thi, 'henvent')) DllStructSetData($thi, 'rsv', 0, 1) EndFunc ;==>thread_call Func thread_addcallparameters($thi, $val) ; add dllcall parameters Local $idx = DllStructGetData($thi, 'rsv', 1) + 1 DllStructSetData($thi, 'rsv', $idx, 1) DllStructSetData($thi, 'parm', $idx, 1) DllStructSetData($thi, 'parm', $val, $idx + 1) EndFunc ;==>thread_addcallparameters Func thread_callsimple($thi, $dll, $nproc, $p1 = Default, $p2 = Default, $p3 = Default, _ $p4 = Default, $p5 = Default, $p6 = Default, $p7 = Default, $p8 = Default, _ $p9 = Default, $p10 = Default, $p11 = Default, $p12 = Default, $p13 = Default, _ $p14 = Default, $p15 = Default, $p16 = Default, $p17 = Default, $p18 = Default) ; simple call api ;) Local $cp = 1 While Execute('$p' & $cp & ' <> Default') thread_addcallparameters($thi, Execute('$p' & $cp)) $cp += 1 WEnd thread_call($thi, _WinAPI_GetProcAddress(_WinAPI_LoadLibrary($dll), $nproc)) EndFunc ;==>thread_callsimple Opt("MustDeclareVars", 1) Global $s1, $s2 Func __thread_callback($thi, $phase) Switch $phase Case -1 ;thread is closed MsgBox(0, '', 'thread is closed return ' & thread_getreturn($thi) & ' error ' & thread_GetLastError($thi)) Case 0 ;thread is started $s1 = _WinAPI_CreateString('i love autoit') $s2 = _WinAPI_CreateString('from remote thread') thread_callsimple($thi, 'user32', 'MessageBoxW', 0, $s1, $s2, 0x00000006) ;~ ;DllCall('user32', 'int', 'MessageBoxW', 'hwnd', 0, 'ptr', $s1, 'ptr', $s2, 'uint', 0x00000006) Case 1 ;return first call _WinAPI_FreeMemory($s1) _WinAPI_FreeMemory($s2) MsgBox(0, '', 'callback api return ' & thread_getreturn($thi) & ' error ' & thread_GetLastError($thi)) $s2 = DllStructCreate('dword') DllStructSetData($s2, 1, 1024) $s1 = DllStructCreate('wchar[1024]') thread_callsimple($thi, 'Advapi32', 'GetUserNameW', DllStructGetPtr($s1), DllStructGetPtr($s2)) ;~ ;DllCall('Advapi32', 'BOOL', 'GetUserNameW', 'ptr', DllStructGetPtr($s1), 'ptr', DllStructGetPtr($s2)) Case 2 ;return second call MsgBox(0, '', 'callback api return : ' & thread_getreturn($thi) & _ @CRLF & ' error : ' & thread_GetLastError($thi) & _ @CRLF & ' string len : ' & DllStructGetData($s2, 1) & _ @CRLF & ' user name : ' & DllStructGetData($s1, 1) & _ '') thread_close($thi) ;endif thread Case 3 ; return previous call EndSwitch EndFunc ;==>__thread_callback Local $rth = thread_create('__thread_callback') While thread_isrunning($rth) ConsoleWrite('thread is running' & @CRLF) Sleep(1000) WEnd
    2 points
  2. I like the fact that, with the basic music player script (Nine's last script or his precedent one), each one of us can now add some functionality and personalize the script for his own need. I notice that Emanoel did that in the post just above, great My personal need was to be able to quickly modify the volume level and few lines of code just did it (a slider control, no need of tick marks or another fancy design, the pic speaks for itself) If you want to do same, here are the 3 groups of required lines, you sure will know where to place them, adjusting the coords to your own script : Local $idVolume = GUICtrlCreateSlider(155, 55, 90, 25, $TBS_NOTICKS) GUICtrlSetLimit(-1, 100, 0) ; volume level (0 - 100) GUICtrlSetData(-1, 50) ; initial volume level (50) ... ; Nine's original line below was = 100 $oPlayer.Settings.Volume = 50 ; initial volume level (50) ... Case $idVolume $oPlayer.Settings.Volume = GUICtrlRead($idVolume) Something else : the "blue" shuttle in the pic above is just for fun. Its color changes each time the script is run, due to the following script line and 6 little separated pics 18x18 pixels. Let's be creative Local $idShuttle = GUICtrlCreatePic(@ScriptDir & "\SliderButton" & Random(1,6,1) & ".jpg", 0, 0, $iShuttleWidth, 18)
    2 points
  3. Hi everyone, I have a quick interim update on the project, as usual life pushed me in all other directions despite my attempts to speed up development... However I have managed to complete the expression parsing code, and I have just pushed it to GitHub: https://github.com/DcodingTheWeb/EasyCodeIt/commit/920ff107634b5ef2e6b584b189d3732e5d8df995 The next step is to parse the statements to construct the final syntax tree, and that should be the finale for the "frontend" part which takes in the code and makes sense of it. I'll keep you guys updated. But wait! There is another major-ish annoucement, I have created a new forum at my website (forum.dtw.tools) and I intend to post more frequent shorter updates there as I plan, investigate and code. I don't want to spam the AutoIt forum with that stuff so a dedicated forum should be a good place! The forum is effectively in alpha stage at this moment so there isn't a particular theme to it, so you can post questions, chat discussions, memes and pretty much anything else. I'll be waiting for you there
    2 points
  4. version: 3.0.0 changes Most notable change: ROT¹ support! 🎊 ¹ Running Object Table
    2 points
  5. ; ;################################## ; Include ;################################## #Include<file.au3> ;################################## ; Variables ;################################## $SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED $FromName = "Name" ; name from who the email was sent $FromAddress = "your@Email.Address.com" ; address from where the mail should come $ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED $Subject = "Userinfo" ; subject from the email - can be anything you want it to be $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed $BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = "******" ; username for the account used from where the mail gets sent - REQUIRED $Password = "********" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required ;~ $SmtpServer = "smtp.gmail.com" ; GMAIL address for the smtp-server to use - REQUIRED ;~ $IPPort=465 ; GMAIL port used for sending the mail ;~ $ssl=1 ; GMAIL enables/disables secure socket layer sending - put to 1 if using https ;~ $SmtpServer = "smtp.office365.com" ; O365 address for the smtp-server to use - REQUIRED ;~ $IPPort=25 ; O365 port used for sending the mail ;~ $ssl=1 ; O365 enables/disables secure socket layer sending - put to 1 if using https ;~ SmtpServer = "smtp.mail.yahoo.com" ; Yahoo address for the smtp-server to use - REQUIRED ;~ $IPPort = 465 ; Yahoo port used for sending the mail ;~ $ssl = 1 ; Yahoo enables/disables secure socket layer sending - put to 1 if using https ;################################## ; Script ;################################## Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf ; ; The UDF Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail="" EndFunc ;==>_INetSmtpMailCom ; ; ; Com Error Handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) $oMyRet[0] = $HexNumber $oMyRet[1] = StringStripWS($oMyError.description, 3) ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF) SetError(1); something to check for when this function returns Return EndFunc ;==>MyErrFunc Edit: Fixed Bcc ... Edit: Added support for different port and SLL which are used by GMail (Port 465) Edit: Added Importance support (10/2008) EDIT: Added $TLS option (07/2020 Some interesting Info from the thread:
    1 point
  6. trancexx

    Ribbon

    Few years ago Microsoft introduced new UI feature that they named Ribbon. With the release of Windows 7 they added it as standard system feature. Windows Ribbon framework. You could say it's a new technology waiting to be fully embraced. Considering AutoIt is currently in some shitty stage Ribbons are not expected to be supported natively. Which is actually good thing because otherwise some developer could have GUICtrlCreateRibbon idiotic idea. Ribbons are beautiful things. In order to work with them you have to master objects. It's COM based technology. Some people will stop reading now, but really their shame. Anyway, this example is based on work by Mr. Michael Chourdakis. Guy really took deeper dive to ribbon thematic and made few very interesting articles. All is available on internet naturally, just google Michael Chourdakis Ribbon or something like that. So, the main thing to do is create so called Ribbon Framework Object. After that you have to initialize event handlers (two callback objects made with ObjectFromTag function) and load your Ribbon. Ribbon is loaded from resource, either one of your app or some other. I have compiled resource dll for this example so that scripts could be run non-compiled and still use ribbon command bar. Example shown here is not completely dummy, it uses all of the ribbon controls. Only it doesn't do anything smart besides that. ZIP: Ribbon.zip Inside the zip there is folder called Ribbon with two files RibbonExample_NEW.au3 and RibRes.dll. Extract that folder somewhere, run RibbonExample_NEW.au3 and enjoy the Ribbon beauty. There are few comments inline for easier comprehension of the overall script code. Thanks Andreik for asking for more.
    1 point
  7. Note that this is a real Windows Explorer. But only the right pane. All functionality of Windows Explorer is working. E.g. keyboard shortcuts, the context (right click) menu, cut, copy, paste, drag & drop and automatic update of the window. Implementations There are three implementations: An implementation for Vista, 7 and 8, an implementation for Windows XP, and a SysListView32 based implementation for Vista, 7 and 8. The latter is named SysLv32.au3 in the examples. This is more or less the Windows XP implementation adapted for Vista, 7 and 8. Functionality The implementations are based on Shell interfaces. This means that most functionality of Windows Explorer is working automatically without any additional code. Other features: Position Explorer window in GUISpecify root and start foldersSpecify an initial icon view modeSpecify an icon view mode for the DesktopSpecify a file filter to filter files by extensionUse folder flags $FWF_NOBACKBROWSING, $FWF_SINGLESEL and $FWF_NOSUBFOLDERSBrowse to child/parent folder with Enter/Backspace keysDelete, disable and insert items in the context menuExecute context menu commands in codeDocumentation Use ExplorerWindowCreate() to create the right pane window. This function is located in Explorer\<Implementation>\WindowsExplorer.au3. You find documentation for the function in top of the file. Documentation for the Vista, 7, 8 implementation is included in the Examples section below. Ini file To handle Rename, New and View in the context menu, it's necessary to be able to identify these items. This seems only to be possible to do, by identifying the names. Because the names are localized, an ini file is used to store the names. Especially the View command depends on the ini file. If the View command isn't recognized, the icon view modes are not set properly. Rename and New commands are depending on the ini file, when the commands are selected with the keyboard. More information in the sections below. First release 2013-11-28 In first release Explorer right pane windows are created with enough functionality to get it to work. There are two implementations: One for Vista, 7 and 8, and one for Windows XP. First update 2014-03-14 This update consists primarily of bug fixes in first release. Because both APIConstants.au3 and WinAPIEx.au3 are included, the scripts can't run on AutoIt 3.3.10 without modifications. A new implementation for Vista, 7 and 8 is added. This implementation is based on a SysListView32 control. This is more or less the Windows XP implementation adapted for Vista, 7 and 8. Second update 2014-04-23 The implementations are based on Shell interfaces, and most functionality of Windows Explorer is working automatically. But you still have to integrate that functionality into your script. Especially you have to take care of keystrokes in combination with various controls and windows. E.g. the rename edit box, the context menu and dialog boxes. This update introduces an ini file: Explorer\Inifiles\ContextMenu.ini Third update 2014-05-02 The third update is mostly about the context menu. It's divided into two parts. The first part is about manipulating the context menu. The example shows how to delete, disable and add custom menu items. The second part shows how to execute context menu commands in code. The example implements Cut, Copy and Paste buttons. The spoiler section starts with an explanation of the message flow and message handlers. Final release 2014-05-10 Left, top, width and height parameters are added to the ExplorerWindowCreate() function. This makes it easier to position the Explorer window in the GUI. When the GUI is resized, the Explorer window is resized so that margins are retained. The margins can be used for buttons or other controls. The new parameters are implemented in the examples. Redundant code is moved from example files to common files. Some minor bug fixes. This is the final release of the small examples. It should not be too difficult to reuse the examples and code. I'm currently working on a large example where an address bar, a toolbar, a left pane and a status bar is implemented besides the right pane. This is a much bigger example, and it'll be more difficult to reuse the code. I'll probably add this example to a new thread. Final release, Vista update 2014-06-21 The Vista, 7, 8 example in first release dated 2013-11-28 was based on Vista code. The XP example was based on XP code. But most of the additional code in the next updates was XP code (see post 40). This meant that some functionality wasn't implemented completely under Vista and later. E.g. icon view modes. Examples The zip contains seven folders at the top level: 1. Basic example2. Position and size3. Navigation buttons4. Toolbar example5. Context menu6. Cut-copy-pasteExplorerThe first six folders are examples. The Explorer folder contains common files and includes. Resources specific for a particular example are contained in the example folder. There are three scripts for each example: Vista, 7, 8.au3, SysLv32.au3 and Windows XP.au3. Other examples (Vista and later) in posts below: Three examples where all panes are implemented (not just the right pane)You can find an example which implements the other panes in this post.This example shows how to merge all include files into a single Include folder.Implement proper tab order between LV and TV, and update LV on up/down keys in TV here.An example that shows how to cancel drag/drop operations can be found here. AutoIt 3.3.8 If you want to run the scripts on AutoIt 3.3.8 you need APIConstants.au3 and WinAPIEx.au3 by Yashied. The UDFs are not included in the zip. You must enable the UDFs in top of ShellFunctions.au3. The UDFs are already added, but commented out. And you must comment out the 3.3.10 UDFs in ShellFunctions.au3 and WERPFuncs.au3. Testet on XP 32 bit and Win 7 32/64 bit. The scripts can be run as both 32 and 64 bit programs. If you are running a 64 bit Windows you should run the scripts as 64 bit programs. Windows Explorer right pane.7z
    1 point
  8. The ObjectFromTag() function is used to implement COM callback interfaces, pointers and objects. This is documentation for using the function. When talking about ObjectFromTag(), you cannot get around ObjCreateInterface(). ObjCreateInterface() was introduced in AutoIt version 3.3.8.0 (2011-12-23). The function is coded in the C/C++ language by trancexx. At the top of the official documentation there is a large warning box. A few comments on this warning: "This feature is experimental". No it's not. A function that has been used for more than 9 years to implement advanced code like the following is no longer experimental but has long proven its worth: IUIAutomation MS framework automate chrome, FF, IE, .... created by junkew August 2013 Newer versions of UIA code in this and other threads Using .NET library with AutoIt, possible? and several derived and advanced examples Implementing IRunningObjectTable Interface File/Windows Explorer examples Microsoft Edge - WebView2 As well as a myriad of other examples "It may not work, may contain bugs". The function works and it contains no bugs. This has long been proven by the examples above. "may be changed or removed without notice". On what grounds? The function works, contains no bugs, and adds lots of value to the AutoIt language. "DO NOT REPORT BUGS OR REQUEST NEW FEATURES FOR THIS FEATURE". There's really no reason for that. ObjectFromTag() is implemented as pure AutoIt code and is also made by trancexx. One of the first versions of the function is available in the Ribbon example. One of the latest versions of the function coded by trancexx is found in this post. Description tagsBoth ObjCreateInterface() and ObjectFromTag() use description tags to create objects with methods and properties. A description tag is a string that looks like this (the example of ObjCreateInterface()) $dTag_ITaskbarList = _ "HrInit hresult();" & _ "AddTab hresult(hwnd);" & _ "DeleteTab hresult(hwnd);" & _ "ActivateTab hresult(hwnd);" & _ "SetActiveAlt hresult(hwnd);" Here, the description tag is split into substrings for each method/property. ITaskbarList is the name of the COM interface. The name to the left of each substring is the name of the method/property. hresult in the middle is the method/property return type (always hresult for COM methods/properties), and the data types to the right in parentheses are parameter data types. If there are several parameters, the data types must be separated by a semi colon. Methods/properties of the description tag string must be in correct Vtable order. Vtable order In the Microsoft documentation for the ITaskbarList interface, methods/properties are listed in alphabetical order. But it's not possible to determine the correct Vtable order from this alphabetical list. The only way to determine the correct Vtable order is to study the interface in the appropriate C/C++ header file (shobjidl_core.h for ITaskbarList). All Microsoft header files are included in the Windows SDK. To access the header files, it's necessary to install the Windows SDK on your PC. The header files are located in the folder "E:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0" or similar. When you need a specific header file, it's easiest to search for it. shobjidl_core.h is found in the um subfolder. This is the definition of ITaskbarList in shobjidl_core.h: /* interface ITaskbarList */ /* [object][uuid] */ EXTERN_C const IID IID_ITaskbarList; #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("56FDF342-FD6D-11d0-958A-006097C9A090") ITaskbarList : public IUnknown { public: virtual HRESULT STDMETHODCALLTYPE HrInit( void) = 0; virtual HRESULT STDMETHODCALLTYPE AddTab( /* [in] */ __RPC__in HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE DeleteTab( /* [in] */ __RPC__in HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE ActivateTab( /* [in] */ __RPC__in HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE SetActiveAlt( /* [in] */ __RPC__in HWND hwnd) = 0; }; #else /* C style interface */ typedef struct ITaskbarListVtbl { BEGIN_INTERFACE HRESULT ( STDMETHODCALLTYPE *QueryInterface )( __RPC__in ITaskbarList * This, /* [in] */ __RPC__in REFIID riid, /* [annotation][iid_is][out] */ _COM_Outptr_ void **ppvObject); ULONG ( STDMETHODCALLTYPE *AddRef )( __RPC__in ITaskbarList * This); ULONG ( STDMETHODCALLTYPE *Release )( __RPC__in ITaskbarList * This); HRESULT ( STDMETHODCALLTYPE *HrInit )( __RPC__in ITaskbarList * This); HRESULT ( STDMETHODCALLTYPE *AddTab )( __RPC__in ITaskbarList * This, /* [in] */ __RPC__in HWND hwnd); HRESULT ( STDMETHODCALLTYPE *DeleteTab )( __RPC__in ITaskbarList * This, /* [in] */ __RPC__in HWND hwnd); HRESULT ( STDMETHODCALLTYPE *ActivateTab )( __RPC__in ITaskbarList * This, /* [in] */ __RPC__in HWND hwnd); HRESULT ( STDMETHODCALLTYPE *SetActiveAlt )( __RPC__in ITaskbarList * This, /* [in] */ __RPC__in HWND hwnd); END_INTERFACE } ITaskbarListVtbl; interface ITaskbarList { CONST_VTBL struct ITaskbarListVtbl *lpVtbl; }; The upper part of the definition is used in the C++ language. The lower part is used in the C language. When translating the definition to AutoIt, it's easiest to look at the C++ definition: /* interface ITaskbarList */ /* [object][uuid] */ EXTERN_C const IID IID_ITaskbarList; #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("56FDF342-FD6D-11d0-958A-006097C9A090") ITaskbarList : public IUnknown { public: virtual HRESULT STDMETHODCALLTYPE HrInit( void) = 0; virtual HRESULT STDMETHODCALLTYPE AddTab( /* [in] */ __RPC__in HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE DeleteTab( /* [in] */ __RPC__in HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE ActivateTab( /* [in] */ __RPC__in HWND hwnd) = 0; virtual HRESULT STDMETHODCALLTYPE SetActiveAlt( /* [in] */ __RPC__in HWND hwnd) = 0; }; Note that the order of the methods in the description tag string above corresponds to the order of the methods in the C++ definition. Names of methods/properties and the correct Vtable order can be copied directly from the C++ definition. Parameter data types The parameter data types that can be used in the description tag string are listed in the ObjCreateInterface() documentation. Both the header file and the Microsoft documentation can be used to help you find the right data types. In many cases, the data type in the header file or Microsoft documentation corresponds directly to one of the data types in the ObjCreateInterface() documentation. In other cases, it's necessary to translate the data type to one of the valid AutoIt data types. Filling in the parameter data types is the most time consuming task of creating the description tag string. Fortunately, it's enough to fill in the data types for the methods/properties you actually need. For methods/properties you don't need, you can simply enter an empty parenthesis, as is the case in the "HrInit hresult();" substring (in this case because HrInit doesn't actually take any parameters). You can omit the parameter data types for methods/properties that are not to be used in the first place, but all methods/properties must be specified in the correct Vtable order. IUnknown interface All COM interfaces inherits from the IUnknown interface. It's indicated in the C++ definition by this line ITaskbarList : public IUnknown Because all COM interfaces inherits from the IUnknown interface, don't specify IUnknown methods/properties in the description tag string. IUnknown methods/properties are added automatically in both ObjCreateInterface() and ObjectFromTag() functions. $sIID and $sCLSID Note that this line in the AutoIt code $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}" corresponds to this line in the C++ definition MIDL_INTERFACE("56FDF342-FD6D-11D0-958A-006097C9A090") And that this line in the AutoIt code $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" corresponds to these lines in the C++ definition (further down in the header file) class DECLSPEC_UUID("56FDF344-FD6D-11D0-958A-006097C9A090") TaskbarList; ObjectFromTag() functionThe version of ObjectFromTag() that I'm using is based on this version by trancexx. My first version is contained in the 7z-file below and coded in ObjectFromTag-a.au3 dated 2014-01-14. My current version is coded in ObjectFromTag.au3 dated 2021-02-06. The function is defined as follows: Func ObjectFromTag( _ $sFunctionPrefix, _ ; Presents methods/properties with the same prefix name $tagInterface, _ ; Interface description tag string ByRef $tInterface, _ ; Interface struct (DllStruct) $bObject = True, _ ; Return object or object pointer $bPrint = False, _ ; Print information in SciTE console $bIsUnknown = True, _ ; Inherits from the IUnknown interface $sIID = "{00000000-0000-0000-C000-000000000046}" ) ; $sIID_IUnknown ObjectFromTag() exampleAs an example of using the function, I'll show how to create the first part of the WebView2-1.au3 example here (WebView2-1-0.au3, all required code and files are contained in the 7z-file below). According to the Getting started with WebView2 example, the prerequisites for running the code are installing the Microsoft Edge Chromium version and the WebView2 Runtime (Evergreen Bootstrapper). #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui ; Project includes #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of the DllCall() function above Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc The code can be run without errors. However, since it's only about half of all the code, an empty window without web content is displayed. A crucial point, of course, is to create this code from scratch. I've read the WebView2 documentation and especially the API reference documentation and studied the HelloWebView.cpp and WebView2.ahk examples (contained in the 7z-file). By running the examples and adding "ConsoleWrites" to the code, I've found that the examples can be translated to AutoIt code as shown. Because the WebView2 code is new code that's still under development, the WebView2.h header file isn't included in the Windows SDK. WebView2.h can instead be downloaded in a NuGet package as described in the WebView2 documentation. I'll focus on this part of the code: ; Create callback interfaces and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) The code creates the CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface and its functions. CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate() in WV2Interfaces.au3: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( $bPrint = False ) $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, $bPrint ) If $bPrint Then ConsoleWrite( "$pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = " & _ $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler & @CRLF & @CRLF ) EndFunc The function executes ObjectFromTag(), which creates the callback interface and its functions. Note the False parameter just before $bPrint. False means that ObjectFromTag() returns an object pointer instead of the object itself. It seems that all WebView2 callback interfaces are created from an object pointer and not the object itself. Implement these steps to create the callback interface and its functions: Step 1: Create the description tag for ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface Step 2: Execute ObjectFromTag() with the $bPrint = True parameter Step 3: Copy the functions printed in the SciTE console into the code and run the code again Step 4: Continue executing ObjectFromTag() and copy the functions until there are no more errors Step 5: Test the code to check if the interface functions are called as expected Step 1The $dtag for the ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler callback interface can be created based on the information in WebView2.h (search the interface) and the Microsoft documentation (google the interface): Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" Step 2Execute ObjectFromTag() with the $bPrint = True parameter this way (WebView2-1-1.au3) #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" ; Project includes ;#include "..\Includes\WV2Interfaces.au3" #include "..\Includes\ObjectFromTag.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, True ) ; $bPrint = True ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup EndFunc SciTE console output: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 3 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 3 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 3 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 3 @error = 3 is an error code from DllCallbackRegister() in the ObjectFromTag() function and apparently means that the functions don't exist. Step 3Copy the four functions into the code and run the code again (WebView2-1-2.au3, delete @error = 3 lines): #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" ; Project includes ;#include "..\Includes\WV2Interfaces.au3" #include "..\Includes\ObjectFromTag.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, True ) ; $bPrint = True ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc SciTE console output: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 Step 4No more errors. We're done. The callback interface and its functions are implemented. Step 5Check if the interface functions are called as expected (WebView2-1-3.au3) #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui Global $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler Global Const $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ "Invoke hresult(hresult;ptr*);" ; Project includes ;#include "..\Includes\WV2Interfaces.au3" #include "..\Includes\ObjectFromTag.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interfaces and functions $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = _ ObjectFromTag( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_", _ $dtag_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, _ $tCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, False, True ) ; $bPrint = True ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup DllClose( $hWebView2Loader ) EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc SciTE console output: Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $pRIID, $pObj EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release( $pSelf ) ; Ret: dword ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release()" & @CRLF & @CRLF ) Return 1 ; For AddRef/Release #forceref $pSelf EndFunc @error = 0 Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke()" & @CRLF & @CRLF ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long, $ptr EndFunc @error = 0 CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release() CreateCoreWebView2EnvironmentWithOptions OK Output looks as expected - even if CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface() isn't called. If you get a CreateCoreWebView2EnvironmentWithOptions ERR from the DllCall() function and you're sure that the function is coded correctly, read this post by Chimp for a description and solution to the problem. Note that for all WebView2 callback interfaces, it seems that the Invoke() method is interesting, while the other methods/properties aren't so interesting. To proceed with the WebView2-1.au3 example (included as WebView2-1-a.au3) add code in the CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() function. 7z-fileThe 7z-file contains source code for the UDF and examples and other files needed to run the code. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. ObjectFromTag.7z
    1 point
  9. Thanks for this detailed information! First I will check if it is really possible to get the NewMail or ItemAdd event for another mailbox. Then I will play with the Categories. Stay tuned
    1 point
  10. This is because you created $ShuttleButton before the disabled $Sliderbar I reworked your script a bit, it's not 100% finished but it works better now. #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("GUIResizeMode", 1) Opt("MouseCoordMode", 2) Global $FilePath, $Paused = False Global $FileExt[] = [".3g2", ".3gp2", ".3gp", ".3gpp", ".aac", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".asf", ".asx", ".au", ".avi", ".cda", _ ".dvr-ms", ".flac", ".ivf", ".m1v", ".m2ts", ".m3u", ".m4a", ".m4v", ".mid", ".midi", ".mov", ".mp2", ".mp3", ".mp4", ".mp4v", ".mpa", ".mpe", _ ".mpeg", ".mpg", ".rmi", ".snd", ".wav", ".wax", ".wm", ".wma", ".wmd", ".wms", ".wmv", ".wmx", ".wmz", ".wpl", ".wvx"] Global $iSliderLength = 421 ; in pixels Global $adlibInterval = 250 ; in milliseconds Global $iMediaLength = 0 Global $iShuttleWidth = 25 #Region ### START Koda GUI section ### Form= $hGui = GUICreate("Music Player", 466, 170, 192, 132, Default, BitOR($WS_EX_TOPMOST, $WS_EX_ACCEPTFILES)) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") Global $PauseButton = GUICtrlCreateButton("Play", 184, 128, 99, 33) GUICtrlSetOnEvent($PauseButton, "PauseButton") Global $InputFile = GUICtrlCreateInput("", 8, 32, 417, 55) GUICtrlSetState($InputFile, $GUI_DROPACCEPTED) GUICtrlGetHandle($InputFile) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlSetCursor(-1, 5) GUICtrlCreateLabel("Drop your song here or browse it:", 8, 8, 199, 20) $BrowseButton = GUICtrlCreateButton("...", 432, 32, 27, 25) GUICtrlSetOnEvent($BrowseButton, "BrowseFile") Global $Sliderbar = GUICtrlCreateButton("", 8, 96, 451, 25, $BS_CENTER) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetBkColor(-1, 0xE3E3E3) Global $ShuttleButton = GUICtrlCreateButton("", 8, 96, $iShuttleWidth, 25) GUICtrlSetBkColor(-1, 0x646464) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_Event_PrimaryDown") Global $Progress = GUICtrlCreateLabel("0:00", 8, 128, 28, 20, $SS_LEFT) ; current media position Global $Length = GUICtrlCreateLabel("0:00", 432, 128, 28, 20, $SS_RIGHT) ; media length GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_DROPPED, "DropFile") #EndRegion ### END Koda GUI section ### $oPlayer = ObjCreate("WMPlayer.OCX") If Not IsObj($oPlayer) Then MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5) GUIDelete($hGui) Exit EndIf $oPlayer.URL = "" $oPlayer.Settings.Volume = 100 While 1 Sleep(10) If $Paused Then While $Paused Sleep(100) WEnd EndIf If $oPlayer.playState = 3 Then ; when song playing ;ConsoleWrite("Playing ") do whatever you want ElseIf $oPlayer.playState = 1 Then ; when song stopped GUICtrlSetData($PauseButton, "Play Again!") EndIf WEnd Func CLOSEClicked() $oPlayer.Close Exit EndFunc ;==>CLOSEClicked Func BrowseFile() Local $Extension = Null For $temp In $FileExt $Extension &= "*" & $temp & ";" Next $Extension = (StringTrimRight($Extension, 1)) $FilePath = FileOpenDialog("Open Music File", "", "Media Files (" & $Extension & ")", 12) If CheckFile() Then GUICtrlSetData($InputFile, $FilePath) GUICtrlSetData($Sliderbar, _RemoveFileExt(StringMid($FilePath, StringInStr($FilePath, "\", 0, -1) + 1))) $oPlayer.URL = $FilePath Local $hTimer = TimerInit() While $oPlayer.playState <> 3 ; 1 - stopped, 2 - paused, 3 - playing If TimerDiff($hTimer) > 3000 Then MsgBox(0, "WMPlayer.OCX", $FilePath & @CRLF & @CRLF & "Cannot play this file.", 5) ExitLoop EndIf Sleep(5) WEnd $oPlayer.Controls.Pause $oPlayer.Controls.currentPosition = 0 $iMediaLength = Int($oPlayer.currentMedia.Duration) ; in seconds GUICtrlSetData($Length, Int($iMediaLength / 60) & ":" & StringFormat("%02i", Mod($iMediaLength, 60))) AdlibRegister("Slider", $adlibInterval) GUICtrlSetData($PauseButton, "Play") EndIf EndFunc ;==>BrowseFile Func DropFile() $oPlayer.Close Switch @GUI_DropId Case $InputFile $FilePath = GUICtrlRead($InputFile) If CheckFile() Then GUICtrlSetData($Sliderbar, _RemoveFileExt(StringMid($FilePath, StringInStr($FilePath, "\", 0, -1) + 1))) $oPlayer.URL = $FilePath Local $hTimer = TimerInit() While $oPlayer.playState <> 3 ; 1 - stopped, 2 - paused, 3 - playing If TimerDiff($hTimer) > 3000 Then MsgBox(0, "WMPlayer.OCX", $FilePath & @CRLF & @CRLF & "Cannot play this file.", 5) ExitLoop EndIf Sleep(5) WEnd $oPlayer.Controls.Pause $oPlayer.Controls.currentPosition = 0 $iMediaLength = Int($oPlayer.currentMedia.Duration) ; in seconds GUICtrlSetData($Length, Int($iMediaLength / 60) & ":" & StringFormat("%02i", Mod($iMediaLength, 60))) AdlibRegister("Slider", $adlibInterval) GUICtrlSetData($PauseButton, "Play") EndIf EndSwitch EndFunc ;==>DropFile Func PauseButton() CheckFile() If GUICtrlRead($PauseButton) = "Pause" Then $oPlayer.Controls.Pause AdlibUnRegister() $Paused = True GUICtrlSetData($PauseButton, "Resume") Else $oPlayer.Controls.Play AdlibRegister("Slider", $adlibInterval) $Paused = False GUICtrlSetData($PauseButton, "Pause") EndIf EndFunc ;==>PauseButton Func _Event_PrimaryDown() Local $n_msg = GUIGetCursorInfo()[4] Switch $n_msg Case $ShuttleButton AdlibUnRegister() ; $x = MouseGetPos(0) ; $xOffset = $x - $iPos While _IsPressed("01") $x = MouseGetPos(0) GUICtrlSetPos($ShuttleButton, $x - $iShuttleWidth / 2) Sleep(10) WEnd $oPlayer.Controls.currentPosition = ($x - $iShuttleWidth / 2) / $iSliderLength * $iMediaLength $oPlayer.Controls.Play AdlibRegister("Slider", $adlibInterval) Case $Sliderbar GUICtrlSetPos($ShuttleButton, MouseGetPos(0) - $iShuttleWidth / 2) $x = (MouseGetPos(0) - $iShuttleWidth / 2) / $iSliderLength * $iMediaLength $oPlayer.Controls.currentPosition = $x > $iMediaLength ? $iMediaLength : $x $oPlayer.Controls.Play EndSwitch EndFunc ;==>_Event_PrimaryDown Func CheckFile() Local $check = True For $temp In $FileExt If StringInStr($FilePath, $temp, Default, -1) = False Then $check = False Else $check = True ExitLoop EndIf Next If $FilePath = "" Then MsgBox(0, "File Error", "The file has not been selected yet.") Return 0 ElseIf $check = False Then MsgBox(0, "File Error", "The dropped file is not a media file, try again please.") Return 0 EndIf Return 1 EndFunc ;==>CheckFile Func _RemoveFileExt($string) Return StringLeft($string, StringInStr($string, ".", Default, -1) - 1) EndFunc ;==>_RemoveFileExt Func Slider() Local Static $iPlayTime Local $mediaPos = Round($oPlayer.Controls.currentPosition) Local $iPos = $mediaPos * $iSliderLength / $iMediaLength GUICtrlSetPos($ShuttleButton, $iPos) If $iPlayTime = $mediaPos Then Return GUICtrlSetData($Progress, Int($mediaPos / 60) & ":" & StringFormat("%02i", Mod($mediaPos, 60))) $iPlayTime = $mediaPos EndFunc ;==>Slider
    1 point
  11. I wonder if dummyfy is a word. Dummification ?. Simplify, yes, a subset of ..., nope. An AutoItfication for the WebView2. So what I mean by that, is that we( I really ) would use this to: 1) make GUIs more on par with the times. 2) have some use for it ? My point is that functions that resemble what is the IE UDF would be used ( maybe ? ). Going overboard with each interaction as described by WebView2 may be way to complicated to follow by ppl ( like me ), hence a DLL that would do the actual heavy lifting and calls that are simple to use by the scripting community ( me ). Because, from my point of view ( without knowing or understanding ), a "creative architecture" can be developed/invented, that is relatable in usefulness for a simpletonscripter ( like me ). ...I hope all this chatter makes sense. I'd really like to have a simple to use implementation because, the life of IE is going the way of the dodo.
    1 point
  12. When sound files have to be played, Sound.au3 UDF comes to our mind immediately. It is simple and easy to use. But WMPlayer.ocx has a lot more features: it can play video clips and flac audio files, which Sound.au3 UDF cannot. Below are quick and dirty comparison of codes utilizing two different methods. Both of them do exactly the same thing: play back a playlist of audio files, with a simple slider control. 1. Use of Sound.au3 UDF #include <GUIConstants.au3> #include <Sound.au3> #include <Misc.au3> $hGui = GUICreate("Sound.au3", 400, 75, -1, -1) $Label1 = GUICtrlCreateButton("", 0, 0, 400, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Shuttle = GUICtrlCreatePic(StringReplace(@AutoItExe, "autoit3.exe", "\examples\gui\msoobe.jpg"), 0, 0, 20, 20) $Pause = GUICtrlCreateButton("Pause", 160, 40, 80, 20) $Progress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position $Length = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length GUISetState(@SW_SHOW) Local $aPlayList[3] ; Put your own mp3 file paths in this playlist $aPlayList[0] = 2 ; number of files in the playlist $aPlayList[1] = "D:\Music - Classics\Beethoven - Piano Concerto 5 in Eb Major Allegro.mp3" $aPlayList[2] = "D:\Music - Pops\Adele - Hello.mp3" $nFiles = 0 For $i = 1 To $aPlayList[0] If Not FileExists($aPlayList[$i]) Then $nFiles += 1 EndIf Next If $nFiles = $aPlayList[0] Then MsgBox(0, "Sound.au3", "None of the files listed in $aPlayList array exists.", 5) GUIDelete($hGui) Exit EndIf $iPos = 0 ; x coordinate of $Shuttle cntrol in progress bar $hDLL = DllOpen("user32.dll") ; to dectect mouse down on the $Shuttle control $sliderLength = 380 ; in pixels $adlibInterval = 250 ; in milliseconds $nFile = 0 While 1 $nFile += 1 If $nFile > $aPlayList[0] Then $nFile = 1 EndIf $sFullPath = $aPlayList[$nFile] $aSound = _SoundOpen($sFullPath) If $aSound = 0 Then MsgBox(0, "Sound.au3", $sFullPath & @CRLF & @CRLF & "Cannot open this file.", 5) ContinueLoop EndIf _SoundPlay($aSound) $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1)+1) GUICtrlSetData($Label1, $sFile) $mediaLength = _SoundLength($aSound, 2) / 1000 ; in seconds GUICtrlSetData($Length, Int($mediaLength/60) & ":" & StringFormat("%02i", Mod($mediaLength, 60))) AdlibRegister("Slider", $adlibInterval) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _SoundClose($aSound) Exit Case $Pause If GUICtrlRead($Pause) = "Pause" Then _SoundPause($aSound) AdlibUnRegister() GUICtrlSetData($Pause, "Resume") Else _SoundResume($aSound) AdlibRegister("Slider") GUICtrlSetData($Pause, "Pause") EndIf Case $Shuttle AdlibUnRegister() $x = MouseGetPos(0) $xOffset = $x - $iPos While _IsPressed("01", $hDLL) = 1 $x = MouseGetPos(0) If $x > 380+$xOffset Then $x = 380+$xOffset ElseIf $x < $xOffset Then $x = $xOffset EndIf $iPos = $x - $xOffset GUICtrlSetPos($Shuttle, $iPos) Sleep(1) WEnd $mediaPos = Round($iPos/$sliderLength*$mediaLength) $iHour = Int($mediaPos/3600) $iMin = Int(Mod($mediaPos, 3600)/60) $iSec = Mod($mediaPos, 60) _SoundSeek($aSound, $iHour, $iMin, $iSec) _SoundPlay($aSound) AdlibRegister("Slider", $adlibInterval) GUICtrlSetData($Pause, "Pause") EndSwitch If _SoundStatus($aSound) = "stopped" Then ; playing, paused, stopped ExitLoop EndIf WEnd WEnd Func Slider() $mediaPos = _SoundPos($aSound, 2)/1000 $iPos = $mediaPos * $sliderLength / $mediaLength GUICtrlSetPos($Shuttle, $iPos) GUICtrlSetData($Progress, Int($mediaPos/60) & ":" & StringFormat("%02i", Mod($mediaPos, 60))) EndFunc 2. Use of WMPlayer.ocx #include <GuiConstants.au3> #include <Misc.au3> $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1) $Label1 = GUICtrlCreateButton("", 0, 0, 400, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Shuttle = GUICtrlCreatePic(StringReplace(@AutoItExe, "autoit3.exe", "examples\gui\msoobe.jpg"), 0, 0, 20, 20) $Pause = GUICtrlCreateButton("Pause", 160, 40, 80, 20) $Progress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position $Length = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length GUISetState(@SW_SHOW) Local $aPlayList[3] ; Put your own mp3 file paths in this playlist $aPlayList[0] = 2 ; number of files in the playlist $aPlayList[1] = "D:\Music - Classics\Beethoven - Piano Concerto 5 in Eb Major Allegro.mp3" $aPlayList[2] = "D:\Music - Pops\Adele - Hello.mp3" $nFiles = 0 For $i = 1 To $aPlayList[0] If Not FileExists($aPlayList[$i]) Then $nFiles += 1 EndIf Next If $nFiles = $aPlayList[0] Then MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5) GUIDelete($hGui) Exit EndIf $oPlayer = ObjCreate("WMPlayer.OCX") If Not IsObj($oPlayer) Then MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5) GUIDelete($hGui) Exit EndIf $iPos = 0 ; x coordinate of $Shuttle cntrol in progress bar $hDLL = DllOpen("user32.dll") ; to dectect mouse down on the $Shuttle control $sliderLength = 380 ; in pixels $adlibInterval = 250 ; in milliseconds $oPlayer.Settings.Volume = 100 $nFile = 0 While 1 $nFile += 1 If $nFile > $aPlayList[0] Then $nFile = 1 EndIf $sFullPath = $aPlayList[$nFile] $oPlayer.URL = $sFullPath $hTimer = TimerInit() While $oPlayer.playState <> 3 ; 1 - stopped, 2 - paused, 3 - playing If TimerDiff($hTimer) > 3000 Then MsgBox(0, "WMPlayer.OCX", $sFullPath & @CRLF & @CRLF & "Cannot play this file.", 5) ExitLoop EndIf Sleep(5) WEnd If $oPlayer.playState <> 3 Then ContinueLoop EndIf $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1)+1) GUICtrlSetData($Label1, $sFile) $mediaLength = Int($oPlayer.currentMedia.Duration) ; in seconds GUICtrlSetData($Length, Int($mediaLength/60) & ":" & StringFormat("%02i", Mod($mediaLength, 60))) AdlibRegister("Slider", $adlibInterval) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE $oPlayer.Close Exit Case $Pause If GUICtrlRead($Pause) = "Pause" Then $oPlayer.Controls.Pause AdlibUnRegister() GUICtrlSetData($Pause, "Resume") Else $oPlayer.Controls.Play AdlibRegister("Slider") GUICtrlSetData($Pause, "Pause") EndIf Case $Shuttle AdlibUnRegister() $x = MouseGetPos(0) $xOffset = $x - $iPos While _IsPressed("01", $hDLL) = 1 $x = MouseGetPos(0) If $x > 380+$xOffset Then $x = 380+$xOffset ElseIf $x < $xOffset Then $x = $xOffset EndIf $iPos = $x - $xOffset GUICtrlSetPos($Shuttle, $iPos) Sleep(1) WEnd $mediaPos = $iPos/$sliderLength*$mediaLength $oPlayer.Controls.currentPosition = $mediaPos $oPlayer.Controls.Play AdlibRegister("Slider", $adlibInterval) GUICtrlSetData($Pause, "Pause") EndSwitch If $oPlayer.playState = 1 Then ExitLoop EndIf WEnd WEnd Func Slider() $mediaPos = $oPlayer.Controls.currentPosition $iPos = $mediaPos * $sliderLength / $mediaLength GUICtrlSetPos($Shuttle, $iPos) GUICtrlSetData($Progress, Int($mediaPos/60) & ":" & StringFormat("%02i", Mod($mediaPos, 60))) EndFunc
    1 point
  13. Shame on me, I just realised that the original code is yours Well done @CYCho
    1 point
  14. Changed the symbols for back and forward (didn't like them much). Made a separate func to load image. And corrected bug found by @pixelsearch Have fun ! Thanks to all for your ideas and testings. Special thanks to @CYCho for initial code.
    1 point
  15. Do you have a server that we can use to test the code? I would rather not have to start implementing a server myself.
    1 point
  16. Getting started example step 4: Navigation eventsWebView2-2.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui ; Project includes #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() ; Create WebView2 GUI $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) ; Initialize COM _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) ; Create callback interface and functions CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate( True ) ; Forces CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke() below to be executed ; Create callback interface and functions CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate( True ) ; Create callback interface and functions CoreWebView2NavigationStartingEventHandlerCreate( True ) ; DllCall CreateCoreWebView2EnvironmentWithOptions Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) ; Show WebView2 GUI GUISetState( @SW_SHOW ) ; Loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc ; Copied from WV2Interfaces.au3 ; Executed automatically when the callback interface is created Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF ) ; Create CoreWebView2Environment object $oCoreWebView2Environment = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment ) = " & IsObj( $oCoreWebView2Environment ) & @CRLF & @CRLF ) ; Set $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler callback pointer for the WebView2 GUI $oCoreWebView2Environment.CreateCoreWebView2Controller( $hGui, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler ) ; Forces CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke() below to be executed Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2Environment.CreateCoreWebView2Controller() above Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke" & @CRLF ) ; Create CoreWebView2Controller object $oCoreWebView2Controller = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller ) = " & IsObj( $oCoreWebView2Controller ) & @CRLF ) $oCoreWebView2Controller.AddRef() ; Prevent the object from being deleted when the function ends ; Set bounds for the CoreWebView2 object Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) ; Create CoreWebView2 object $oCoreWebView2Controller.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2 ) = " & IsObj( $oCoreWebView2 ) & @CRLF & @CRLF ) ; Add NavigationStarting event handler Local $tEventRegistrationToken = DllStructCreate( "uint64" ) $oCoreWebView2.add_NavigationStarting( $pCoreWebView2NavigationStartingEventHandler, $tEventRegistrationToken ) ConsoleWrite( "DllStructGetData( $tEventRegistrationToken, 1 ) = " & DllStructGetData( $tEventRegistrationToken, 1 ) & @CRLF & @CRLF ) ; Forces CoreWebView2NavigationStartingEventHandler_Invoke() below to be executed ; Navigate to web page $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $long EndFunc ; Copied from WV2Interfaces.au3 ; Executed as a consequence of $oCoreWebView2.add_NavigationStarting() above Func CoreWebView2NavigationStartingEventHandler_Invoke( $pSelf, $ptr1, $ptr2 ) ; Ret: long Par: ptr*;ptr* ConsoleWrite( "CoreWebView2NavigationStartingEventHandler_Invoke()" & @CRLF ) ; Create CoreWebView2NavigationStartingEventArgs object $oCoreWebView2NavigationStartingEventArgs = ObjCreateInterface( $ptr2, $sIID_ICoreWebView2NavigationStartingEventArgs, $dtag_ICoreWebView2NavigationStartingEventArgs ) ConsoleWrite( "IsObj( $oCoreWebView2NavigationStartingEventArgs ) = " & IsObj( $oCoreWebView2NavigationStartingEventArgs ) & @CRLF & @CRLF ) $oCoreWebView2NavigationStartingEventArgs.AddRef() ; Prevent the object from being deleted when the function ends ; Get navigation information Local $bIsUserInitiated, $bIsRedirected $oCoreWebView2NavigationStartingEventArgs.get_IsUserInitiated( $bIsUserInitiated ) $oCoreWebView2NavigationStartingEventArgs.get_IsRedirected( $bIsRedirected ) ; Confirm navigation If $bIsUserInitiated And Not $bIsRedirected Then Local $sUri $oCoreWebView2NavigationStartingEventArgs.get_Uri( $sUri ) If MsgBox( $MB_YESNO+$MB_ICONWARNING, "Navigation warning", "You are about to navigate to: " & $sUri & @CRLF & @CRLF & "Do you want to continue?" ) = $IDNO Then $oCoreWebView2NavigationStartingEventArgs.put_Cancel( True ) $oCoreWebView2.NavigateToString( "<h1>Navigation Canceled</h1><p>You chose to cancel navigation to the following URL: " & $sUri & "</p>" ) EndIf EndIf Return 0 ; S_OK = 0x00000000 #forceref $pSelf, $ptr1, $ptr2 EndFunc The code is translated to AutoIt from the C++ code in the Getting started example step 4, from the C++ code in ICoreWebView2.add_NavigationStarting() and from the AutoHotkey code in WebView2.ahk. In case of a CreateCoreWebView2EnvironmentWithOptions ERR in the SciTE console then the cause of the problem and the solution is described by Chimp in this post above. WebView2.h, HelloWebView.cpp and the three dll-files contained in the 7z-file are copied from the NuGet package needed to compile the C++ Getting started example. Examples: WebView2-1.au3: Getting started example step 3: WebView window WebView2-2.au3: Getting started example step 4: Navigation events (this example) WebView2-3.au3: AutoIt implementation of the AutoHotkey example WebView2-4.au3: Scripting example based on code by Chimp WebView2-5.au3: Getting started example step 5: Scripting WebView2-6.au3: Getting started example step 6: Communication (doesn't work) WebView2.7z
    1 point
  17. Getting started example step 3: WebView window First AutoIt implementation. Tested on Windows 10/7, 32/64 bit. Execute WebView2.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPICom.au3> #include <WinAPI.au3> Global $hGui, $oCoreWebView2Environment, $oCoreWebView2Controller #include "..\Includes\WV2Interfaces.au3" WebView2() Func WebView2() $hGui = GUICreate( "WebView2 Sample", 1200, 900, -1, -1, $WS_OVERLAPPEDWINDOW ) _WinAPI_CoInitialize( $COINIT_APARTMENTTHREADED ) CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerCreate() ConsoleWrite( "$pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler = " & $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler & @CRLF & @CRLF ) CoreWebView2CreateCoreWebView2ControllerCompletedHandlerCreate() ConsoleWrite( "$pCoreWebView2CreateCoreWebView2ControllerCompletedHandler = " & $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler & @CRLF & @CRLF ) Local $hWebView2Loader = DllOpen( @AutoItX64 ? "WebView2Loader-x64.dll" : "WebView2Loader-x86.dll" ) Local $aRet = DllCall( $hWebView2Loader, "long", "CreateCoreWebView2EnvironmentWithOptions", "wstr", "", "wstr", "", _ "ptr", NULL, "ptr", $pCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ) If @error Or $aRet[0] Then Return ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions ERR" & @CRLF ) ConsoleWrite( "CreateCoreWebView2EnvironmentWithOptions OK" & @CRLF & @CRLF ) GUISetState( @SW_SHOW ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd CoreWebView2CreateCoreWebView2ControllerCompletedHandlerDelete() CoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerDelete() DllClose( $hWebView2Loader ) EndFunc Func CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke" & @CRLF ) $oCoreWebView2Environment = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Environment, $dtag_ICoreWebView2Environment ) ConsoleWrite( "IsObj( $oCoreWebView2Environment ) = " & IsObj( $oCoreWebView2Environment ) & @CRLF & @CRLF ) $oCoreWebView2Environment.CreateCoreWebView2Controller( $hGui, $pCoreWebView2CreateCoreWebView2ControllerCompletedHandler ) Return 0 #forceref $pSelf, $long EndFunc Func CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke( $pSelf, $long, $ptr ) ; Ret: long Par: long;ptr* ConsoleWrite( "CoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke" & @CRLF ) $oCoreWebView2Controller = ObjCreateInterface( $ptr, $sIID_ICoreWebView2Controller, $dtag_ICoreWebView2Controller ) ConsoleWrite( "IsObj( $oCoreWebView2Controller ) = " & IsObj( $oCoreWebView2Controller ) & @CRLF ) $oCoreWebView2Controller.AddRef() $oCoreWebView2Controller.get_CoreWebView2( $pCoreWebView2 ) $oCoreWebView2 = ObjCreateInterface( $pCoreWebView2, $sIID_ICoreWebView2, $dtag_ICoreWebView2 ) ConsoleWrite( "IsObj( $oCoreWebView2 ) = " & IsObj( $oCoreWebView2 ) & @CRLF & @CRLF ) Local $tRect = _WinAPI_GetClientRect( $hGui ) $oCoreWebView2Controller.put_Bounds( $tRect ) $oCoreWebView2.Navigate( "https://www.bing.com/" ) Return 0 #forceref $pSelf, $long EndFunc The code is translated to AutoIt from the C++ code in the Getting started example step 3 and from the AutoHotkey code in WebView2.ahk. A slightly updated example is included in WebView2-1.au3 in the 7z-file at bottom of this post.
    1 point
  18. This is an update of the old Automating Windows Explorer example. The update includes Desktop automation. However, Windows XP code has been removed. ThreadsOther threads related to File/Windows Explorer: Implementing Windows Explorer right pane Implementing Windows Explorer address bar Enumerating and Browsing the Desktop Some of these threads are very old. I'm considering updating some of the examples: Remove Windows XP code. Implement some of the code in other ways. Enumerating and Browsing the Desktop is important to me personally because it was the first time I used the ObjCreateInterface() function. The first version of the example was based on _AutoItObject_WrapperCreate() from the AutoItObject UDF. Then I was told that you can use ObjCreateInterface() instead. Of course I had to try. Automating File/Windows Explorer and DesktopAutomating File/Windows Explorer The old example contains a description of the techniques for automating File/Windows Explorer. The techniques are based on COM interfaces. Initially, it's about getting an IShellBrowser interface based on a File/Windows Explorer window handle. An IDispatch interface for the window is important for creating the IShellBrowser interface. Through the IShellBrowser interface, you can generate a large number of interfaces that can be used to implement the automation functions. Automating DesktopBilgus figured out how to get an IDispatch interface for the Desktop in this post: $oIShellWindows.FindWindowSW( Null, Null, $SWC_DESKTOP, $hWnd, $SWFO_NEEDDISPATCH, $pIDispatch ) This is the part of the old code in the GetIShellBrowser() function that needs to be updated to include the Desktop: ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows - 1 $oIShellWindows.Item( $i, $pIDispatch ) If $pIDispatch Then $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next And here the code to include the Desktop is added: ; Get an IWebBrowserApp object for each window ; This is done in two steps: ; 1. Get an IDispatch object for the window ; 2. Get the IWebBrowserApp interface ; Check if it's the right window Local $pIDispatch, $oIDispatch, $hRes Local $pIWebBrowserApp, $oIWebBrowserApp, $hWnd For $i = 0 To $iWindows $hRes = $i < $iWindows ? $oIShellWindows.Item( $i, $pIDispatch ) _ : $oIShellWindows.FindWindowSW( Null, Null, $SWC_DESKTOP, $hWnd, $SWFO_NEEDDISPATCH, $pIDispatch ) If $pIDispatch Then $oIDispatch = ObjCreateInterface( $pIDispatch, $sIID_IDispatch, $dtag_IDispatch ) $oIDispatch.QueryInterface( $tRIID_IWebBrowserApp, $pIWebBrowserApp ) If $pIWebBrowserApp Then $oIWebBrowserApp = ObjCreateInterface( $pIWebBrowserApp, $sIID_IWebBrowserApp, $dtag_IWebBrowserApp ) $oIWebBrowserApp.get_HWND( $hWnd ) If $hWnd = $hExplorer Then ExitLoop EndIf EndIf Next The For loop runs an extra round if a File/Explorer Window has not been identified. In this last loop, the FindWindowSW() method returns a window corresponding to the Desktop. Here, the method always returns the Program Manager window. a consequence of this implementation is that if you specify a non-existent window as a parameter to the GetIShellBrowser() function, then the function will return the Program Manager window. Thus, the Program Manager window is the default window for the function. The IDispatch interface is the important thing in terms of automating the Desktop. Then all the functions used in connection with a File/Windows Explorer window can also be used in connection with the Desktop. Except for a few functions that are not relevant for the Desktop. Functions The automation functions are coded in FileExplorer.au3. The functions are implemented using a number of Shell API functions and Shell COM interfaces coded in ShellFunctions.au3 and ShellInterfaces.au3. The old example contains a list of implemented functions. New functions GetSortColumns() GetSortColumnsEx() SetSortColumns() Examples The 7z-file contains examples for automating the Desktop and a File/Windows Explorer window. These are the same examples as in this post. Note that the examples GetFiles.au3 and GetFolders.au3 also show how to make a list of selected files and folders. Note that the GetSetIconView.au3 example can change the order of icons on the Desktop. If you don't want this, run this example only in a File/Windows Explorer window. The GUI application that was used to demonstrate the features in the old version is not included. The small examples seems to be much more useful. This post contains new examples. In both the old and the new post, the examples are shown for a File/Windows Explorer window. But the 7z-file contains similar examples for the Desktop. Forum examplesThis is a list of the most interesting examples in the old thread: The original collection of small examples Automate a file search with UI Automation code. The question that led to this answer was asked in a slightly earlier post. Execute a function on a double-click in empty space of the listview. Based on UI Automation code. Here the question was asked somewhat earlier. UI Automation code to make a selected item visible by scrolling the listview up or down 7z-fileThe 7z-file contains source code for the UDF and examples. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. FileExplorerAndDesktop.7z
    1 point
  19. The address bar in Windows Explorer on Windows 7 seems to be a hot-track enabled toolbar menu with popup listviews and a combo box. The toolbar buttons shows the folders in the current path. The popup listviews shows the child folders. The toolbar menu can be implemented as a mixture of script 6 (split buttons) and 9 (popup windows) in Hot-Track Enabled and Custom Drawn Toolbar Menu. The combo box is implemented as a combination of an input box and a listview. The picture shows the last three folders in the path. The split part of AutoIt button is clicked to open a popup listview with child folders. The toolbar is hot-track enabled. If you move the mouse cursor over the neighbour buttons, the neighbour listviews opens automatically without the need to click the buttons. The listview for the leftmost button (without a folder name) contains the folders, which doesn't fit into the toolbar, because the window is too narrow. If you increase the width of the window, folders from this listview will be moved into the toolbar. If you decrease the width, folders from the toolbar will be moved into the listview. If you click a toolbar button or a folder in a listview, this folder will become the current folder. If you click in the empty area of the toolbar between the rightmost button and the combo button, the toolbar will be replaced by an input box. Paste the full path of a folder into the input box and press Enter to make this folder the current folder. If the folder is invalid, the Enter is canceled and the input box stays open. Press Escape or click the title bar or edit box to cancel the input box. Click the combo button to the right to open a listview with previous folders. Click a folder to make this folder the current folder. When you click the combo button, the input box is opened too. Press Escape or click the combo button again to close the listview and set focus to the input box. Press down arrow in the input box to open the listview. Click the title bar or edit box to cancel listview and input box. When the script is opened, or when you paste a folder into the input box and press Enter, or when you click a folder in the combo listview, all folders and child folders along the path are extracted. While the code is running the cursor is shown as an hourglass. You'll only be able to see the hourglass, if the cursor is over the title bar or the toolbar. If the cursor is over the edit box, you'll not see the hourglass. $sFolderPath contains the full path of the current folder. The zip contains two small DLL files, WSP.dll (6 KB) and WSP_x64.dll (10 KB), by Yashied to handle Enter key in listviews. See post 16 in this thread. Windows Explorer address bar.7z Testet on XP 32 bit and Win 7 32/64 bit. Run AddressBar.au3. Edit: $sFolderPath
    1 point
  20. Hot-tracking in a menu bar means that the (drop down) menu items are shown automatically, when the mouse cursor hovers over the top menu item, without the need to click it. This is the case for an ordinary menu, but not for a toolbar menu. To implement that functionality for a toolbar menu, you have to code it yourself. These examples implements that functionality. The toolbar menu can be custom drawn, to look like an ordinary menu. You have to click a top menu item once, to open the first drop down menu. The toolbar can contain other controls in addition to the menu. And it can be used in a rebar. When the window is resized, the arrows and menu are aligned to the left border. The search box and icon are aligned to the right border. This means, that it's the gap between the two parts of the rebar, that is resized. The first version of the examples was created autumn 2013 with AutoIt 3.3.8. These examples are not running under 3.3.10. This is an update for 3.3.10. Update 2014-05-04: AutoIt 3.3.10 All the examples in this update are based on a rebar. The code is optimized, and there are several bug fixes. This is a list of the examples: ToolbarReBar1.au3 - just a toolbar menu and a search box ToolbarReBar2.au3 - the example in the picture ToolbarReBar3.au3 - the right arrow is moved to the right side of the menu ToolbarReBar4.au3 - the top menu items (not custom drawn) are provided with an icon ToolbarReBar5.au3 - same as 4 but the top menu items are custom drawn ToolbarReBar6.au3 - the top menu buttons are split buttons ToolbarReBar7.au3 - added 4 buttons on the right side of the menu ToolbarReBar8.au3 - same as 7 but the 4 buttons can be replaced dynamically ToolbarReBar9.au3 - the drop down menus are replaced with custom controls The buttons in a toolbar are often used to open a drop down menu. Example 9 shows how the buttons can be used to open various controls. The buttons are still hot-track enabled. This is a picture of example 9: HotToolbar3.3.10.7z Testet on XP 32 bit and Win 7 32/64 bit. First version october 2013: AutoIt 3.3.8
    1 point
  21. Windows 7 I've had a chance to test the script on Windows 7. To be able to browse system folders e.g. the Control Panel on Windows 7 you have to run the script, EnumDesktopGUI.au3, in the proper way. If you are using Windows 7 64 bit you have to run the script as a 64 bit program to be able to browse the system folders. On Windows XP the generel look and appearance of the GUI is OK. There are problems on Windows 7: The menu bar doesn't look good. Disabled icons are looking very bad. The drop down menu of some of the buttons can erase parts of other controls. The grouping in the ListView of the items in Computer folder is looking very clumsy and the items seems to be mixed up in some way. Also for the Control Panel some items are mixed up and some items appears both as folders and files. I will try to find a solution to these issues. Update #2: 2012-08-20 See first post dated 2012-04-19 below. zip-files are attached to the bottom of the post. Severe error Fixed an error which could lead to a crash immediately before GUI was closed down. Data for the TreeView was deleted and memory freed while the TreeView still had focus. Sorting _GUICtrlListView_RegisterSortCallBack() and related functions are used for sorting. The functions are modified to group files and folders, and to properly sort by size, by type and by time. The functions are provided in the file SortListView.au3. It can be time consuming to sort a large number of files and folders. To prevent using time on both updating and sorting the ListView when a new folder is selected in the TreeView, the sorting mechanism is reset to default when a new folder is selected. The default sorting is the order of files and folders as provided in the "While $IEnumIDList.Next() ... WEnd" loops. Virtual folders It can be a lengthy process to expand a large number of subfolders in the TreeView. To avoid this multiple subfolders can be grouped into a number of virtual folders with a specific number of subfolders in each virtual folder. The virtual folders are only created in the TreeView and ListView. Not on the disk. Virtual folders will be used when the number of subfolders exceeds 300. The number of subfolders in each virtual folder is set to 100. These limits can be changed in the options. And the functionality can be disabled completely. This is testet in a folder with 4000 subfolders and 100 pictures in each subfolder. Expanding the subfolders is much much faster when using virtual folders. In this example there will be created 40 virtual folders named "1 - 100", "101 - 200", ..., "3901 - 4000". Each virtual folder will contain 100 subfolders. But the 100 subfolders will not be expanded until you click a virtual folder. That means that in stead of creating 4000 subfolders at one time (which is extremely time consuming) there will be created 40 virtual folders, and when you click a virtual folder there will be created 100 subfolders at a time. Other updates Right click menu in TreeView: Refresh Added a SplitterBar control between the TreeView and ListView Added grouping information to the ListView for My Computer folder If an icon file EnumDesktopGUI.ico exists, this icon will be used for the GUI Option to save GUI position and size on exit Option to set TreeView startup folder More info to the Details View Fixed some minor issues Update #1: 2012-04-25 In post #3 wraithdu pointed out that the built-in function ObjCreateInterface could be used in stead of AutoItObject. An advantage in using ObjCreateInterface is that according to the helpfile you can use a struct as a parameter in the description string for the methods of the interface. It works in this example. No need for a lot of calls to DllStructGetPtr(). With ObjCreateInterface enumeration of a folder looks like this: ; The address that receives an IShellFolder Interface pointer $pParentFolder = GetParentFolder( ... ) ; Create an IDispatch-Object for the IShellFolder Interface $IShellFolder = ObjCreateInterface( $pParentFolder, $sIID_IShellFolder, $dtagIShellFolder ) ; $pIEnumIDList is the address that receives an IEnumIDList interface pointer of the enumeration object If $IShellFolder.EnumObjects( $NULL, BitOR( $SHCONTF_FOLDERS, $SHCONTF_INCLUDEHIDDEN ), $pIEnumIDList ) = $S_OK Then ; Create an IDispatch-Object for the IEnumIDList Interface $IEnumIDList = ObjCreateInterface( $pIEnumIDList, $sIID_IEnumIDList, $dtagIEnumIDList ) ; Enumerate the folders ; Param 1 [in] : Step value as in a For-loop While $IEnumIDList.Next( 1, $pidlRel, $iFetched ) = $S_OK ; Param 2 [out]: PIDL relative to parent folder $iFolders += 1 ; Param 3 [out]: 0 if no more PIDLs, 1 else ... ... ... WEnd EndIf The zipfile below is updated with new au3-files (the 3 EnumDesktop-files) that uses ObjCreateInterface. This version is not depending on AutoItObject and AutoItObject.au3 is not included. In this example ObjCreateInterface seems to be working flawlessly. 2012-04-19 I've been looking at AutoItObject for some time. I've got inspiration for this example from a similar C++ example and from this thread http://www.autoitscript.com/forum/index.php?showtopic=123365. The GUI in the example is a Windows Explorer Viewer with a TreeView and a ListView. The root of the TreeView is the Desktop. You can browse the Desktop by expanding the folders in the TreeView. Select a folder to show the subfolders and files in the ListView. Right click on an item in the ListView to get file properties. Right click in the free area of the ListView to print a list of item names. Double click or press Enter on an item in the ListView to open a file or execute a program. With AutoItObject a folder doesn't have to be a file system folder. It can be any folder in the Desktop e.g. the Control Panel. The Desktop in this case means the root of the Shell's namespace. To enumerate a folder using AutoItObject you use code like this: ; The address that receives an IShellFolder Interface pointer $pParentFolder = GetParentFolder( ... ) ; Create an IDispatch-Object for the IShellFolder Interface $IShellFolder = _AutoItObject_WrapperCreate( $pParentFolder, $dtagIShellFolder ) ; The address that receives an IEnumIDList interface pointer of the enumeration object $aRet = $IShellFolder.EnumObjects( $NULL, BitOR( $SHCONTF_FOLDERS, $SHCONTF_INCLUDEHIDDEN ), 0 ) If $aRet[0] = $S_OK Then $pIEnumIDList = $aRet[3] ; Create an IDispatch-Object for the IEnumIDList Interface $IEnumIDList = _AutoItObject_WrapperCreate( $pIEnumIDList, $dtagIEnumIDList ) ; Enumerate the folders $aRet = $IEnumIDList.Next( 1, 0, 0 ) ; Param 1 [in] : Step value as in a For-loop While $aRet[3] ; Param 2 [out]: PIDL relative to parent folder $iFolders += 1 ; Param 3 [out]: 0 if no more PIDLs, 1 else ... ... ... $aRet = $IEnumIDList.Next( 1, 0, 0 ) WEnd EndIf Enumeration of a folder in this way uses PIDLs (pointers to ITEMIDLIST structures) in stead of file and folder names. See http://msdn.microsoft.com/en-us/library/windows/desktop/cc144090(v=vs.85).aspx. The zipfile below contains a number of files: EnumDesktopConsts.au3 - definitions and declarationsEnumDesktopFuncs.au3 - functions for the enumerationsEnumDesktopGUI.au3 - the GUI, run this fileFunctions.au3 - different functionsGetIcon.au3 - icon functionsWindows.au3 - child windows for options and infoStringSize.au3 - by Melba23, see http://www.autoitscript.com/forum/index.php?showtopic=114034HourglassOff.au3 - turn hourglass off, see belowres\ - 4 icons and WSP.dll by Yashied, see http://www.autoitscript.com/forum/index.php?showtopic=83621 post #16WSP.dll is used for NM_RETURN notifications in the ListView. The central file in the example is EnumDesktopFuncs.au3. The most important functions in the file are GetParentFolder() - returns an IShellFolder Interface pointer to the parent folderEnumTreeViewObjects() - expands the folders of the parent folder in the TreeViewEnumListViewObjects() - shows the folders and files in the ListView for the parent folderInvokeCommand() - opens a file or runs a program when an item in the ListView is activatedYou need AutoItObject by the AutoItObject team and APIConstants.au3 and WinAPIEx.au3 version 3.6 or 3.7 by Yashied. If the script fails for some reason and you are left with an hourglass cursor, then run HourglassOff.au3 to get the normal cursor back. Run EnumDesktopGUI.au3 in the zipfile. Testet on XP SP3. The zip-files can be opened with 7-Zip. 2012-04-19: Implemented with AutoItObject EnumDesktop.zip Update #2 2012-08-20: Implemented with ObjCreateInterface() (no need for AutoItObject, not included) EnumDesktop.zip EnumDesktop.zip
    1 point
×
×
  • Create New...