Не добавляется пункт в контекстное меню проводника

Раздел посвящен программированию с использованием Power Basic.
jangle
Википедик
Википедик
Аватара пользователя
 
Сообщения: 3013
Зарегистрирован: 03.06.2005 (Пт) 12:02
Откуда: Нидерланды

Не добавляется пункт в контекстное меню проводника

Сообщение jangle » 25.07.2007 (Ср) 11:05

Вот такой код, для всех типов файлов, можно добавить пункт меню, а конкретно для .vbp файлов не получается, в чем проблема? Никак не могу понять



Код: Выделить всё
#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 .vbp files"
$ButtonExeClean    = "Clean registry for ""Windows Explorer"" with .vbp 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  = ".vbp"
                            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(".vbp\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       

jangle
Википедик
Википедик
Аватара пользователя
 
Сообщения: 3013
Зарегистрирован: 03.06.2005 (Пт) 12:02
Откуда: Нидерланды

Сообщение jangle » 26.07.2007 (Чт) 8:41

Докопался наконец в чем проблема, информация добавлялась не в ту ветку реестра, нужно не в ".vbp" а в "VisualBasic.Project", вот такой код работает правильно:

Код: Выделить всё
#Compile Exe '#Win 8.03#
#Register None
#Dim All
#Include "Win32Api.Inc" 

$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 .vbp files"
$ButtonExeClean    = "Clean registry for ""Windows Explorer"" with .vbp 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  = "VisualBasic.Project"
                            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"
     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
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("VisualBasic.Project\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


Вернуться в Power Basic

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1

    TopList