We help IT Professionals succeed at work.

procedures

hugh34
hugh34 asked
on
i have the following code and would like to know how i can put it into a procedure in which i can call it

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

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

at the moment this code looks for c:\windows\logo.bmp but i have converted it to look for a file in a resource file

eg

NewImage.Bitmap.LoadFromResourceName(hInstance,'PIC2');

what i would like is for the code above to be put into a procedure that i can call in a button click so with a different button i can change the start button bitmap.

eg  procedure StartButtonChange


and on the button click

startButtonChange := LoadFromResourceName(hInstance,'PIC2');

i hope you can understand this!!!



Comment
Watch Question

Commented:
How this.. using properties to change the Start Button Image.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    procedure FormCreate(Sender: TObject);
  private    { Private declarations }
    Function GetStartButtonImage:TPicture;
    Procedure SetStartButtonImage(Pic:TPicture);
  public     { Public declarations }
    Property StartButtonImage:TPicture
      Read GetStartButtonImage
      Write SetStartButtonImage;
  end;
var
  Form1: TForm1;

implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin //Example of Use..
  Image2.Picture.LoadFromFile('C:\MCP.Bmp');
  Image1.Picture := StartButtonImage;
  StartButtonImage := Image2.Picture;
end;

//Returns the Image of the Start Button
Function TForm1.GetStartButtonImage:TPicture;
Var
 SB_hWnd:HWND; //Handle to Start Button
Begin
  SB_hWnd := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0,'Button', nil);
  GetStartButtonImage := TPicture(SendMessage(SB_hWnd, BM_GETIMAGE, 0, 0));
End;

//Sets the Image of the Start Button
Procedure TForm1.SetStartButtonImage(Pic:TPicture);
Var
 SB_hWnd:HWND; //Handle to Start Button
Begin
  SB_hWnd := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0,'Button', nil);
  SendMessage(SB_hWnd, BM_SETIMAGE, 0, Pic.Handle);
End;
end.

Another idea would be to encapsulate this and other methods pertaining to the start button in its own class.

Good Luck,
RH.

Commented:
I don't think that this stuff will work in NT based systems...

Author

Commented:
there seems to be a problem with this line

SendMessage(SB_hWnd, BM_SETIMAGE, 0, Pic.Handle);


undeclared identifier Handle!
Commented:
Opps it's Pic.Bitmap.Handle

Sorry,
RH.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.