Jump to content

Leaderboard

Popular Content

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

  1. I tidied the code from a post made by KaFu. The code is fully working in both x32 & x64. I also used _CmdLineRaw() to parse $CmdLineRaw to an Array. Function: Version 11 (20/07/2014) #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Global Const $tagCOPYDATASTRUCT = 'ulong_ptr dwData;' & _ 'dword cbData;' & _ 'ptr lpData' Global $IPC_GUID = 'E23D443E-F0E1-11E3-9E5C-90580B9E45A7' Global Enum $IPC_AUTOITID, _ $IPC_CLIENTWND, $IPC_CLIENTID, _ $IPC_GLOBALID, _ $IPC_ID, $IPC_ISMONITORING, _ $IPC_MONITORID, _ $IPC_SERVERWND, $IPC_SERVERID, _ $IPC_MAX Global Enum $IPC_CONTROLID, _ $IPC_RECEIVEDDATA, $IPC_RECEIVEDWND, $IPC_RECEIVEDMSG, _ $IPC__MAX Global $IPC[$IPC__MAX] ; Internal array for the interprocess communication functions. $IPC[$IPC_CONTROLID] = 0 #Region Example ; Display only if compiled. If @Compiled Then Example() Else MsgBox($MB_SYSTEMMODAL, '', 'Please compile the example before running.') EndIf Func Example() Local $hIPC = _InterProcess('F23B0E88-ED9F-11E3-8179-82ADECBA0006', Default) ; Start the interprocess communication. _InterProcess_Monitor($hIPC) If _InterProcess_IsServerExists($hIPC) And Not _InterProcess_SendToServer($hIPC, 'This is a sample string') Then ; Send a sample string if there is a main process already running. MsgBox($MB_SYSTEMMODAL, 'Second Instance: ' & @AutoItPID, _ 'Seems there was an error sending the IPC message, but more than likely the string was blank.') EndIf Local $hWnd = 0, _ $iMsg = 0, _ $sMsg = '' Local Const $SERVER_CLOSE_PROCESS = 1001 While 1 Switch GUIGetMsg() Case _InterProcess_GetMonitorID($hIPC) ; The monitoring id used to notify when an IPC message is received. ; If the process is an server i.e. the first instance, then read the data sent by a client and ; respond that the IPC message was received If _InterProcess_IsThisServer($hIPC) Then If _InterProcess_GetData($hIPC, $hWnd, $sMsg, $iMsg) Then MsgBox($MB_SYSTEMMODAL, 'First Instance: ' & @AutoItPID, _ 'hWnd: ' & $hWnd & @CRLF & _ 'Data: ' & $sMsg & @CRLF & _ 'Message: ' & $iMsg & @CRLF) ; Parse the relevant handle and data from the message. If $iMsg = $SERVER_CLOSE_PROCESS Then ; Check the $iMsg parameter doesn't contain the message to close this instance. ExitLoop ; If the $iMsg parameter is equal to $IPC_CLOSE_PROCESS (1001) the close the first instance. Else _InterProcess_SendToClient($hIPC, $hWnd, 'The data was successfully received by the first instance (server). This second instance (client) will now close. Thanks.') EndIf EndIf ; If the process is not the first instance also known as a client, then wait for the server to send a reply that it ; successfully recived the IPC message. ElseIf _InterProcess_IsThisClient($hIPC) Then If _InterProcess_GetData($hIPC, $hWnd, $sMsg, $iMsg) Then MsgBox($MB_SYSTEMMODAL, 'Second Instance: ' & @AutoItPID, _ 'hWnd: ' & $hWnd & @CRLF & _ 'Data: ' & $sMsg & @CRLF & _ 'Message: ' & $iMsg & @CRLF) ; Parse the relevant handle and data from the message. _InterProcess_SendToServer($hIPC, 'The second instance (client) recieved the message to close their instance so this instance (server) will close too.', $SERVER_CLOSE_PROCESS) ExitLoop EndIf EndIf EndSwitch WEnd _InterProcess_Destroy($hIPC) EndFunc ;==>Example #EndRegion Example Func _InterProcess($sGUID, $hWnd) Local $aIPC[$IPC_MAX] $aIPC[$IPC_ID] = $IPC_GUID $aIPC[$IPC_AUTOITID] = AutoItWinGetTitle() $aIPC[$IPC_ISMONITORING] = False If StringRegExp($sGUID, '^(?:\{){0,1}[[:xdigit:]]{8}-(?:[[:xdigit:]]{4}-){3}[[:xdigit:]]{12}(?:\}){0,1}$') Then ; Is GUID. $aIPC[$IPC_GLOBALID] = StringUpper($sGUID) Else $aIPC[$IPC_GLOBALID] = 'IPC_' & $IPC_GUID EndIf $aIPC[$IPC_CLIENTWND] = $hWnd $aIPC[$IPC_CLIENTID] = $aIPC[$IPC_GLOBALID] & '_CLIENT' $aIPC[$IPC_SERVERWND] = 0 $aIPC[$IPC_SERVERID] = $aIPC[$IPC_GLOBALID] & '_SERVER' $hWnd = WinGetHandle($aIPC[$IPC_SERVERID]) If @error Or Not $hWnd Then ; No interprocess communication server exists. $aIPC[$IPC_SERVERWND] = 0 Else Local Const $hControl = ControlGetHandle($hWnd, '', 'Edit1') $aIPC[$IPC_SERVERWND] = HWnd( _ StringRegExp('|' & ControlGetText($hWnd, '', $hControl) & '|IPC_WND:0x00000000|', _ '\|IPC_WND:(0[xX][[:xdigit:]]+)\|', _ $STR_REGEXPARRAYGLOBALMATCH)[0] _ ) ; Retrieve the server communication handle. EndIf Return $aIPC EndFunc ;==>_InterProcess Func _InterProcess_Destroy(ByRef $aIPC) Local $bReturn = False If __InterProcess_IsAPI($aIPC) Then $bReturn = True Local $hAutoItWnd = 0 If _InterProcess_IsThisServer($aIPC) Then $hAutoItWnd = WinGetHandle($aIPC[$IPC_SERVERID]) ElseIf _InterProcess_IsThisClient($aIPC) And _InterProcess_IsClientExists($aIPC) Then $hAutoItWnd = WinGetHandle($aIPC[$IPC_CLIENTID]) EndIf If IsHWnd($hAutoItWnd) Then Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, _ StringRegExpReplace(ControlGetText($hAutoItWnd, '', $hControl), _ '(?<=\n)\|IPC_(?:WND|PID):\V+\R', _ '')) ; Destroy the communication handle and PID. ; Destroy the associated GUI. GUIRegisterMsg($WM_COPYDATA, '') If $aIPC[$IPC_MONITORID] > 0 Then GUICtrlDelete($aIPC[$IPC_MONITORID]) EndIf If IsHWnd($aIPC[$IPC_CLIENTWND]) Then GUIDelete($aIPC[$IPC_CLIENTWND]) EndIf EndIf _InterProcess_Destroy_Monitor($aIPC) AutoItWinSetTitle($aIPC[$IPC_AUTOITID]) EndIf $aIPC = Null ; Destroy the contents of the API. Return $bReturn EndFunc ;==>_InterProcess_Destroy Func _InterProcess_Destroy_Monitor(ByRef $aIPC) Local $bReturn = False If __InterProcess_IsAPI($aIPC) And $aIPC[$IPC_ISMONITORING] Then $IPC[$IPC_CONTROLID] = 0 $aIPC[$IPC_ISMONITORING] = False $bReturn = True EndIf Return $bReturn EndFunc ;==>_InterProcess_Destroy_Monitor Func _InterProcess_GetClientID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_CLIENTID] : Null EndFunc ;==>_InterProcess_GetClientID Func _InterProcess_GetGlobalID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_GLOBALID] : Null EndFunc ;==>_InterProcess_GetGlobalID Func _InterProcess_GetMonitorID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_MONITORID] : 0 EndFunc ;==>_InterProcess_GetMonitorID Func _InterProcess_GetServerID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_SERVERID] : Null EndFunc ;==>_InterProcess_GetServerID Func _InterProcess_GetData(ByRef $aIPC, ByRef $hWnd, ByRef $sMsg, ByRef $iMsg) $hWnd = 0 $iMsg = 0 $sMsg = '' Local $bReturn = False If __InterProcess_IsAPI($aIPC) And ($IPC[$IPC_RECEIVEDDATA] Or $IPC[$IPC_RECEIVEDMSG]) Then $bReturn = True $hWnd = (IsHWnd($IPC[$IPC_RECEIVEDWND]) ? $IPC[$IPC_RECEIVEDWND] : Null) ; hWnd. $iMsg = Int($IPC[$IPC_RECEIVEDMSG]) $sMsg = $IPC[$IPC_RECEIVEDDATA] ; Data EndIf $IPC[$IPC_RECEIVEDDATA] = '' $IPC[$IPC_RECEIVEDWND] = 0 $IPC[$IPC_RECEIVEDMSG] = 0 Return $bReturn EndFunc ;==>_InterProcess_GetData Func _InterProcess_GetClientWnd(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_CLIENTWND] : Null EndFunc ;==>_InterProcess_GetClientWnd Func _InterProcess_GetServerWnd(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? (_InterProcess_IsThisServer($aIPC) ? $aIPC[$IPC_CLIENTWND] : $aIPC[$IPC_SERVERWND]) : Null EndFunc ;==>_InterProcess_GetServerWnd Func _InterProcess_IsClientExists(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And IsHWnd($aIPC[$IPC_CLIENTWND]) And $aIPC[$IPC_MONITORID] > 0 EndFunc ;==>_InterProcess_IsClientExists Func _InterProcess_IsMonitoring(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And $aIPC[$IPC_ISMONITORING] EndFunc ;==>_InterProcess_IsMonitoring Func _InterProcess_IsServerExists(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And IsHWnd($aIPC[$IPC_SERVERWND]) EndFunc ;==>_InterProcess_IsServerExists Func _InterProcess_IsThisServer(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And Not IsHWnd($aIPC[$IPC_SERVERWND]) EndFunc ;==>_InterProcess_IsThisServer Func _InterProcess_IsThisClient(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And Not _InterProcess_IsThisServer($aIPC) EndFunc ;==>_InterProcess_IsThisClient Func _InterProcess_Monitor(ByRef $aIPC) Local $bReturn = False If __InterProcess_IsAPI($aIPC) And Not $aIPC[$IPC_ISMONITORING] Then $aIPC[$IPC_ISMONITORING] = True If _InterProcess_IsThisServer($aIPC) And Not _InterProcess_IsClientExists($aIPC) Then __InterProcess_Create($aIPC[$IPC_CLIENTWND], $aIPC[$IPC_MONITORID], $aIPC[$IPC_SERVERID]) ElseIf _InterProcess_IsThisClient($aIPC) And Not _InterProcess_IsClientExists($aIPC) Then __InterProcess_Create($aIPC[$IPC_CLIENTWND], $aIPC[$IPC_MONITORID], $aIPC[$IPC_CLIENTID]) EndIf $IPC[$IPC_CONTROLID] = $aIPC[$IPC_MONITORID] $bReturn = True EndIf Return $bReturn EndFunc ;==>_InterProcess_Monitor Func _InterProcess_SendToServer(ByRef $aIPC, $sMsg, $iMsg = Default) Return __InterProcess_IsAPI($aIPC) And __InterProcess_Send($aIPC[$IPC_CLIENTWND], $aIPC[$IPC_SERVERWND], $iMsg, $sMsg) EndFunc ;==>_InterProcess_SendToServer Func _InterProcess_SendToClient(ByRef $aIPC, $hWnd, $sMsg, $iMsg = Default) Return __InterProcess_IsAPI($aIPC) And __InterProcess_Send($aIPC[$IPC_CLIENTWND], $hWnd, $iMsg, $sMsg) EndFunc ;==>_InterProcess_SendToClient Func _InterProcess_SetGUID($sGUID) $IPC_GUID = $sGUID Return True EndFunc ;==>_InterProcess_SetGUID Func __InterProcess_Create(ByRef $hWnd, ByRef $iControl, $sID) If Not IsHWnd($hWnd) Or $hWnd = Default Then $hWnd = GUICreate('', 0, 0, -99, -99, $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW) GUISetState(@SW_SHOWNOACTIVATE, $hWnd) EndIf If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hWnd, $WM_COPYDATA, $MSGFLT_ALLOW) EndIf If Not $iControl Then $iControl = GUICtrlCreateDummy() EndIf GUIRegisterMsg($WM_COPYDATA, WM_COPYDATA) AutoItWinSetTitle($sID) Local Const $hAutoItWnd = WinGetHandle($sID) Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, ControlGetText($hAutoItWnd, '', $hControl) & @CRLF & _ '|IPC_WND:' & $hWnd & '|IPC_PID:' & @AutoItPID & @CRLF) ; Set the communication handle and PID. Return True EndFunc ;==>__InterProcess_Create Func __InterProcess_IsAPI(ByRef $aIPC) Return UBound($aIPC) = $IPC_MAX And $aIPC[$IPC_ID] = $IPC_GUID EndFunc ;==>__InterProcess_IsAPI Func __InterProcess_Send($hSender, $hReciever, $iMsg, $sMsg) If Not IsHWnd($hReciever) Then Return SetError(1, 0, False) EndIf If StringStripWS($sMsg, $STR_STRIPALL) = '' Then Return SetError(2, 0, False) EndIf If Not IsInt($iMsg) Then $iMsg = 0 EndIf $sMsg = $IPC_GUID & $sMsg Local Const $tBuffer = DllStructCreate('wchar cdata[' & StringLen($sMsg) + 1 & ']') DllStructSetData($tBuffer, 'cdata', $sMsg) Local Const $tCOPYDATASTRUCT = DllStructCreate($tagCOPYDATASTRUCT) DllStructSetData($tCOPYDATASTRUCT, 'dwData', $iMsg) DllStructSetData($tCOPYDATASTRUCT, 'cbData', DllStructGetSize($tBuffer)) DllStructSetData($tCOPYDATASTRUCT, 'lpData', DllStructGetPtr($tBuffer)) _SendMessage($hReciever, _ $WM_COPYDATA, _ $hSender, _ DllStructGetPtr($tCOPYDATASTRUCT)) Return Not @error EndFunc ;==>__InterProcess_Send Func WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local Const $tCOPYDATASTRUCT = DllStructCreate($tagCOPYDATASTRUCT, $lParam) Local Const $tBuffer = DllStructCreate('wchar cdata[' & DllStructGetData($tCOPYDATASTRUCT, 'cbData') / 2 & ']', DllStructGetData($tCOPYDATASTRUCT, 'lpData')) $IPC[$IPC_RECEIVEDDATA] = StringRegExpReplace(DllStructGetData($tBuffer, 'cdata'), '^' & $IPC_GUID, '') ; Data. If @extended > 0 Then $IPC[$IPC_RECEIVEDWND] = $wParam ; hWnd. $IPC[$IPC_RECEIVEDMSG] = DllStructGetData($tCOPYDATASTRUCT, 'dwData') ; Message. If $IPC[$IPC_CONTROLID] > 0 Then GUICtrlSendToDummy($IPC[$IPC_CONTROLID]) ; Send to the control. EndIf Else $IPC[$IPC_RECEIVEDDATA] = '' EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COPYDATA
    1 point
  2. Gianni

    Inputbox description ?

    GUICtrlCreateInput("description that is erased when you type", 10, 5, 300, 20)
    1 point
  3. InputBox('title', 'prompt' , 'description that is erased when you type')
    1 point
  4. Are you trying to write to HKLM? if so, you need admin rights, that's maybe your issue
    1 point
  5. Two small spherical trig UDFs using Airy's ellipsoid to convert between the British Ordnance Survey grid (easting and northing, in metres) and latitude-longitude coordinates (in decimal degrees), with alternative ellipsoids for Ireland and Channel Islands (see annotations at the end). All four parameters need to be pre-declared (as the new values are parsed ByRef). Source was partly gleaned from here. I doubt whether anyone outside of Britain will find this of use, but you never know, so here goes: ; Example OS grid to lat/lon $easting=651409 ; in meters $northing=313177 ; in meters $lat=0 ; in decimal degrees $lon=0 ; in decimal degrees ; returns results in pre-declared vars $lat, $lon _OSgrid_ToLatLon($easting, $northing, $lat, $lon) MsgBox(0,"OSgrid_TOLatLon", "OS coordinates Easting: " & $easting & ", Northing: " & $northing & @CR & _ "Latitude: " & $lat & ", Longitude: " & $lon & @CR & "NGR: " & _OSNE2BNG($easting, $northing)) ; Example lat/lon to OS grid $lat = 52.65757 $lon = 1.71791 $easting=0 $northing=0 _OSgrid_FromLatLon($lat, $lon, $easting, $northing) MsgBox(0,"OSgrid_FROMLatLon", "OS coordinates Easting: " & $easting & ", Northing: " & $northing & @CR & _ "Latitude: " & $lat & ", Longitude: " & $lon & @CR & "NGR: " & _OSNE2BNG($easting, $northing)) Func _OSgrid_ToLatLon($E, $N, ByRef $lat, ByRef $lon) ; converts Ordnance Survey grid easting and norting, in meters ; into latitude-longitude coordinates, in decimal degrees ; source not recorded; adapted from a code I wrote many years ago. Local $deg2rad=3.141592653589793238462643/180 Local $rad2deg=180/3.141592653589793238462643 ; Airy 1830, national grid parameters Local $a = 6377563.396 ; semi-major ellipsoidal axis Local $b = 6356256.910 ; semi-minor ellipsoidal axis Local $N0= -100000 ; northing of true origin Local $E0= 400000 ; easting of true origin Local $F0= 0.9996012717 ; scale factor on central meridian Local $phi0= 49 * $deg2rad ; latitude of true origin Local $lam0= -2 * $deg2rad ; longitude of true origin and central meridian Local $e2=($a^2-$b^2)/$a^2 ; squared ellipticity Local $phi_prime=(($N-$N0)/($a*$F0))+$phi0 Local $M=_GetM($phi_prime) Local $iter=0 While abs($N-$N0-$M)>=0.01 and $iter<=100 ; max iterations to converge $iter+=1 $phi_prime=(($N-$N0-$M)/($a*$F0))+$phi_prime $M=_GetM($phi_prime) WEnd Local $nu = $a*$F0*(1-$e2*sin($phi_prime)^2)^-0.5 Local $rho = $a*$F0*(1-$e2)*(1-$e2*sin($phi_prime)^2)^-1.5 Local $eta2 = ($nu/$rho)-1 Local $VII = tan($phi_prime)/(2*$rho*$nu) Local $VIII = (tan($phi_prime)/(24*$rho*$nu^3))*(5+3*tan($phi_prime)^2+$eta2-$eta2*9*(tan($phi_prime)^2)) Local $IX = (tan($phi_prime)/(720*$rho*$nu^5))*(61+(90*tan($phi_prime)^2)+45*tan($phi_prime)^4) Local $X = _sec($phi_prime)/$nu Local $XI = (_sec($phi_prime)/(6*$nu^3))*(($nu/$rho)+2*tan($phi_prime)^2) Local $XII = (_sec($phi_prime)/(120*$nu^5))*(5+(28*tan($phi_prime)^2)+24*tan($phi_prime)^4) Local $XIIA = (_sec($phi_prime)/(5040*$nu^7))*(61+(662*tan($phi_prime)^2)+(1320*tan($phi_prime)^4)+(720*tan($phi_prime)^6)) Local $phi = $phi_prime-($VII*($E-$E0)^2)+($VIII*($E-$E0)^4)-($IX*($E-$E0)^6) Local $lamb = $lam0+(($X*($E-$E0))-($XI*($E-$E0)^3)+($XII*($E-$E0)^5)-($XIIA*($E-$E0)^7)) $lat=$phi*$rad2deg $lon=$lamb*$rad2deg EndFunc Func _OSgrid_FromLatLon($lat, $lon, ByRef $easting, ByRef $northing) ; converts latitude-longitude coordinates, in decimal degrees ; into Ordnance Survey grid easting and norting, in meters ; http://www.dorcus.co.uk/carabus/ll_ngr.html Local $deg2rad=3.141592653589793238462643/180 Local $rad2deg=180/3.141592653589793238462643 Local $phi = $lat * $deg2rad; convert latitude to radians Local $lam = $lon * $deg2rad; convert longitude to radians Local $a = 6377563.396 ; semi-major ellipsoidal axis Local $b = 6356256.910 ; semi-minor ellipsoidal axis Local $N0= -100000 ; northing of true origin Local $E0= 400000 ; easting of true origin Local $F0= 0.9996012717 ; scale factor on central meridian Local $e2=($a^2-$b^2)/$a^2 ; squared ellipticity Local $phi0= 49 * $deg2rad ; latitude of true origin Local $lam0= -2 * $deg2rad ; longitude of true origin and central meridian Local $af0 = $a * $F0 Local $bf0 = $b * $F0 ; easting Local $slat2 = sin($phi) * sin($phi) Local $nu = $af0 / (sqrt(1 - ($e2 * ($slat2)))) Local $rho = ($nu * (1 - $e2)) / (1 - ($e2 * $slat2)) Local $eta2 = ($nu / $rho) - 1 Local $p = $lam - $lam0 Local $IV = $nu * cos($phi) Local $clat3 = (cos($phi))^3 Local $tlat2 = tan($phi) * tan($phi) Local $V = ($nu / 6) * $clat3 * (($nu / $rho) - $tlat2) Local $clat5 = (cos($phi))^5 Local $tlat4 = (tan($phi))^4 Local $VI = ($nu / 120) * $clat5 * ((5 - (18 * $tlat2)) + $tlat4 + (14 * $eta2) - (58 * $tlat2 * $eta2)) $easting = Round($e0 + ($p * $IV) + (($p^3) * $V) + (($p^5) * $VI),0) ; northing Local $n = ($af0 - $bf0) / ($af0 + $bf0) Local $M = _GetM($phi) Local $I = $M + ($n0) Local $II = ($nu / 2) * sin($phi) * cos($phi) Local $III = (($nu / 24) * sin($phi) * (cos($phi)^3)) * (5 - (tan($phi)^2) + (9 * $eta2)) Local $IIIA = (($nu / 720) * sin($phi) * $clat5) * (61 - (58 * $tlat2) + $tlat4) $northing = Round($I + (($p * $p) * $II) + (($p^4) * $III) + (($p^6) * $IIIA),0) EndFunc Func _GetM($phi_prime) Local $deg2rad=3.141592653589793238462643/180 Local $rad2deg=180/3.141592653589793238462643 Local $a = 6377563.396 ; semi-major ellipsoidal axis Local $b = 6356256.910 ; semi-minor ellipsoidal axis Local $F0= 0.9996012717 ; scale factor on central meridian Local $phi0= 49 * $deg2rad ; latitude of true origin Local $phi_diff=$phi_prime-$phi0 Local $phi_sum =$phi_prime+$phi0 Local $n_small =($a-$b)/($a+$b) Local $part1 =(1+$n_small+(5/4)*$n_small^2+(5/4)*$n_small^3)*$phi_diff Local $part2 =(3*$n_small+3*$n_small^2+(21/8)*$n_small^3)*sin($phi_diff)*cos($phi_sum) Local $part3 =((15/8)*$n_small^2+(15/8)*$n_small^3)*sin(2*$phi_diff)*cos(2*$phi_sum) Local $part4 =((35/24)*$n_small^3)*sin(3*$phi_diff)*cos(3*$phi_sum) Return $b*$F0*($part1-$part2+$part3-$part4) EndFunc Func _sec($theta) Return 1/cos($theta) EndFunc Func _OSNE2BNG($easting, $northing) ; produces OS grid reference letter codes ; http://www.dorcus.co.uk/carabus/ll_ngr.html Local $eX = $easting / 500000 Local $nX = $northing / 500000 Local $tmp = floor($eX)-5.0 * floor($nX)+17.0 $nX = 5 * ($nX - floor($nX)) $eX = 20 - 5.0 * floor($nX) + floor(5.0 * ($eX - floor($eX))) if $eX > 7.5 Then $eX+=1 if $tmp > 7.5 Then $tmp+=1 Return Chr($tmp + 65) & Chr($eX + 65) & " " & $easting & " " & $northing EndFunc #cs NB for Ireland, use a Modified Airy ellipsoid: Local $a = 6377340.189 Local $b = 6356034.447 Local $e0 = 200000 Local $n0 = 250000 Local $f0 = 1.000035 Local $e2 = 0.00667054015 Local $lam0 = -0.13962634015954636615389526147909 Local $phi0 = 0.93375114981696632365417456114141 And the last line of _OSNE2BNG becomes: Return Chr($tmp + 65) & Chr($eX + 65) & " " & $easting & " " & $northing For the Channel Islands, use the International 1924 ellipsoid: Local $a = 6378388.000 ; INT24 ED50 semi-major Local $b = 6356911.946 ; INT24 ED50 semi-minor Local $e0 = 500000 ; CI easting of false origin Local $n0 = 0 ; CI northing of false origin Local $f0 = 0.9996 ; INT24 ED50 scale factor on central meridian Local $e2 = 0.0067226700223333 ; INT24 ED50 eccentricity squared Local $lam0 = -0.0523598775598 ; CI false east Local $phi0 = 0 * $deg2rad ; CI false north Func _OSNE2BNG_ChannelIslands($easting, $northing) ; http://www.dorcus.co.uk/carabus/ll_ngr.html Local $eX = $easting / 500000 Local $nX = $northing / 500000 Local $tmp = floor($eX)-5.0 * floor($nX)+17.0 $nX = 5 * ($nX - floor($nX)) $eX = 20 - 5.0 * floor($nX) + floor(5.0 * ($eX - floor($eX))) if $eX > 7.5 Then $eX+=1 if $tmp > 7.5 Then $tmp+=1 If $northing>5500000 Then Return "WA " & StringLeft(String($easting),6) & " " & StringTrimLeft(String($northing),1) Else Return "WV " & StringLeft(String($easting),6) & " " & StringTrimLeft(String($northing),1) EndIf EndFunc #ce Enjoy.
    1 point
  6. Maybe you could tell us a little more about what kind of functions are is failing else it will be come a guessing game with off-the-wall answers llkeTD was kind enough to demonstrate already? Jos
    1 point
  7. @MrKris1224, Opening a new thread on the same topic that has been closed is not welcomed here. If you feel you were unjustly treated, your first recourse should have been to PM the moderator that closed your topic in the first place, explain why you feel it shouldn't have been closed, and waited for a response. None of us would just leave you in the dark without explaining why we did what we did and possibly even provide you a solution to get your question(s) answered in a different manner. Please do not open another thread on the subject at hand or anything resembling it until you've spoken with the moderator that closed your thread in the first place. If you do, I'm afraid you will no longer be a part of the forum. Have a good evening/morning.
    1 point
  8. Ever wanted to keep a copy of a video message you got (or sent) through Skype? It is actually not so hard to get it manually, but here is a script that does it automatically. Before you try it, please note: the script has been tested on Skype v.7.x, running on Windows 7, but can be easily modified to work with Skype versions for Windows 8.x (or so I read). I have no Windows 8.x machine, and do not intend to change the script to support it until further notice. the URLs found in the Skype database are dynamic, and get invalidated after a while (within the hour in my experience). To get valid URLs in the database, open Skype and play the video messages you want to download. Once it starts playing within Skype, the link should be valid again. Try running the script after that. if the script takes a while to start, it could be because it didn't find sqlite3.dll, and will download it. If you want it to start without delay, put a copy of sqlite3.dll where the script can find it, e.g. in the same folder as the script. if you have more than one Skype user saved under your profile folder (@UserProfileDir & "AppDataRoamingSkype"), the script will go through all of them. Once again, only valid links will be downloaded. DownloadSkypeVideoMessages.au3
    1 point
  9. @soledad: Try the modified version in post #4. There was an error. Itemcount was not removed.
    1 point
  10. MikahS

    File Encrypt Decrypt

    What's with all the hexadecimal?
    1 point
  11. LarsJ

    Automating Windows Explorer

    Here is a collection of small examples. Windows Explorer should be open before you run the examples. If you create shortcuts for the scripts, and copy the shortcuts to the desktop, you can run the examples and use Windows Explorer at the same time. For some of the examples you can select files or folders before you run the example. 1) GetCurrentFolder.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get current folder Local $pFolder = GetCurrentFolder(), $sFolder SHGetPathFromIDList( $pFolder, $sFolder ) MsgBox( 0, "Folder", $sFolder ) ; Free memory _WinAPI_CoTaskMemFree( $pFolder ) EndFunc 2) SetCurrentFolder.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Set current folder to desktop Local $pDesktop = _WinAPI_ShellGetSpecialFolderLocation( $CSIDL_DESKTOP ) SetCurrentFolder( $pDesktop, $SBSP_ABSOLUTE ) ; Free memory _WinAPI_CoTaskMemFree( $pDesktop ) EndFunc 3) CountItems.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Count files and folders MsgBox( 0, "Count files and folders", CountItems() ) ; Count selected files and folders MsgBox( 0, "Count selected files and folders", CountItems( True ) ) EndFunc 4) GetFiles.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFiles = GetFiles( False, True ) _ArrayDisplay( $aFiles, "All files" ) ; Get selected files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFiles = GetFiles( True, True ) _ArrayDisplay( $aFiles, "Selected files" ) EndFunc 5) GetFolders.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get all folders ;GetFolders( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFolders = GetFolders() _ArrayDisplay( $aFolders, "All folders" ) ; Get selected folders ;GetFolders( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFolders = GetFolders( True ) _ArrayDisplay( $aFolders, "Selected folders" ) EndFunc 6) SetSelectedItem.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Set second item selected SetSelectedItem( 1 ) EndFunc 7) GetSetIconView.au3 #include "Includes\AutomatingWindowsExplorer.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; Get other interfaces GetShellInterfaces() ; Get current icon view Local $view = GetIconView() Local $iView, $iSize If IsArray( $view ) Then ; OS > XP $iView = $view[0] ; Icon view $iSize = $view[1] ; Icon size If $iView <> $FVM_DETAILS Then ; Not details view SetIconView( $FVM_DETAILS, 16 ) ; Set details view ElseIf $iView <> $FVM_ICON Then ; Not icon view SetIconView( $FVM_ICON, 48 ) ; Set icon view EndIf Sleep( 3000 ) ; Wait 3 seconds SetIconView( $iView, $iSize ) ; Restore old view Else ; OS = XP $iView = $view If $iView <> $FVM_DETAILS Then ; Not details view SetIconView( $FVM_DETAILS ) ; Set details view ElseIf $iView <> $FVM_ICON Then ; Not icon view SetIconView( $FVM_ICON ) ; Set icon view EndIf Sleep( 3000 ) ; Wait 3 seconds SetIconView( $iView ) ; Restore old view EndIf EndFunc Zipfile The zip contains examples and necessary include files. Examples.7z
    1 point
  12. 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
  13. LarsJ

    The Shell Context Menu

    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
×
×
  • Create New...