Change the Window's Start button bitmap  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 18/09/99

Tip accessed 537 times

 



 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;



And in the OnDestroy of the form, we put:


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





Updated at 05/09/99
For insistence of Delphin that asked us through 4, 5 or 6 emails, messages here in the trick and in ' Requests your tip' (that insistence:) I have added the LockWindoUpdate so that it doesn't fade the new bitmap that we have put in the button.



New update (Delphin is really insistent...) :) at 07/09/99

This time the trick is complete: the bitmap is changed, and the button press it in the same manner as the original...

  • We need several global variables, so, we declare them in the var of the form:


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



  • Now, we put this code in the OnCreate event of the 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;
    



  • And this other in the OnDestroy:


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



    And it is Already. (I hate the Start button!)