public static void UAC_EnableElevateIcon(System.Windows.Forms.Button button)
{
const uint BCM_SETSHIELD = 0x0000160C;
if (button == null)
return;
button.Image = null;
button.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
button.FlatStyle = System.Windows.Forms.FlatStyle.System;
// Send the BCM_SETSHIELD message to the button control
SendMessage(new HandleRef(button, button.Handle),
BCM_SETSHIELD, IntPtr.Zero, new IntPtr(1));
}
Remarque :
Ce snippet appel la fonction SendMessage, voici sa déclaration:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
Public Shared Sub UAC_EnableElevateIcon(ByVal button As System.Windows.Forms.Button)
Const BCM_SETSHIELD As UInteger = 5644
If button Is Nothing Then
Return
End If
button.Image = Nothing
button.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
button.FlatStyle = System.Windows.Forms.FlatStyle.System
' Send the BCM_SETSHIELD message to the button control
SendMessage(New HandleRef(button, button.Handle), BCM_SETSHIELD, IntPtr.Zero, New IntPtr(1))
End Sub
Remarque :
'Ce snippet appel la fonction SendMessage, voici sa déclaration:
_
Shared Function SendMessage(ByVal hWnd As HandleRef, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
const
{ Constante à envoyer au bouton pour afficher l'icône }
BCM_SETSHIELD = 5644;
function SetUACShield(Button: TButton; pSet: Boolean): Boolean;
begin
{ Si le bouton existe, on lui envoie le message BCM_SETSHIELD avec comme lParam 0 pour retirer l'icône et 1 pour l'afficher }
if Assigned(Button) then Result := (SendMessage(Button.Handle, BCM_SETSHIELD, 0, Integer(pSet)) = 1);
end;
Remarque :
- Passez pSet = True pour afficher l'icône, pSet= False sinon.
- La fonction renvoie True si tout s'est bien passé, False sinon.
- Les thèmes Vista doivent être activés et votre application doit disposer d'un manifeste de thème valide.