Leaderboard
Popular Content
Showing content with the highest reputation on 04/25/2014 in all areas
-
how to find a text on the screen
JayHawkfl and one other reacted to ModemJunki for a topic
I'm testing and I keep getting an error with hex "486f772061626f7574206e6f3f" ... ?2 points -
This guy? Inmate 107? I hope he and his pets are free soon.2 points
-
Don't wait for too long: JohnOne is known to be an extremely slow coder but don't repeat that, he's quite touchy2 points
-
Ok, wait there.2 points
-
1 point
-
Detefon, How about this little trick? #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> Global $hGui, $hMsg, $hStatus Global $iGUIHeight = 600 $hGui = GUICreate('title', 800, $iGUIHeight) Local $a_Status_Part[3] = [266, 532, -1] $hStatus = _GUICtrlStatusBar_Create($hGui) _GUICtrlStatusBar_SetParts($hStatus, $a_Status_Part) _GUICtrlStatusBar_SetText($hStatus, 'Part I', 0) _GUICtrlStatusBar_SetText($hStatus, 'Part II', 1) _GUICtrlStatusBar_SetText($hStatus, 'Part III', 2) GUISetState(@SW_SHOWNORMAL) $iStatusHeight = _GUICtrlStatusBar_GetHeight($hStatus) + (_GUICtrlStatusBar_GetBordersVert($hStatus) * 2) $aRect = _GUICtrlStatusBar_GetRect($hStatus, 0) $hMask = GUICreate("", $aRect[2] - $aRect[0], $aRect[3] - $aRect[1], 0, $iGUIHeight - $iStatusHeight, $WS_POPUP, $WS_EX_MDICHILD, $hGui) GUISetBkColor(0xFF0000) WinSetTrans($hMask, "", 0) GUISetState() AdlibRegister('flash', 500) While 1 $hMsg = GUIGetMsg() Switch $hMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func flash() Local Static $toggle = 1 If $toggle Then $toggle = 0 WinSetTrans($hMask, "", 100) Else $toggle = 1 WinSetTrans($hMask, "", 0) EndIf EndFunc ;==>flash Good enough? M231 point
-
That line should be: For $j = 0 To UBound($aTableData, 2) - 1 Cheers, sahsanu1 point
-
Whenever I have that kind of need I create an input and the date control next to it, resized to show only drop-down arrow. When user selects date I then copy date selected to input. This allows me to have blanks or whatever other value the situation dictates.1 point
-
Thank you for your effort john one I can't wait for the results1 point
-
Just adding the finishing touches.1 point
-
1 point
-
1 point
-
Set image png to ListView
incepator reacted to johnmcloud for a topic
; Johnmcloud - 2014 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIImageList.au3> #include <GUIListView.au3> #include <GDIPlus.au3> $hGUI = GUICreate("Johnmcloud Test GUI", 620, 440, -1, -1) $iListView = GUICtrlCreateListView("County|Name|Address", 0, 0, 620, 440, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($iListView) $hImageList = _GUIImageList_Create(40, 40) _GUICtrlListView_SetImageList($hListView, $hImageList, 1) _GUICtrlListView_InsertItem($hListView, 'RO', 0) _GUICtrlListView_SetItemImageEx($hListView, 0, @ScriptDir & "\img1.png") _GUICtrlListView_AddSubItem($hListView, 0, "Place to eat in Romania", 1) _GUICtrlListView_AddSubItem($hListView, 0, "7722 Dusty Cider Highlands", 2) _GUICtrlListView_InsertItem($hListView, 'RO', 1) _GUICtrlListView_SetItemImageEx($hListView, 0, @ScriptDir & "\img2.png") _GUICtrlListView_AddSubItem($hListView, 1, "Place to eat in England", 1) _GUICtrlListView_AddSubItem($hListView, 1, "3042 High Branch Freeway", 2) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, -1) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, -1) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, -1) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _GUICtrlListView_SetItemImageEx($hWnd, $iIndex, $sFile) ; Orginal function by Yashied Local $Size = _GUIImageList_GetIconSize($hImageList), $W, $H, $hGraphic, $hPic, $hImage, $hIcon If (Not $Size[0]) Or (Not $Size[1]) Then Return 0 _GDIPlus_Startup() $hPic = _GDIPlus_ImageLoadFromFile($sFile) $W = _GDIPlus_ImageGetWidth($hPic) $H = _GDIPlus_ImageGetHeight($hPic) If ($W < 0) Or ($H < 0) Then _GDIPlus_Shutdown() Return 0 EndIf If $W < $H Then $W = $Size[0] * $W / $H $H = $Size[1] Else $H = $Size[1] * $H / $W $W = $Size[0] EndIf $hImage = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hPic, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage[4]) _GDIPlus_GraphicsClear($hGraphic, 0) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPic, ($Size[0] - $W) / 2, ($Size[1] - $H) / 2, $W, $H) $hIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'ptr', $hImage[4], 'ptr*', 0) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage[4]) _GDIPlus_ImageDispose($hPic) _GDIPlus_Shutdown() If Not $hIcon[2] Then Return 0 _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon[2]) _GUICtrlListView_SetItemImage($hWnd, $iIndex, _GUIImageList_GetImageCount($hImageList) - 1) _WinAPI_DestroyIcon($hIcon[2]) Return 1 EndFunc ;==>_GUICtrlListView_SetItemImageEx1 point -
I created this after I developed because I was interested in the entry displaying when a folder was right clicked on. The entry will pass the folder name to your program via a commandline argument, so you'll have to use $CmdLine/$CmdLineRaw to access the folder that was selected. Any problems or suggestions then please post below. Thanks. UDF: #include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _ShellFolder ; AutoIt Version : v3.2.12.1 or higher ; Language ......: English ; Description ...: Create an entry in the shell contextmenu when selecting a folder, includes the program icon as well. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: Special thanks to KaFu for EnumRegKeys2Array() which I used as inspiration for enumerating the Registry Keys. ; =============================================================================================================================== ; #INCLUDES# ==================================================================================================================== ; None ; #GLOBAL VARIABLES# ============================================================================================================ ; None ; #CURRENT# ===================================================================================================================== ; _ShellFolder_Install: Creates an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu, but only displays when selecting a folder. ; _ShellFolder_Uninstall: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; __ShellFolder_RegistryGet ......; Retrieve an array of registry entries for a specific key. ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFolder_Install ; Description ...: Creates an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu, but only displays when selecting a file and folder. ; Syntax ........: _ShellFolder_Install($sText[, $sName = @ScriptName[, $sFilePath = @ScriptFullPath[, $sIconPath = @ScriptFullPath[, ; $iIcon = 0[, $fAllUsers = False[, $fExtended = False]]]]]]) ; Parameters ....: $sText - Text to be shown in the contextmenu. ; $sName - [optional] Name of the program. Default is @ScriptName. ; $sFilePath - [optional] Location of the program executable. Default is @ScriptFullPath. ; $sIconPath - [optional] Location of the icon e.g. program executable or dll file. Default is @ScriptFullPath. ; $iIcon - [optional] Index of icon to be used. Default is 0. ; $fAllUsers - [optional] Add to Current Users (False) or All Users (True) Default is False. ; $fExtended - [optional] Show in the Extended contextmenu using Shift + Right click. Default is False. ; Return values .: Success - Returns True ; Failure - Returns False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _ShellFolder_Install($sText, $sName = @ScriptName, $sFilePath = @ScriptFullPath, $sIconPath = @ScriptFullPath, $iIcon = 0, $fAllUsers = False, $fExtended = False) Local $i64Bit = '', $sRegistryKey = '' If $iIcon = Default Then $iIcon = 0 EndIf If $sFilePath = Default Then $sFilePath = @ScriptFullPath EndIf If $sIconPath = Default Then $sIconPath = @ScriptFullPath EndIf If $sName = Default Then $sName = @ScriptName EndIf If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & 'SOFTWAREClassesFoldershell' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & 'SOFTWAREClassesFoldershell' EndIf $sName = StringLower(StringRegExpReplace($sName, '.[^./]*$', '')) If StringStripWS($sName, 8) = '' Or FileExists($sFilePath) = 0 Then Return SetError(1, 0, False) EndIf _ShellFolder_Uninstall($sName, $fAllUsers) Local $iReturn = 0 $iReturn += RegWrite($sRegistryKey & $sName, '', 'REG_SZ', $sText) $iReturn += RegWrite($sRegistryKey & $sName, 'Icon', 'REG_EXPAND_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & 'command', '', 'REG_SZ', '"' & $sFilePath & '" "%1"') If $fExtended Then $iReturn += RegWrite($sRegistryKey & $sName, 'Extended', 'REG_SZ', '') EndIf Return $iReturn > 0 EndFunc ;==>_ShellFolder_Install ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFolder_Uninstall ; Description ...: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; Syntax ........: _ShellFolder_Uninstall([$sName = @ScriptName[, $fAllUsers = False]]) ; Parameters ....: $sName - [optional] Name of the Program. Default is @ScriptName. ; $fAllUsers - [optional] Was it added to Current Users (False) or All Users (True) Default is False. ; Return values .: Success - Returns True ; Failure - Returns False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _ShellFolder_Uninstall($sName = @ScriptName, $fAllUsers = False) Local $i64Bit = '', $sRegistryKey = '' If $sName = Default Then $sName = @ScriptName EndIf If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & 'SOFTWAREClassesFoldershell' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & 'SOFTWAREClassesFoldershell' EndIf $sName = StringLower(StringRegExpReplace($sName, '.[^./]*$', '')) If StringStripWS($sName, 8) = '' Then Return SetError(1, 0, 0) EndIf Local $aReturn = __ShellFolder_RegistryGet($sRegistryKey), $iReturn = 0, $sNameDeleted = '' If $aReturn[0][0] Then For $i = 1 To $aReturn[0][0] If $aReturn[$i][0] = $sName And $sNameDeleted <> $aReturn[$i][1] Then $sNameDeleted = $aReturn[$i][1] $iReturn += RegDelete($sNameDeleted) EndIf Next EndIf $aReturn = 0 Return $iReturn > 0 EndFunc ;==>_ShellFolder_Uninstall ; #INTERNAL_USE_ONLY#============================================================================================================ Func __ShellFolder_RegistryGet($sRegistryKey) Local $aArray[1][5] = [[0, 5]], $iCount_1 = 0, $iCount_2 = 0, $iDimension = 0, $iError = 0, $sRegistryKey_All = '', $sRegistryKey_Main = '', $sRegistryKey_Name = '', _ $sRegistryKey_Value = '' While 1 If $iError Then ExitLoop EndIf $sRegistryKey_Main = RegEnumKey($sRegistryKey, $iCount_1 + 1) If @error Then $sRegistryKey_All = $sRegistryKey $iError = 1 Else $sRegistryKey_All = $sRegistryKey & $sRegistryKey_Main EndIf $iCount_2 = 0 While 1 $sRegistryKey_Name = RegEnumVal($sRegistryKey_All, $iCount_2 + 1) If @error Then ExitLoop EndIf If ($aArray[0][0] + 1) >= $iDimension Then $iDimension = Ceiling(($aArray[0][0] + 1) * 1.5) ReDim $aArray[$iDimension][$aArray[0][1]] EndIf $sRegistryKey_Value = RegRead($sRegistryKey_All, $sRegistryKey_Name) $aArray[$aArray[0][0] + 1][0] = $sRegistryKey_Main $aArray[$aArray[0][0] + 1][1] = $sRegistryKey_All $aArray[$aArray[0][0] + 1][2] = $sRegistryKey & $sRegistryKey_Main & '' & $sRegistryKey_Name $aArray[$aArray[0][0] + 1][3] = $sRegistryKey_Name $aArray[$aArray[0][0] + 1][4] = $sRegistryKey_Value $aArray[0][0] += 1 $iCount_2 += 1 WEnd $iCount_1 += 1 WEnd ReDim $aArray[$aArray[0][0] + 1][$aArray[0][1]] Return $aArray EndFunc ;==>__ShellFolder_RegistryGetExample 1: #include "_ShellFolder.au3" Example() Func Example() _ShellFolder_Install('Start ShellFolder') ; Add the running EXE to the Shell ContextMenu. This will only display when selecting a drive and folder. Sleep(10000) _ShellFolder_Uninstall() ; Remove the running EXE from the Shell ContextMenu. EndFunc ;==>ExampleAll of the above has been included in a ZIP file. ShellFolder.zip1 point
-
See original post dated 2012-09-12 below. Final release: 2012-10-10 Everything put together in one zipfile (bottom of post) with two UDFs: ShellContextMenu.au3 and ShellContextMenuCustom.au3. The zip contains several examples. If you use ShellContextMenuCustom to add custom items to the context menu or modify existing items you must include five functions in your program to handle the custom/modified items: InsertCustomMenuItems(), InvokeCustomMenuItems(), HelpOnCustomMenuItems(), PrintMenuHelpMessage() and WM_INITMENUPOPUP(). See ListViewCustom. To add bitmaps to custom menu items you need _GUICtrlMenu_CreateBitmap.au3 and/or GUICtrlMenuEx.au3. See update #2. You also need APIConstants.au3 v3.8. Examples All examples are based on a ListView. Drag and drop some files or folders on the ListView. ListView.au3: Small example with ShellContextMenu.au3. ListViewCustom.au3: An example with ShellContextMenuCustom.au3. Shows how to add custom items to the context menu and how to add bitmaps to the custom items. ExContextMenus.au3: Shows three different context menus. If you right click a file/folder it shows the usual menu. If you right click in the free area of the ListView it shows a context menu similar to the context menu in the free area of Windows Explorer. This menu contains the New-menu. If you right click a label in the bottom of the GUI it shows the desktop context menu. ExModifyMenu.au3: Shows how to add custom items to the context menu and modify existing items. Also shows how to add bitmaps to custom items and to identify existing items with the language-independent verb. The picture is created from this example. ExPrintMenu.au3: If you right click a file/folder to display the menu and then quit, info about the menu items will be printed with _ArrayDisplay(). For each item the index, command id, menu text and verb will be printed. ExSubmenu.au3: Adds the context menu to an existing menu as a submenu. Update #7 2012-10-08: Cut/Copy/Paste asdf8 has pointed out that Cut/Copy/Paste commands aren't working. I've been doing some reading on this subject in the weekend. To make Cut/Copy/Paste work just use OleInitialize() to initialize COM in stead of CoInitialize(). Zipfile updated. Update #6 2012-10-05: Multiple selections asdf8 has pointed out that the menu commands aren't working if more than one file/folder is selected in the ListView. If this line in ShellContextMenu.au3 and ShellContextMenuCustom.au3: If $IShellFolder.GetUIObjectOf( $NULL, 1, $tArray, $tRIID_IContextMenu, 0, $pIContextMenu ) = $S_OK Then is replaced with this line: If $IShellFolder.GetUIObjectOf( $NULL, $cidl, $apidl, $tRIID_IContextMenu, 0, $pIContextMenu ) = $S_OK Then where $cidl is the number of selected files/folders and $apidl is an array of PIDLs for the files/folders relative to the parent folder, then the menu commands are working for multiple selections. Changed the styles of ListViews to allow multiple selections. Zipfile updated. Update #5 2012-10-01 Not applicable after update #6: Changed the style of ListViewCustom.au3 to allow multiple selections and added an example to show the proper Properties dialog box when multiple files/folders are selected. This is done with the function SHMultiFileProperties and the helper function CIDLData_CreateFromIDArray. Both functions are implemented in shell32.dll. On XP CIDLData_CreateFromIDArray can only be called with the ordinal value which is 83. Fixed an error in ListViewCustom.au3 which could lead to a crash on Windows 7. The function GetCommandVerb( $iCmd ) to get the language-independent verb must not be called if not $iCmd is in the valid range between $idCmdFirst (0x0001) and $idCmdLast (0x6FFF). Update #4 2012-09-27: Language-independent verb Added the CMF_EXTENDEDVERBS flag to the QueryContextMenu method to get extended items (Pin to Start menu) if holding the shift key while right clicking. To modify existing menu items it's necessary to be able to identify the items. A convenient way to identify the items is to use the language-independent verb. The language-independent verb can be extracted with a function like this: ; Get the verb, the language-independent command name ; Canonical verbs: copy, cut, delete, open, paste, print, rename Func GetCommandVerb( $iCmd ) Local $uFlags, $szName, $pszName, $tszName $uFlags = $GCS_VERB $tszName = DllStructCreate( "wchar[64]" ) $pszName = DllStructGetPtr( $tszName, 1 ) If $IContextMenu.GetCommandString( $iCmd - $idCmdFirst, $uFlags, $NULL, $pszName, 64 ) = $S_OK Then If BitAND( $uFlags, $GCS_UNICODE ) Then $szName = DllStructGetData( $tszName, 1 ) If StringLen( $szName ) > 0 Then Return $szName EndIf EndIf Return "" EndFuncGetCommandVerb() is called from WM_INITMENUPOPUP(). The WM_INITMENUPOPUP message is catched in the new window procedure. Examples of these canonical verbs are: copy, cut, delete, open, paste, print and rename. In ListViewCustom the Cut/Copy commands are renamed to Copy/Paste, the command identifiers are saved in two variables, and custom code is executed in stead of the default code. Update #3 2012-09-23: Help messages For Windows Explorer under XP help messages for the context menu are shown in the status bar. A help message is shown when an item is selected (hilited). When an item is selected it generates a WM_MENUSELECT notification which can be catched in the new window procedure: ; New window procedure to be able to handle messages from the shell context menu Func NewWindowProc( $hWnd, $iMsg, $iwParam, $ilParam ) If $pIContextMenu Then If $iMsg = $WM_MENUSELECT Then WM_MENUSELECT( $hWnd, $iMsg, $iwParam, $ilParam ) ... EndFuncIn the WM_MENUSELECT() function help messages are printed with the GetCommandString method of the IContextMenu interface. Update #2 2012-09-20: Bitmaps To add bitmaps to system-drawn (not owner-drawn) menu items (Custom1 and Custom2) you can use the UDF _GUICtrlMenu_CreateBitmap.au3 by UEZ. You can get it in the German forum by following this link: http://www.autoit.de/index.php?page=Thread&threadID=21001. The UDF is not included in the zip. To add bitmaps to owner-drawn menu items (Custom3, Custom4 and Custom5) you can use the UDF GUICtrlMenuEx.au3 by Ward. You can get it here: http://www.autoitscript.com/forum/index.php?showtopic=123223. The UDF is not included in the zip. If you want slightly more space between the owner-drawn menu items you can modify a line in the __GUICtrlMenuEx_WM_MEASUREITEM() function like this: DllStructSetData($MeasureItem, "itemHeight", $Size[1]) The original line DllStructSetData($MeasureItem, "itemHeight", $Size[1]+4) Add 4 extra pixels of spaceThis is done in the picture. Added a new zip at the bottom. Update #1 2012-09-17: Custom menu items When we have a handle to the context menu it's easy to add custom items. The zip at the bottom is updated. 2012-09-12 With ObjCreateInterface() it's possible to create a Shell Context Menu (Windows Explorer right click menu) for files and folders e.g. in a ListView or TreeView. This can also be implemented with AutoItObject or with a C/C++ dll-file (there is an example of that in this forum). Here is used ObjCreateInterface() so this is pure AutoIt. To create a Shell Context Menu you use the GetUIObjectOf method of the IShellFolder interface to get a pointer for the IContextMenu interface. With the QueryContextMenu method of this interface you add commands to the context menu and you execute the selected command with the InvokeCommand method. With QueryInterface you can get pointers to the IContextMenu2 and IContextMenu3 interfaces. You need these interfaces to be able to handle owner-drawn menu items e.g. the "Open With" or "Send To" submenues. To handle the events of the owner-drawn menu items you also need a new window procedure and you must initialize COM. This is the function in the UDF that shows the context menu: ; Show the Shell Context Menu Func ShellContextMenu( $hWnd, $hWndContext, $tPOINT, $sFullPath ) Local $pidlFQ, $pidlRel, $pIShellFolder, $IShellFolder Local $pIContextMenu, $IContextMenu, $tArray = DllStructCreate( "ptr" ) Local $hPopup, $iX, $iY, $iCmd, $fMask, $KeyState ; Get the fully qualified PIDL associated with the file $pidlFQ = ILCreateFromPath( $sFullPath ) ; Get an IShellFolder interface pointer ($pIShellFolder) for the parent folder ; and a PIDL ($pidlRel) associated with the file relative to the parent folder. SHBindToParent( $pidlFQ, DllStructGetPtr( $tRIID_IShellFolder ), $pIShellFolder, $pidlRel ) ; Create an IDispatch-Object for the IShellFolder Interface $IShellFolder = ObjCreateInterface( $pIShellFolder, $sIID_IShellFolder, $dtagIShellFolder ) ; Get a pointer to the IContextMenu Interface DllStructSetData( $tArray, 1, $pidlRel ) If $IShellFolder.GetUIObjectOf( $NULL, 1, $tArray, $tRIID_IContextMenu, 0, $pIContextMenu ) = $S_OK Then ; Create an IDispatch-Object for the IContextMenu Interface $IContextMenu = ObjCreateInterface( $pIContextMenu, $sIID_IContextMenu, $dtagIContextMenu ) ; Create a Popup menu $hPopup = CreatePopupMenu() ; Add commands to the Popup menu $IContextMenu.QueryContextMenu( $hPopup, 0, $idCmdFirst, $idCmdLast, $CMF_NORMAL ) ; Create an IDispatch-Object for the IContextMenu2 Interface $IContextMenu.QueryInterface( DllStructGetPtr( $tRIID_IContextMenu2 ), $pIContextMenu2 ) $IContextMenu2 = ObjCreateInterface( $pIContextMenu2, $sIID_IContextMenu2, $dtagIContextMenu2 ) ; Create an IDispatch-Object for the IContextMenu3 Interface $IContextMenu.QueryInterface( DllStructGetPtr( $tRIID_IContextMenu3 ), $pIContextMenu3 ) $IContextMenu3 = ObjCreateInterface( $pIContextMenu3, $sIID_IContextMenu3, $dtagIContextMenu3 ) ; Convert client coordinates to screen coordinates. ; This is among other things used to place the upper left corner ; of the Properties dialog box at the position of the mouse cursor. _WinAPI_ClientToScreen( $hWndContext, $tPoint ) $iX = DllStructGetData( $tPoint, "X" ) $iY = DllStructGetData( $tPoint, "Y" ) ; Show the Popup menu and track the selection $iCmd = TrackPopupMenuEx( $hPopup, $TPM_RETURNCMD, $iX, $iY, $hWnd ) If $iCmd > 0 Then ; Create and fill a $tagCMINVOKECOMMANDINFOEX structure Local $tCMINVOKECOMMANDINFOEX = DllStructCreate( $tagCMINVOKECOMMANDINFOEX ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "cbSize", DllStructGetSize( $tCMINVOKECOMMANDINFOEX ) ) $fMask = BitOr( $CMIC_MASK_UNICODE, $CMIC_MASK_PTINVOKE ) $KeyState = GetKeyState( $VK_CONTROL ) If $KeyState < 0 Or $KeyState > 32768 Then _ $fMask = BitOr( $fMask, $CMIC_MASK_CONTROL_DOWN ) $KeyState = GetKeyState( $VK_SHIFT ) If $KeyState < 0 Or $KeyState > 32768 Then _ $fMask = BitOr( $fMask, $CMIC_MASK_SHIFT_DOWN ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "fMask", $fMask ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "hWnd", $hWnd ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "lpVerb", $iCmd - $idCmdFirst ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "lpVerbW", $iCmd - $idCmdFirst ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "nShow", $SW_SHOWNORMAL ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "X", $iX ) DllStructSetData( $tCMINVOKECOMMANDINFOEX, "Y", $iY ) ; Invoke the command $IContextMenu.InvokeCommand( $tCMINVOKECOMMANDINFOEX ) EndIf ; Free memory allocated by the PIDL CoTaskMemFree( $pidlFQ ) ; Destroy menu and free memory DestroyMenu( $hPopup ) $pIContextMenu3 = 0 $pIContextMenu2 = 0 $IContextMenu3 = 0 $IContextMenu2 = 0 $IContextMenu = 0 $IShellFolder = 0 EndIf EndFunc Double click To open a file or folder in Windows Explorer you double click it. It's the same as right click and select the default (bold) menu item. When you double click you use the CMF_DEFAULTONLY flag to tell the QueryContextMenu that you only want the default menu item. This is the function in the UDF that executes the default menu item: ; Execute the default menu item Func InvokeCommand( $hWnd, $sFullPath ) Local $pidlFQ, $pidlRel, $pIShellFolder, $IShellFolder Local $pIContextMenu, $IContextMenu, $tArray = DllStructCreate( "ptr" ) Local $hPopup, $aRet, $idMenu ; Get the fully qualified PIDL associated with the file $pidlFQ = ILCreateFromPath( $sFullPath ) ; Get an IShellFolder interface pointer ($pIShellFolder) for the parent folder ; and a PIDL ($pidlRel) associated with the file relative to the parent folder. SHBindToParent( $pidlFQ, DllStructGetPtr( $tRIID_IShellFolder ), $pIShellFolder, $pidlRel ) ; Create an IDispatch-Object for the IShellFolder Interface $IShellFolder = ObjCreateInterface( $pIShellFolder, $sIID_IShellFolder, $dtagIShellFolder ) ; Get a pointer to the IContextMenu Interface DllStructSetData( $tArray, 1, $pidlRel ) If $IShellFolder.GetUIObjectOf( $NULL, 1, $tArray, $tRIID_IContextMenu, 0, $pIContextMenu ) = $S_OK Then ; Create an IDispatch-Object for the IContextMenu Interface $IContextMenu = ObjCreateInterface( $pIContextMenu, $sIID_IContextMenu, $dtagIContextMenu ) ; Create a Popup menu $hPopup = CreatePopupMenu() ; Add the default command to the Popup menu $aRet = $IContextMenu.QueryContextMenu( $hPopup, 0, $idCmdFirst, $idCmdLast, $CMF_DEFAULTONLY ) If $aRet >= 0 Then ; Get the menu item identifier Local $idMenu = GetMenuItemID( $hPopup, 0 ) ; Create and fill a $tagCMINVOKECOMMANDINFO structure Local $tCMINVOKECOMMANDINFO = DllStructCreate( $tagCMINVOKECOMMANDINFO ) DllStructSetData( $tCMINVOKECOMMANDINFO, "cbSize", DllStructGetSize( $tCMINVOKECOMMANDINFO ) ) DllStructSetData( $tCMINVOKECOMMANDINFO, "fMask", 0 ) DllStructSetData( $tCMINVOKECOMMANDINFO, "hWnd", $hWnd ) DllStructSetData( $tCMINVOKECOMMANDINFO, "lpVerb", $idMenu - $idCmdFirst ) DllStructSetData( $tCMINVOKECOMMANDINFO, "nShow", $SW_SHOWNORMAL ) ; Invoke the command $IContextMenu.InvokeCommand( $tCMINVOKECOMMANDINFO ) EndIf ; Free memory allocated by the PIDL CoTaskMemFree( $pidlFQ ) ; Destroy menu and free memory DestroyMenu( $hPopup ) $IContextMenu = 0 $IShellFolder = 0 EndIf EndFuncThis is a demonstration of how to use these functions to execute the default menu item when you double click. You can do exactly the same thing in one line with the builtin function ShellExecute(). Example This is a small example with a ListView. Drag and drop some files and folders on the ListView and right click to show the context menu or double click to open. (If the window with the ListView is inactive then activate the window by clicking the titlebar or click in the ListView outside the items. If you click a LV item in an inactive window it generates a double click and opens the corresponding file or folder.) #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include "ShellContextMenu.au3" Opt( "MustDeclareVars", 1 ) Global $hGui, $idLV, $hLV, $idLVdropFiles, $aLVfiles[1] Global $idLVrightClick, $idLVdoubleClick, $tLVpoint, $iLVidx MainScript() Func MainScript() $hGui = GUICreate( "The Shell Context Menu", 300, 200, 600, 300, -1, BitOR( $WS_EX_ACCEPTFILES, $WS_EX_TOPMOST ) ) $idLV = GUICtrlCreateListView( "", 0, 0, 300, 200 ) GUICtrlSetStyle( $idLV, BitOR( $LVS_LIST, $GUI_SS_DEFAULT_LISTVIEW ) ) GUICtrlSetState( $idLV, $GUI_DROPACCEPTED ) $hLV = ControlGetHandle( $hGui, "", $idLV ) $idLVdropFiles = GUICtrlCreateDummy() $idLVrightClick = GUICtrlCreateDummy() $idLVdoubleClick = GUICtrlCreateDummy() ; Window Procedures $hNewWinProc = DllCallbackRegister( "NewWindowProc", "int", "hwnd;uint;wparam;lparam" ) ; New window procedure $hOldWinProc = _WinAPI_SetWindowLong( $hGui, $GWL_WNDPROC, DllCallbackGetPtr( $hNewWinProc ) ) ; Old window procedure GUIRegisterMsg( $WM_DROPFILES, "WM_DROPFILES" ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState( @SW_SHOW ) ; Initialize COM CoInitialize() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete( $hGui ) ; Cleanup DllCallbackFree( $hNewWinProc ) CoUninitialize() CloseDlls() Exit Case $idLVdropFiles LVupdate() Case $idLVrightClick ; Show the Shell Context Menu ShellContextMenu( $hGui, $hLV, $tLVpoint, $aLVfiles[$iLVidx] ) Case $idLVdoubleClick ; Execute the default menu item InvokeCommand( $hGui, $aLVfiles[$iLVidx] ) EndSwitch WEnd EndFunc Func WM_DROPFILES( $hWnd, $iMsg, $iwParam, $ilParam ) #forceref $iMsg, $ilParam Switch $hWnd Case $hGui Local $aRet, $nSize, $tFileName $aRet = DllCall( $dllShell32, "int", "DragQueryFile", "hwnd", $iwParam, "int", -1, "ptr", 0, "int", 255 ) For $i = 0 To $aRet[0] - 1 $nSize = DllCall( $dllShell32, "int", "DragQueryFile", "hwnd", $iwParam, "int", $i, "ptr", 0, "int", 0 ) $nSize = $nSize[0] + 1 $tFileName = DllStructCreate( "char[" & $nSize & "]" ) DllCall( $dllShell32, "int", "DragQueryFile", "hwnd", $iwParam, "int", $i, "ptr", DllStructGetPtr( $tFileName ), "int", $nSize ) ReDim $aLVfiles[$i+1] $aLVfiles[$i] = DllStructGetData( $tFileName, 1 ) $tFileName = 0 Next GUICtrlSendToDummy( $idLVdropFiles ) Return 0 EndSwitch EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hLV Switch $iCode Case $NM_DBLCLK $tLVpoint = _WinAPI_GetMousePos( True, $hLV ) Local $iX = DllStructGetData( $tLVpoint, "X" ) Local $iY = DllStructGetData( $tLVpoint, "Y" ) Local $aHit = _GUICtrlListView_HitTest( $hLV, $iX, $iY ) If $aHit[2] Or $aHit[3] Then $iLVidx = $aHit[0] GUICtrlSendToDummy( $idLVdoubleClick ) EndIf Case $NM_RCLICK $tLVpoint = _WinAPI_GetMousePos( True, $hLV ) Local $iX = DllStructGetData( $tLVpoint, "X" ) Local $iY = DllStructGetData( $tLVpoint, "Y" ) Local $aHit = _GUICtrlListView_HitTest( $hLV, $iX, $iY ) If $aHit[2] Or $aHit[3] Then $iLVidx = $aHit[0] GUICtrlSendToDummy( $idLVrightClick ) Return 0 EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func LVupdate() _GUICtrlListView_DeleteAllItems( $hLV ) For $file In $aLVfiles GUICtrlCreateListViewItem( StringRight( $file, StringLen( $file ) - StringInStr( $file, "\", 0, -1 ) ), $idLV ) Next EndFuncThe example is also contained in the zipfile. Zipfile The zipfile contains the ShellContextMenu.au3 and ShellContextMenuCustom.au3 UDFs with the necessary globals, structures, interface definitions and functions. You need APIConstants.au3 v3.8 by Yashied. The zip contains several examples too. Testet on XP and 7. It would be nice if someone would test the UDF on Vista. The zipfile can be opened with 7-Zip. ShellContextMenu.zip (You need _GUICtrlMenu_CreateBitmap.au3 and/or GUICtrlMenuEx.au3. See top of post.)1 point