Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile EXE '#Win 8.03#
#Register NONE
#Dim ALL
#Include "Win32Api.Inc" '#2005-01-14#
$AppName = "Windows Explorer - Right-click"
%LabelCommand = 101
%ButtonDrive = 201
%ButtonFolder = 202
%ButtonFile = 203
%ButtonExe = 204
$ButtonDriveAdd = "Add right-click to ""Windows Explorer"" For drives"
$ButtonDriveClean = "Clean registry for ""Windows Explorer"" with drives"
$ButtonFolderAdd = "Add right-click to ""Windows Explorer"" For folders"
$ButtonFolderClean = "Clean registry for ""Windows Explorer"" with folders"
$ButtonFileAdd = "Add right-click to ""Windows Explorer"" For files"
$ButtonFileClean = "Clean registry for ""Windows Explorer"" with files"
$ButtonExeAdd = "Add right-click to ""Windows Explorer"" For .Exe files"
$ButtonExeClean = "Clean registry for ""Windows Explorer"" with .Exe files"
'______________________________________________________________________________
Function ExeName() AS String
Local FileName As AsciiZ * %Max_Path
Local FileNameLen As Long
FileNameLen = GetModuleFileName(ByVal %NULL, FileName, %Max_Path)
Function = Left$(FileName, FileNameLen)
End Function
'______________________________________________________________________________
CallBack Function DlgProc
Local TextAdd AS String
Local TextClean AS String
Local KeyPrefix AS String
Local hKey AS DWord
Local RetVal As Long
Local szKeyValue As AsciiZ * %MAX_PATH
Local szKeyData As AsciiZ * %MAX_PATH
Select Case Cbmsg
Case %WM_COMMAND
Select Case LoWrd(Cbwparam)
Case %ButtonDrive : KeyPrefix = "Drive"
TextAdd = $ButtonDriveAdd
TextClean = $ButtonDriveClean
GoSub RegSet
Case %ButtonFolder : KeyPrefix = "Folder"
TextAdd = $ButtonFolderAdd
TextClean = $ButtonFolderClean
GoSub RegSet
Case %ButtonFile : KeyPrefix = "*" 'All files
TextAdd = $ButtonFileAdd
TextClean = $ButtonFileClean
GoSub RegSet
Case %ButtonExe : KeyPrefix = "exefile"
TextAdd = $ButtonExeAdd
TextClean = $ButtonExeClean
GoSub RegSet
End Select
End Select
Exit Function
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RegSet:
If RegCreateKeyEx(%HKEY_CLASSES_ROOT, KeyPrefix & "\Shell\" & $AppName & "\Command", _
ByVal %NULL, "", %REG_OPTION_NON_VOLATILE, %KEY_ALL_ACCESS, _
ByVal %NULL, hKey, RetVal) = %ERROR_SUCCESS Then
If Retval = %REG_CREATED_NEW_KEY Then 'Nothing found so create it
szKeyValue = ""
szKeyData = $DQ & ExeName & $DQ & " %L"
'%L : Long path, ex: C:\Program Files
'%1 : Short path, ex: c:\progra~1
'%I : Unique ID, need /IDLIST as a flag
'Also any environment variables as %?SystemRoot% or
'%?ProgramFiles% or %UserProfile% or %AllUsersProfile%
RegSetValueEx hKey, szKeyValue, ByVal %NULL, %REG_SZ, szKeyData, Len(szKeyData)
Control Set Text Cbhndl, LoWrd(Cbwparam), TextClean
Else 'Retval = %REG_OPENED_EXISTING_KEY, already exist so delete it
RegDeleteKey %HKEY_CLASSES_ROOT, KeyPrefix & "\shell\" & $AppName & "\command"
RegDeleteKey %HKEY_CLASSES_ROOT, KeyPrefix & "\shell\" & $AppName
Control Set Text Cbhndl, LoWrd(Cbwparam), TextAdd
End If
End If
RegCloseKey hKey
Return
'Also: AllFilesystemObjects * Directory exefile drvfile fndfile
'Also: folder hlpfile inifile lnkfile txtfile regfile wrifile
End Function
'______________________________________________________________________________
Function regKeyExist(sKeyName AS String)As Long
Local hKey AS DWord
If RegOpenKeyEx(%HKEY_CLASSES_ROOT, ByVal StrPTR(sKeyName), _
ByVal %NULL, %KEY_READ, hKey)= %ERROR_SUCCESS Then
RegCloseKey(hKey)
Function = 1 'Key exist
End If
End Function
'______________________________________________________________________________
Function PBMain()
Local hDlg AS DWord
Local Buffer AS String
Dialog New %HWND_DESKTOP, $AppName, , , 200, 100, %WS_CAPTION Or _
%WS_MINIMIZEBOX Or %WS_SYSMENU, 0 TO hDlg
SetClassLong hDlg, %GCL_HICON, LoadIcon(ByVal %NULL, ByVal %IDI_INFORMATION)
Buffer = IIF$(regKeyExist("Drive\Shell\" & $AppName & "\Command"), _
$ButtonDriveClean, $ButtonDriveAdd)
Control Add Button, hDlg, %ButtonDrive, Buffer, 5, 5, 190, 12
Buffer = IIF$(regKeyExist("Folder\Shell\" & $AppName & "\Command"), _
$ButtonFolderClean, $ButtonFolderAdd)
Control Add Button, hDlg, %ButtonFolder, Buffer, 5, 25, 190, 12
Buffer = IIF$(regKeyExist("*\Shell\" & $AppName & "\Command"), _
$ButtonFileClean, $ButtonFileAdd)
Control Add Button, hDlg, %ButtonFile, Buffer, 5, 45, 190, 12
Buffer = IIF$(regKeyExist("exefile\Shell\" & $AppName & "\Command"), _
$ButtonExeClean, $ButtonExeAdd)
Control Add Button, hDlg, %ButtonExe, Buffer, 5, 65, 190, 12
Control Add Label, hDlg, %LabelCommand, "%L = " & Command$, 5, 83, 190, 17
Dialog Show Modal hDlg Call DlgProc
End Function
'________________________________________
'gbs_00568
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm