Cambiar el bitmap del boton de Inicio de Windows  

Enviado Por: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Fecha: 18/09/99

Truco accedido 127 veces

 



 procedure TForm1.Button1Click(Sender: TObject);
 var
   StartButton : hWnd;
   MyRect      : TRect;
   MyCanvas    : TCanvas;
 begin
   { get the startbutton handle }
   { Obtenemos el handle al boton de Inicio}
   StartButton := FindWindowEx(FindWindow(
                                 'Shell_TrayWnd',
                                 nil),
                               0,
                               'Button',
                               nil);
   MyCanvas := TCanvas.Create;
   try
     MyCanvas.Handle := GetWindowDC(StartButton);

     { set canvas font and brush }
     MyCanvas.Brush.Color := clRed;
     MyCanvas.Font.Name   := 'Arial';
     MyCanvas.Font.Size   := 10;
     MyCanvas.Font.Color  := clYellow;
     MyCanvas.Font.Style  := [fsItalic, fsBold];

     { get startbutton clientrect }
     Windows.GetClientRect(StartButton,MyRect);

     { over write the startbutton }
     { Sobreescribe el boton inicio }
     MyCanvas.FillRect(MyRect);

     { add your text to the startbutton }
     { Añadimos un texto al boton }
     Windows.DrawText(MyCanvas.Handle,
                      'HOLA',
                      -1,
                      MyRect,
                      DT_CENTER or
                      DT_VCENTER or
                      DT_SINGLELINE);

     { give the button the appearance of a button }
     { Damos al canvas la apariencia de un boton }
     DrawEdge(MyCanvas.Handle,
              MyRect,
              EDGE_RAISED,
              BF_RECT);
   finally
     { free the created DC }
     {libera el DC creado}
     ReleaseDC(StartButton,
               MyCanvas.Handle);

     { free the temp canvas }
     {Liberamoa el canvas temporal}
     MyCanvas.Free;
   end;
   LockWindowUpdate(StartButton);
 end;



Y en el OnDestroy de la form ponemos:


 procedure TForm1.FormDestroy(Sender: TObject);
 begin
   LockWindowUpdate(0);
 end;





Actualizado el 05/09/99
Por insistencia de Delphin, que nos preguntaba a traves de 4, 5 ó 6 emails, mensajes aqui en el truco y en 'Pide tu truco' (que insistencia:) he añadido el LockWindoUpdate para que no se borre el nuevo bitmap que hemos puesto en el boton.



Nueva actualización (Delphin es realmente insistente...) :) el 07/09/99

Esta vez el truco es completo: se cambia el bitmap, y el boton se hunde igual que el original...

  • Necesitamos unas variables globales, así que las definiremos en el var del form:


     var
       Form1: TForm1;
       StartButton : hWnd;
       OldBitmap   : THandle;
       NewImage : TPicture;
    



  • Ahora ponemos esto en el evento OnCreate de la Form:


     procedure TForm1.FormCreate(Sender: TObject);
     begin
       NewImage:=TPicture.create;
       NewImage.LoadFromFile('C:\Delphi3\Images\DEFAULT\OutOpen.BMP');
       StartButton := FindWindowEx(FindWindow(
                                     'Shell_TrayWnd',
                                     nil),
                                   0,
                                   'Button',
                                   nil);
       OldBitmap:=SendMessage(StartButton,BM_SetImage,0,NewImage.Bitmap.Handle);
     end;
    



  • Y este otro código en el OnDestroy:


     procedure TForm1.FormDestroy(Sender: TObject);
     begin
       SendMessage(StartButton,BM_SetImage,0,OldBitmap);
       NewImage.Free;
     end;
    



    Y Ya está. (¡Odio el boton de Inicio!)