Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/28/2015 in all areas

  1. Header.au3 (run this): #include <WindowsConstants.au3> #include <GUIConstants.au3> #include <WinAPITheme.au3> #include <GuiListView.au3> #include <GuiHeader.au3> #include "DrawItem.au3" Opt( "MustDeclareVars", 1 ) Global $hHeader, $idHeaderOrder, $hLV, $aOrder = [ 0, 1, 2, 3 ] Global $aHeader = [ [ "Column 1", "", "" ], _ [ "Column 2", "Line 2", "" ], _ [ "Column 3", "Line 2", "Line 3" ], _ [ "Column 4", "Line 2", "" ] ] Example() Func Example() ; Create GUI Local $hGui = GUICreate( "ListView with multiple-line header", 400, 300, -1, 300 ) ; Create child Local $hChild = GUICreate( "", 380, 280, 10, 10, $WS_CHILD, -1, $hGui ) ; Create Header in child $hHeader = _GUICtrlHeader_Create( $hChild ) _GUICtrlHeader_AddItem( $hHeader, "", 95 ) _GUICtrlHeader_AddItem( $hHeader, "", 95 ) _GUICtrlHeader_AddItem( $hHeader, "", 95 ) _GUICtrlHeader_AddItem( $hHeader, "", 95 ) ; Doesn't work with themes _WinAPI_SetWindowTheme( $hHeader, "", "" ) ; Set all items owner drawn Local $tItem = DllStructCreate( $tagHDITEM ) For $i = 0 To 3 _GUICtrlHeader_GetItem( $hHeader, $i, $tItem ) DllStructSetData( $tItem, "Mask", $HDI_FORMAT ) DllStructSetData( $tItem, "Fmt", $HDF_OWNERDRAW ) _GUICtrlHeader_SetItem( $hHeader, $i, $tItem ) Next ; Set Header height Local $tRect = _WinAPI_GetClientRect( $hChild ) Local $tPos = _GUICtrlHeader_Layout( $hHeader, $tRect ) _WinAPI_SetWindowPos( $hHeader, DllStructGetData( $tPos, "InsertAfter" ), _ DllStructGetData( $tPos, "X" ), DllStructGetData( $tPos, "Y" ), _ DllStructGetData( $tPos, "CX" ), 54, DllStructGetData( $tPos, "Flags" ) ) ; Height = 54 ; Create ListView in child Local $idLV = GUICtrlCreateListView( "", 0, 54, 380, 280-54, $LVS_NOCOLUMNHEADER ) $hLV = GUICtrlGetHandle( $idLV ) _GUICtrlListView_AddColumn( $hLV, "Column 1", 94 ) _GUICtrlListView_AddColumn( $hLV, "Column 2", 94 ) _GUICtrlListView_AddColumn( $hLV, "Column 3", 94 ) _GUICtrlListView_AddColumn( $hLV, "Column 4", 94 ) For $i = 0 To 9 GUICtrlCreateListViewItem( $i & "/1|" & $i & "/2|" & $i & "/3|" & $i & "/4", $idLV ) Next ; Show child GUISetState() ; Switch to GUI GUISwitch( $hGui ) GUICtrlCreateLabel( "", 8, 8, 384, 58, 0x12 ) ; 0x12 = $SS_ETCHEDFRAME $idHeaderOrder = GUICtrlCreateDummy() GUIRegisterMsg( $WM_DRAWITEM, "WM_DRAWITEM" ) ; Draw Header item texts GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) ; Header events ; Show GUI GUISetState() Local $aMsg, $aOrderPrev = $aOrder, $aColValues[4], $aColWidths[4] While 1 $aMsg = GUIGetMsg( 1 ) Switch $aMsg[1] Case $hGui Switch $aMsg[0] Case $idHeaderOrder ; Get Header item order For $i = 0 To 3 $aOrder[$i] = _GUICtrlHeader_GetItemOrder( $hHeader, $i ) Next ; New order? If $aOrder[0] <> $aOrderPrev[0] Or $aOrder[1] <> $aOrderPrev[1] Or $aOrder[2] <> $aOrderPrev[2] Or $aOrder[3] <> $aOrderPrev[3] Then For $i = 0 To 3 $aColValues[$aOrder[$i]] = $i + 1 ; ListView column values $aColWidths[$aOrder[$i]] = _GUICtrlHeader_GetItemWidth( $hHeader, $i ) ; ListView column widths Next _GUICtrlListView_BeginUpdate( $hLV ) _GUICtrlListView_DeleteAllItems( $hLV ) For $i = 0 To 3 _GUICtrlListView_SetColumnWidth( $hLV, $i, $aColWidths[$i] ) ; Set ListView column widths Next For $i = 0 To 9 ; Set ListView column values GUICtrlCreateListViewItem( $i & "/" & $aColValues[0] & "|" & $i & "/" & $aColValues[1] & "|" & $i & "/" & $aColValues[2] & "|" & $i & "/" & $aColValues[3], $idLV ) Next _GUICtrlListView_EndUpdate( $hLV ) $aOrderPrev = $aOrder EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch EndSwitch WEnd EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Local $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hHeader Switch $iCode Case $HDN_TRACK, $HDN_TRACKW ; Header item width change (dragging the delimiter) Local $tNMHEADER = DllStructCreate( $tagNMHEADER, $lParam ), $tItem = DllStructCreate( $tagHDITEM, DllStructGetData( $tNMHEADER, "pItem" ) ) If BitAND( DllStructGetData( $tItem, "Mask" ), $HDI_WIDTH ) Then _GUICtrlListView_SetColumnWidth( $hLV, $aOrder[DllStructGetData( $tNMHEADER, "Item" )], DllStructGetData( $tItem, "XY" ) ) Case $HDN_ENDDRAG ; Dragging Header item finished GUICtrlSendToDummy( $idHeaderOrder ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_DRAWITEM( $hWnd, $iMsg, $wParam, $lParam ) #forceref $hWnd, $iMsg, $wParam Local $tDRAWITEM = DllStructCreate( $tagDRAWITEM, $lParam ) If DllStructGetData( $tDRAWITEM, "CtlType" ) <> $ODT_HEADER Then Return $GUI_RUNDEFMSG Switch DllStructGetData( $tDRAWITEM, "hwndItem" ) Case $hHeader Switch DllStructGetData( $tDRAWITEM, "itemAction" ) Case $ODA_DRAWENTIRE ; Set Header item texts Local $hDC = DllStructGetData( $tDRAWITEM, "hDC" ) DllStructSetData( $tDRAWITEM, "Left", DllStructGetData($tDRAWITEM, "Left") + 6 ) ; 6 pixel left margin DllStructSetData( $tDRAWITEM, "Top", DllStructGetData($tDRAWITEM, "Top") + 6 ) ; 6 pixel top margin Switch DllStructGetData( $tDRAWITEM, "itemID" ) Case 0 DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[0][0], "int", StringLen( $aHeader[0][0] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText Case 1 DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[1][0], "int", StringLen( $aHeader[1][0] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText DllStructSetData( $tDRAWITEM, "Top", DllStructGetData($tDRAWITEM, "Top") + 14 ) ; 14 pixels between lines DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[1][1], "int", StringLen( $aHeader[1][1] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText Case 2 DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[2][0], "int", StringLen( $aHeader[2][0] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText DllStructSetData( $tDRAWITEM, "Top", DllStructGetData($tDRAWITEM, "Top") + 14 ) ; 14 pixels between lines DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[2][1], "int", StringLen( $aHeader[2][1] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText DllStructSetData( $tDRAWITEM, "Top", DllStructGetData($tDRAWITEM, "Top") + 14 ) ; 14 pixels between lines DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[2][2], "int", StringLen( $aHeader[2][2] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText Case 3 DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[3][0], "int", StringLen( $aHeader[3][0] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText DllStructSetData( $tDRAWITEM, "Top", DllStructGetData($tDRAWITEM, "Top") + 14 ) ; 14 pixels between lines DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHeader[3][1], "int", StringLen( $aHeader[3][1] ), "ptr", DllStructGetPtr($tDRAWITEM, "Left"), "uint", 0 ) ; _WinAPI_DrawText EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc DrawItem.au3 (you need this): #include-once #include <StructureConstants.au3> Global Const $tagDRAWITEM = _ "uint CtlType;" & _ "uint CtlID;" & _ "uint itemID;" & _ "uint itemAction;" & _ "uint itemState;" & _ "hwnd hwndItem;" & _ "handle hDC;" & _ $tagRECT & ";" & _ ; longs: Left, Top, Right, Bottom "ulong_ptr itemData" ; CtlType constants Global Const $ODT_MENU = 1 Global Const $ODT_LISTBOX = 2 Global Const $ODT_COMBOBOX = 3 Global Const $ODT_BUTTON = 4 Global Const $ODT_STATIC = 5 Global Const $ODT_HEADER = 100 Global Const $ODT_TAB = 101 Global Const $ODT_LISTVIEW = 102 ; itemAction constants Global Const $ODA_DRAWENTIRE = 0x0001 Global Const $ODA_SELECT = 0x0002 Global Const $ODA_FOCUS = 0x0004 ; itemState constants Global Const $ODS_SELECTED = 0x0001 Global Const $ODS_GRAYED = 0x0002 Global Const $ODS_DISABLED = 0x0004 Global Const $ODS_CHECKED = 0x0008 Global Const $ODS_FOCUS = 0x0010 Global Const $ODS_DEFAULT = 0x0020 Global Const $ODS_HOTLIGHT = 0x0040 Global Const $ODS_INACTIVE = 0x0080 Global Const $ODS_NOACCEL = 0x0100 Global Const $ODS_NOFOCUSRECT = 0x0200 Global Const $ODS_COMBOBOXEDIT = 0x1000
    2 points
  2. zelles

    Get Mac Address Efficiently

    I was trying to get the MAC address of the computer running the script and the most efficient way seams to be using this function. I found it somewhere, but it was broken and would not run at all, and after making some change I got it displaying the Mac address. Does anyone know a more efficient way? This seams pretty efficient. Also, even though it works without issue, did I do things right in the function? Working function to get the MAC address: $IP_Address = @IPAddress1 $MAC_Address = GET_MAC($IP_Address) MsgBox(0, "MAC Address:", $MAC_Address) Func GET_MAC($_MACsIP) Local $_MAC,$_MACSize Local $_MACi,$_MACs,$_MACr,$_MACiIP $_MAC = DllStructCreate("byte[6]") $_MACSize = DllStructCreate("int") DllStructSetData($_MACSize,1,6) $_MACr = DllCall ("Ws2_32.dll", "int", "inet_addr", "str", $_MACsIP) $_MACiIP = $_MACr[0] $_MACr = DllCall ("iphlpapi.dll", "int", "SendARP", "int", $_MACiIP, "int", 0, "ptr", DllStructGetPtr($_MAC), "ptr", DllStructGetPtr($_MACSize)) $_MACs = "" For $_MACi = 0 To 5 If $_MACi Then $_MACs = $_MACs & ":" $_MACs = $_MACs & Hex(DllStructGetData($_MAC,1,$_MACi+1),2) Next DllClose($_MAC) DllClose($_MACSize) Return $_MACs EndFunc
    1 point
  3. UDF: #include-Once ; #INDEX# ======================================================================================================================= ; Title .........: HtmlEntities ; AutoIt Version : 3.2.10++ ; Language ......: English ; Description ...: Functions to escape Html reserved Characters. ; Author( .......: Raik ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $aisEntities[246][2]=[[34,'quot'],[38,'amp'],[39,'apos'],[60,'lt'],[62,'gt'],[160,'nbsp'],[161,'iexcl'],[162,'cent'],[163,'pound'],[164,'curren'],[165,'yen'],[166,'brvbar'],[167,'sect'],[168,'uml'],[169,'copy'],[170,'ordf'],[171,'laquo'],[172,'not'],[173,'shy'],[174,'reg'],[175,'macr'],[176,'deg'],[177,'plusmn'],[180,'acute'],[181,'micro'],[182,'para'],[183,'middot'],[184,'cedil'],[186,'ordm'],[187,'raquo'],[191,'iquest'],[192,'Agrave'],[193,'Aacute'],[194,'Acirc'],[195,'Atilde'],[196,'Auml'],[197,'Aring'],[198,'AElig'],[199,'Ccedil'],[200,'Egrave'],[201,'Eacute'],[202,'Ecirc'],[203,'Euml'],[204,'Igrave'],[205,'Iacute'],[206,'Icirc'],[207,'Iuml'],[208,'ETH'],[209,'Ntilde'],[210,'Ograve'],[211,'Oacute'],[212,'Ocirc'],[213,'Otilde'],[214,'Ouml'],[215,'times'],[216,'Oslash'],[217,'Ugrave'],[218,'Uacute'],[219,'Ucirc'],[220,'Uuml'],[221,'Yacute'],[222,'THORN'],[223,'szlig'],[224,'agrave'],[225,'aacute'],[226,'acirc'],[227,'atilde'],[228,'auml'],[229,'aring'],[230,'aelig'],[231,'ccedil'],[232,'egrave'],[233,'eacute'],[234,'ecirc'],[235,'euml'],[236,'igrave'],[237,'iacute'],[238,'icirc'],[239,'iuml'],[240,'eth'],[241,'ntilde'],[242,'ograve'],[243,'oacute'],[244,'ocirc'],[245,'otilde'],[246,'ouml'],[247,'divide'],[248,'oslash'],[249,'ugrave'],[250,'uacute'],[251,'ucirc'],[252,'uuml'],[253,'yacute'],[254,'thorn'],[255,'yuml'],[338,'OElig'],[339,'oelig'],[352,'Scaron'],[353,'scaron'],[376,'Yuml'],[402,'fnof'],[710,'circ'],[732,'tilde'],[913,'Alpha'],[914,'Beta'],[915,'Gamma'],[916,'Delta'],[917,'Epsilon'],[918,'Zeta'],[919,'Eta'],[920,'Theta'],[921,'Iota'],[922,'Kappa'],[923,'Lambda'],[924,'Mu'],[925,'Nu'],[926,'Xi'],[927,'Omicron'],[928,'Pi'],[929,'Rho'],[931,'Sigma'],[932,'Tau'],[933,'Upsilon'],[934,'Phi'],[935,'Chi'],[936,'Psi'],[937,'Omega'],[945,'alpha'],[946,'beta'],[947,'gamma'],[948,'delta'],[949,'epsilon'],[950,'zeta'],[951,'eta'],[952,'theta'],[953,'iota'],[954,'kappa'],[955,'lambda'],[956,'mu'],[957,'nu'],[958,'xi'],[959,'omicron'],[960,'pi'],[961,'rho'],[962,'sigmaf'],[963,'sigma'],[964,'tau'],[965,'upsilon'],[966,'phi'],[967,'chi'],[968,'psi'],[969,'omega'],[977,'thetasym'],[978,'upsih'],[982,'piv'],[8194,'ensp'],[8195,'emsp'],[8201,'thinsp'],[8204,'zwnj'],[8205,'zwj'],[8206,'lrm'],[8207,'rlm'],[8211,'ndash'],[8212,'mdash'],[8216,'lsquo'],[8217,'rsquo'],[8218,'sbquo'],[8220,'ldquo'],[8221,'rdquo'],[8222,'bdquo'],[8224,'dagger'],[8225,'Dagger'],[8226,'bull'],[8230,'hellip'],[8240,'permil'],[8242,'prime'],[8243,'Prime'],[8249,'lsaquo'],[8250,'rsaquo'],[8254,'oline'],[8260,'frasl'],[8364,'euro'],[8465,'image'],[8472,'weierp'],[8476,'real'],[8482,'trade'],[8501,'alefsym'],[8592,'larr'],[8593,'uarr'],[8594,'rarr'],[8595,'darr'],[8596,'harr'],[8629,'crarr'],[8656,'lArr'],[8657,'uArr'],[8658,'rArr'],[8659,'dArr'],[8660,'hArr'],[8704,'forall'],[8706,'part'],[8707,'exist'],[8709,'empty'],[8711,'nabla'],[8712,'isin'],[8713,'notin'],[8715,'ni'],[8719,'prod'],[8721,'sum'],[8722,'minus'],[8727,'lowast'],[8730,'radic'],[8733,'prop'],[8734,'infin'],[8736,'ang'],[8743,'and'],[8744,'or'],[8745,'cap'],[8746,'cup'],[8747,'int'],[8764,'sim'],[8773,'cong'],[8776,'asymp'],[8800,'ne'],[8801,'equiv'],[8804,'le'],[8805,'ge'],[8834,'sub'],[8835,'sup'],[8836,'nsub'],[8838,'sube'],[8839,'supe'],[8853,'oplus'],[8855,'otimes'],[8869,'perp'],[8901,'sdot'],[8968,'lceil'],[8969,'rceil'],[8970,'lfloor'],[8971,'rfloor'],[9001,'lang'],[9002,'rang'],[9674,'loz'],[9824,'spades'],[9827,'clubs'],[9829,'hearts'],[9830,'diams']] ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_HtmlEntities_Encode ;_HtmlEntities_Decode ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _HtmlEntities_Encode ; Description ...: Replaces Html Entities with the reserved Chars. ; Syntax.........: _HtmlEntities_Encode(ByRef $sTxt) ; Parameters ....: $sTxt - Html Source to modify ; Return values .: Returns always 0 ; Author ........: Raik ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _HtmlEntities_Encode(ByRef $sTxt) For $i=0 to 245 $sTxt=StringReplace($sTxt,ChrW($aisEntities[$i][0]),'&'&$aisEntities[$i][1]&';',0,1) Next EndFunc ;==>_HtmlEntities_Encode ; #FUNCTION# ==================================================================================================================== ; Name...........: _HtmlEntities_Decode ; Description ...: Replaces reserved Chars with its Html Entities. ; Syntax.........: _HtmlEntities_Decode(ByRef $sTxt) ; Parameters ....: $sTxt - Html Source to modify ; Return values .: Returns always 0 ; Author ........: Raik ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _HtmlEntities_Decode(ByRef $sTxt) For $i=0 to 245 $sTxt=StringReplace($sTxt,'&'&$aisEntities[$i][1]&';',ChrW($aisEntities[$i][0]),0,1) Next EndFunc ;==>_HtmlEntities_Decode Example: #include "EncodeHtmlEntities.au3" $txt="&lt;&Auml;&ouml;&uuml;&gt;" _HtmlEntities_Decode($txt) MsgBox(0,"Decode",$txt) _HtmlEntities_Encode($txt) MsgBox(0,"Encode",$txt)EncodeHtmlEntities.au3 EncodeHtmlEntities_Example.au3
    1 point
  4. Hiya! I'm currently working on a project which involves the mouse and its properties. For this I was in need for a mouse UDF which could capture certain events. I have found some of the many here on the forums, but quite some are using DLL's. I'm not saying this is bad, it's good! But, my application crashed for unknown reasons when compiled to x64. The way this UDF works, is that it checks every tick for certain conditions to be met. For example: if you have registered a double click event, it will check every frame for double click condition and then call the given function if necessary. So I decided to write my own little _Mouse_UDF powered in autoit itself and share it with the rest of the community. Feel free to leave any feedback, negative or positive. Current events $EVENT_MOUSE_IDLE - triggers when the mouse is idle $EVENT_MOUSE_MOVE - triggers when the mouse moves $EVENT_PRIMARY_CLICK - triggers when the primary button is clicked $EVENT_PRIMARY_DBLCLICK - triggers when the primary button is double clicked $EVENT_PRIMARY_RELEASED - triggers when the primary button is released $EVENT_PRIMARY_DOWN - triggers when the primary button is pressed $EVENT_PRIMARY_UP - triggers when the primaty button is not pressed $EVENT_SECONDARY_CLICK - same as primary conditions, but for this button $EVENT_SECONDARY_DBLCLICK - same as primary conditions, but for this button $EVENT_SECONDARY_RELEASED - same as primary conditions, but for this button $EVENT_SECONDARY_DOWN - same as primary conditions, but for this button $EVENT_SECONDARY_UP - same as primary conditions, but for this button $EVENT_MIDDLE_CLICK - same as primary conditions, but for this button $EVENT_MIDDLE_DBLCLICK - same as primary conditions, but for this button $EVENT_MIDDLE_RELEASED - same as primary conditions, but for this button $EVENT_MIDDLE_DOWN - same as primary conditions, but for this button $EVENT_MIDDLE_UP - same as primary conditions, but for this button $EVENT_X1_CLICK - same as primary conditions, but for this button $EVENT_X1_DBLCLICK - same as primary conditions, but for this button $EVENT_X1_RELEASED - same as primary conditions, but for this button $EVENT_X1_DOWN - same as primary conditions, but for this button $EVENT_X1_UP - same as primary conditions, but for this button $EVENT_X2_CLICK - same as primary conditions, but for this button $EVENT_X2_DBLCLICK - same as primary conditions, but for this button $EVENT_X2_RELEASED - same as primary conditions, but for this button $EVENT_X2_DOWN - same as primary conditions, but for this button $EVENT_X2_UP - same as primary conditions, but for this button Current properties $MOUSE_X - current mouse x $MOUSE_Y current mouse y $MOUSE_PREV_X - previous mouse x $MOUSE_PREV_Y - previous mouse y $MOUSE_VEL_X - current mouse x velocity $MOUSE_VEL_Y - current mouse y velocity Current functions _Mouse_RegisterEvent($iEventType, $sCallBack, $avArgs = -1) - registers a function to an event, use an array for arguments _Mouse_UnRegisterEvent($iEventType) - unregister a function from an event _Mouse_Update() - the main update loop, updates the mouse udf logic _Mouse_GetColor($iColorType, $hWnd = Default) - gets the current mouse xy pixel color, in 3 different color type available; decimal, hex and rgb Mouse UDF.zip
    1 point
  5. I created this after I developed >_ShellFolder() because I was interested in the entry displaying when an associated file was right clicked on. I was also intrigued to see how easy it would be to register a file type with my program, quite easy it appears. The UDF is a little different to what I've seen on the forum as this works with the Current User and/or All Users and an icon is created in the ContextMenu too. The entry will pass the file name to your program via a commandline argument, so you'll have to use $CmdLine/$CmdLineRaw to access the file 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 .........: _ShellFile ; AutoIt Version : v3.2.12.1 or higher ; Language ......: English ; Description ...: Create an entry in the shell contextmenu when selecting an assigned filetype, includes the program icon as well. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #INCLUDES# ==================================================================================================================== #include <Constants.au3> ; #GLOBAL VARIABLES# ============================================================================================================ ; None ; #CURRENT# ===================================================================================================================== ; _ShellFile_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 an assigned filetype to the program. ; _ShellFile_Uninstall: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; None ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFile_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 an assigned filetype to the program. ; Syntax ........: _ShellFile_Install($sText, $sFileType[, $sName = @ScriptName[, $sFilePath = @ScriptFullPath[, $sIconPath = @ScriptFullPath[, ; $iIcon = 0[, $fAllUsers = False[, $fExtended = False]]]]]]) ; Parameters ....: $sText - Text to be shown in the contextmenu. ; $sFileType - Filetype to be associated with the application e.g. .autoit or autoit. ; $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 _ShellFile_Install($sText, $sFileType, $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 & '\SOFTWARE\Classes\' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & '\SOFTWARE\Classes\' EndIf $sFileType = StringRegExpReplace($sFileType, '^\.+', '') $sName = StringLower(StringRegExpReplace($sName, '\.[^.\\/]*$', '')) If StringStripWS($sName, $STR_STRIPALL) = '' Or FileExists($sFilePath) = 0 Or StringStripWS($sFileType, $STR_STRIPALL) = '' Then Return SetError(1, 0, False) EndIf _ShellFile_Uninstall($sFileType, $fAllUsers) Local $iReturn = 0 $iReturn += RegWrite($sRegistryKey & '.' & $sFileType, '', 'REG_SZ', $sName) $iReturn += RegWrite($sRegistryKey & $sName & '\DefaultIcon\', '', 'REG_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & '\shell\open', '', 'REG_SZ', $sText) $iReturn += RegWrite($sRegistryKey & $sName & '\shell\open', 'Icon', 'REG_EXPAND_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & '\shell\open\command\', '', 'REG_SZ', '"' & $sFilePath & '" "%1"') $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 ;==>_ShellFile_Install ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFile_Uninstall ; Description ...: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; Syntax ........: _ShellFile_Uninstall($sFileType[, $fAllUsers = False]) ; Parameters ....: $sFileType - Filetype to be associated with the application e.g. .autoit or autoit. ; $fAllUsers - [optional] Add 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 _ShellFile_Uninstall($sFileType, $fAllUsers = False) Local $i64Bit = '', $sRegistryKey = '' If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & '\SOFTWARE\Classes\' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & '\SOFTWARE\Classes\' EndIf $sFileType = StringRegExpReplace($sFileType, '^\.+', '') If StringStripWS($sFileType, $STR_STRIPALL) = '' Then Return SetError(1, 0, False) EndIf Local $iReturn = 0, $sName = RegRead($sRegistryKey & '.' & $sFileType, '') If @error Then Return SetError(2, 0, False) EndIf $iReturn += RegDelete($sRegistryKey & '.' & $sFileType) $iReturn += RegDelete($sRegistryKey & $sName) Return $iReturn > 0 EndFunc ;==>_ShellFile_UninstallExample 1: #include <GUIConstantsEx.au3> #include '_ShellFile.au3' If @Compiled = 0 Then Exit MsgBox($MB_SYSTEMMODAL, '@Compiled Returned 0.', 'Please compile the program before testing. Thanks.') EndIf _Main() Func _Main() Local $sFilePath = '' If $CmdLine[0] > 0 Then $sFilePath = $CmdLine[1] EndIf Local $hGUI = GUICreate('_ShellFile() Example', 370, 110) GUICtrlCreateEdit(_GetFile($sFilePath), 10, 5, 350, 65) ; If a file was passed via commandline then random text will appear in the GUICtrlCreateEdit(). Local $iAdd = GUICtrlCreateButton('Add FileType', 10, 80, 75, 25) Local $iRemove = GUICtrlCreateButton('Remove FileType', 90, 80, 95, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iAdd _ShellFile_Install('Open with _ShellFile()', 'autoit') ; Add the running EXE to the Shell ContextMenu. If @error Then MsgBox($MB_SYSTEMMODAL, 'Association NOT Created.', '".autoit" was not associated due to an error occurring.') Else MsgBox($MB_SYSTEMMODAL, 'Association Created.', '"RandomFile.autoit" file was created to show that the filetype ".autoit" has been associtated with ' & @ScriptName & '.' & _ @CRLF & @CRLF & 'If you restart the computer you''ll see the icon of "RandomFile.autoit" is the same as the program icon.' & _ @CRLF & @CRLF & 'Now close the program and double/right click on "RandomFile.autoit" to display the random text in the edit box.') EndIf _SetFile(_RandomText(5000), @ScriptDir & '\RandomFile.autoit', 1) ; Create a file with Random text. Case $iRemove _ShellFile_Uninstall('autoit') ; Remove the running EXE from the Shell ContextMenu. If @error Then MsgBox($MB_SYSTEMMODAL, 'Association NOT Deleted.', '".autoit" was not deleted from the Registry due to an error occurring.') Else MsgBox($MB_SYSTEMMODAL, 'Association Deleted.', '".autoit" was successfully deleted from the Registry and is no longer associated with ' & @ScriptName & '.') EndIf EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Main Func _GetFile($sFilePath, $sFormat = 0) Local $hFileOpen = FileOpen($sFilePath, $sFormat) If $hFileOpen = -1 Then Return SetError(1, 0, 'No File Was Passed Via Commandline.') EndIf Local $sData = FileRead($hFileOpen) FileClose($hFileOpen) Return $sData EndFunc ;==>_GetFile Func _RandomText($iLength = 7) Local $iCount = 0, $iCRLF, $sData = '', $sRandom For $i = 1 To $iLength $sRandom = Random(55, 116, 1) If $iCount = 100 Then $iCRLF = @CRLF $iCount = 0 EndIf $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65)) & $iCRLF $iCount += 1 $iCRLF = '' Next Return $sData EndFunc ;==>_RandomText Func _SetFile($sString, $sFilePath, $iOverwrite = 0) Local $hFileOpen = FileOpen($sFilePath, $iOverwrite + 1) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) If @error Then Return SetError(1, 0, $sString) EndIf Return $sString EndFunc ;==>_SetFileAll of the above has been included in a ZIP file. ShellFile.zip
    1 point
  6. Here another workaround: #include <GUIConstantsEx.au3> #include <GuiHeader.au3> #include <GuiImageList.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> Global $g_hGUI, $g_idMemo, $g_hHeader Example() Func Example() Local $g_hGUI, $tRect, $tPos, $iHeight_Column = 40 _GDIPlus_Startup() ; Create GUI $g_hGUI = GUICreate("Header", 400, 300) $g_hHeader = _GUICtrlHeader_Create($g_hGUI, $HDS_FLAT) _GUICtrlHeader_SetUnicodeFormat($g_hHeader, True) $g_idMemo = GUICtrlCreateEdit("", 1, 40, 398, 259, 0) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) $tRect = _WinAPI_GetClientRect( $g_hHeader ) $tPos = _GUICtrlHeader_Layout( $g_hHeader, $tRect ) _WinAPI_SetWindowPos( $g_hHeader, DllStructGetData( $tPos, "InsertAfter" ), _ DllStructGetData( $tPos, "X" ), DllStructGetData( $tPos, "Y" ), _ DllStructGetData( $tPos, "CX" ), $iHeight_Column, DllStructGetData( $tPos, "Flags" ) ) $hImage = _GUIImageList_Create(0, 0, 6) ; Add columns _GUICtrlHeader_AddItem($g_hHeader, "", 100, 1, 0) _GUICtrlHeader_AddItem($g_hHeader, "Column 2", 100, 0, 1) _GUICtrlHeader_AddItem($g_hHeader, "Column 3", 100, 0, 2) _GUICtrlHeader_AddItem($g_hHeader, "Column 4", 100) Local $iBgColor = _WinAPI_GetSysColor($COLOR_MENU) ;I don'T know which color index is the correct one ConsoleWrite(Hex($iBgColor, 6) & @CRLF) $hHBitmap = _GDIPlus_DrwTxt(" Line 1" & @CRLF & " Line 2", 90, $iHeight_Column, 0xFFFCFCFC) _GUICtrlHeader_SetItemBitmap($g_hHeader, 0, $hHBitmap) _GUICtrlHeader_SetImageList($g_hHeader, $hImage) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hHBitmap) _GDIPlus_Shutdown() EndFunc ;==>Example Func _GDIPlus_DrwTxt($sText, $iW, $iH, $iBgColor = 0xFFF0F0F0, $iFontSize = 8.5, $sFont = "MS Shell Dlg", $iAlign = 0, $iFontColor = 0xFF000000, $bAntiAlias = False) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hCtxt, $iBgColor) If $bAntiAlias Then _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4) EndIf Local Const $hBrush = _GDIPlus_BrushCreateSolid($iFontColor) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize) _GDIPlus_StringFormatSetAlign($hFormat, $iAlign) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hCtxt) Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBitmap EndFunc
    1 point
  7. I use WMI, personally: #include <MsgBoxConstants.au3> $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $oWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $oItems = $oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($oItems) then For $oOS In $oItems ConsoleWrite($oOS.Caption & @CRLF) Next Else Msgbox($MB_OK,"Error","No WMI Objects Found") Endif
    1 point
  8. I'm uncertain how much of a buffer STDERR reserves so I'd keep that stream for reporting just that, errors. I do not subscribe to what good and bad practices are outside of the notion of commenting your code if someone else is likely to use it, or keeping to standard practices defined by a group you might be working alongside.
    1 point
  9. Never looked into this one myself. Your parent program would use stdinwrite to send data to your child program. For your child program to get information from its parent, it would use the ConoleRead function. That is the opposite of what you have above.
    1 point
  10. Should be called SQGreat.
    1 point
  11. Melba23

    Waitfor Shift+LeftMouse?

    Turin74, AutoIt does indeed have such a feature: as suggested above, look at _IsPressed in the Help file. The function uses an API call and will tell you if specified keys/mouse buttons are pressed or not. M23
    1 point
  12. Q: How can I test if checkbox/radiobutton is checked? A: Use this small function: If IsChecked($checkbox1) Then ... Func IsChecked($control) Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED EndFunc This question was asked/answered really many many times. Probably function IsChecked($control) could be added to AutoIt as native function because it's basic functionality of GUI
    1 point
×
×
  • Create New...