Advertisement
3DotDev

Ajouter menu contextuel au clic droit du bureau

Jan 3rd, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.86 KB | None | 0 0
  1. Imports Microsoft.Win32
  2. Imports System.IO
  3. Friend NotInheritable Class Cls_RightClic
  4.  
  5.     Friend Shared Sub Register(fileType$, shellKeyName$, menuText$, menuCommand$, Optional ByVal Arg$ = "")
  6.         Try
  7.             Dim regPath = String.Format("{0}\shell\{1}", fileType, shellKeyName)
  8.             Dim newPath = menuCommand.Replace(".EXE", New FileInfo(menuCommand).Extension.ToLower)
  9.             Using key = Registry.ClassesRoot.CreateSubKey(regPath)
  10.                 key.SetValue(Nothing, menuText)
  11.                 key.SetValue("Icon", newPath & ",0")
  12.             End Using
  13.             Using key = Registry.ClassesRoot.CreateSubKey(String.Format("{0}\command", regPath))
  14.                 key.SetValue(Nothing, newPath & Arg)
  15.             End Using
  16.         Catch ex As Exception
  17.             MsgBox("Error : Cls_RightClic Register : " & ex.ToString)
  18.         End Try
  19.  
  20.     End Sub
  21.  
  22.     Friend Shared Sub Unregister(fileType$, shellKeyName$)
  23.         Try
  24.             Dim regPath = String.Format("{0}\shell\{1}", fileType, shellKeyName)
  25.             If Not Registry.ClassesRoot.OpenSubKey(regPath, True) Is Nothing Then
  26.                 Registry.ClassesRoot.DeleteSubKeyTree(regPath)
  27.             End If
  28.         Catch ex As Exception
  29.             MsgBox("Error : Cls_RightClic UnRegister " & ex.ToString)
  30.         End Try
  31.     End Sub
  32. End Class
  33.  
  34. '############### COMMENT L'UTILISER
  35.  
  36. '1- Ajoutez une checkbox à votre projet
  37. '2- Entrez dans l'évènement "CheckedChanged" et saisir ceci :
  38.  
  39.   Private Sub ChbDesktopRightClic_CheckedChanged(sender As Object) Handles ChbDesktopRightClic.CheckedChanged
  40.         If ChbDesktopRightClic.Checked Then
  41.             Cls_RightClic.Register("DesktopBackground", "DNR", "Ouvrir <LE NOM DE VOTRE PROGRAMME>", Application.ExecutablePath)
  42.         Else
  43.             Cls_RightClic.Unregister("DesktopBackground", "DNR")
  44.         End If
  45.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement