perthg
asked on
Bitmap with InsertMenu
Hi,
I am using InsertMenu function to insert a menu item in the windows shell. Everything is working fine but how can I insert a bitmap to the left side of the menuItem text?
regards,
Partha
I am using InsertMenu function to insert a menu item in the windows shell. Everything is working fine but how can I insert a bitmap to the left side of the menuItem text?
regards,
Partha
hmm, sorry, it may be that i tell nonsens . . . just checking
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
seems you catch me soon in top 15 yearly, f68 ;-))
Don't worry meikl, i'm going on my vacation at the end of july and i'll stay 'out' for recharging 'til september :)))
And to catch you on top 15 overall will be very hard :)))
BTW me, you, rlilibby or any other on the top 15 it's the same, the most inportant is our knowladge sharing, somethig from i'm learning really more than what i'd ever thinked :))))
F68 ;-)
And to catch you on top 15 overall will be very hard :)))
BTW me, you, rlilibby or any other on the top 15 it's the same, the most inportant is our knowladge sharing, somethig from i'm learning really more than what i'd ever thinked :))))
F68 ;-)
>the most inportant is our knowladge sharing, somethig from i'm learning really more
>than what i'd ever thinked :))))
thats it
oops, sorry to be off topic
meikl ;-)
>than what i'd ever thinked :))))
thats it
oops, sorry to be off topic
meikl ;-)
Just to say 'sorry for meikl and F68 off topic comments' i'm posting a little gift to perthg and future surfer that will come here.
Suppose that you want to have a form with no title bar, customized sysmenu and still you want to show it right clicking everywhere in the form?
Well, here it comes...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
BtnAdd: TButton;
procedure BtnAddClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
myPic: TBitmap;
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure CreateParams(var Params: TCreateParams); override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
SC_MyMenuItem = WM_USER + 1;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType = SC_MyMenuItem then begin
ShowMessage('My system menu clicked!');
end else
inherited;
end;
procedure TForm1.BtnAddClick(Sender: TObject);
const
sMyMenuCaption='My n&ew system menu item';
var
SysMenu : HMenu;
MenuItemInfo : TMenuItemInfo;
begin
SysMenu := GetSystemMenu(Handle, FALSE);
InsertMenu(SysMenu,0, MF_STRING, SC_MyMenuItem, sMyMenuCaption); // this is like you already do
FillChar(MenuItemInfo,Size Of(TMenuIt emInfo), #0);
MenuItemInfo.cbSize := SizeOf(TMenuItemInfo);
MenuItemInfo.fMask := MIIM_BITMAP; //here we set the mask to MII_Bitmap type
menuiteminfo.hbmpItem := myPic.Handle; //assign the HBitmap
SetMenuItemInfo(SysMenu, SC_MyMenuItem, FALSE, MenuItemInfo); // and set the menuitem info
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
self.BorderStyle := bsSizeable;
myPic := TBitmap.Create; //but you could also get bitmaps handle from a timagelist
myPic.LoadFromFile('c:\clo sebutton.b mp');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
myPic.Free;
end;
procedure TForm1.FormMouseDown(Sende r: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
hMenuHandle: hMENU;
hMenuItem: dWord;
p : TPoint;
begin
GetCursorPOs(p);
if ssright in shift then begin
hMenuHandle := GetSystemMenu(Handle, False);
hMenuItem := LongWord(Windows.TrackPopu pMenu(hMen uHandle, TPM_LEFTBUTTON or TPM_RIGHTBUTTON or TPM_RETURNCMD, p.X, p.Y, 0, Handle, nil));
if hMenuItem > 0 then SendMessage(Handle, WM_SYSCOMMAND, hMenuItem, 0);
end;
end;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do //let's remove the title bar
Style:=(Style or WS_POPUP or WS_SYSMENU or WS_THICKFRAME) and not WS_DLGFRAME;
end;
end.
F68 ;-)
Suppose that you want to have a form with no title bar, customized sysmenu and still you want to show it right clicking everywhere in the form?
Well, here it comes...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
BtnAdd: TButton;
procedure BtnAddClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
myPic: TBitmap;
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure CreateParams(var Params: TCreateParams); override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
const
SC_MyMenuItem = WM_USER + 1;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType = SC_MyMenuItem then begin
ShowMessage('My system menu clicked!');
end else
inherited;
end;
procedure TForm1.BtnAddClick(Sender:
const
sMyMenuCaption='My n&ew system menu item';
var
SysMenu : HMenu;
MenuItemInfo : TMenuItemInfo;
begin
SysMenu := GetSystemMenu(Handle, FALSE);
InsertMenu(SysMenu,0, MF_STRING, SC_MyMenuItem, sMyMenuCaption); // this is like you already do
FillChar(MenuItemInfo,Size
MenuItemInfo.cbSize := SizeOf(TMenuItemInfo);
MenuItemInfo.fMask := MIIM_BITMAP; //here we set the mask to MII_Bitmap type
menuiteminfo.hbmpItem := myPic.Handle; //assign the HBitmap
SetMenuItemInfo(SysMenu, SC_MyMenuItem, FALSE, MenuItemInfo); // and set the menuitem info
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
self.BorderStyle := bsSizeable;
myPic := TBitmap.Create; //but you could also get bitmaps handle from a timagelist
myPic.LoadFromFile('c:\clo
end;
procedure TForm1.FormDestroy(Sender:
begin
myPic.Free;
end;
procedure TForm1.FormMouseDown(Sende
Shift: TShiftState; X, Y: Integer);
var
hMenuHandle: hMENU;
hMenuItem: dWord;
p : TPoint;
begin
GetCursorPOs(p);
if ssright in shift then begin
hMenuHandle := GetSystemMenu(Handle, False);
hMenuItem := LongWord(Windows.TrackPopu
if hMenuItem > 0 then SendMessage(Handle, WM_SYSCOMMAND, hMenuItem, 0);
end;
end;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do //let's remove the title bar
Style:=(Style or WS_POPUP or WS_SYSMENU or WS_THICKFRAME) and not WS_DLGFRAME;
end;
end.
F68 ;-)
Another OT posting...
Hi F68 and meikl... seems like both of you are advancing well in your points, while I'm lagging behind... sigh, too busy with work lately, not much time to frequent EE... glad you have time to go for vacation, F68 (2 month vacation? wow, I can live with that!)
DragonSlayer
Hi F68 and meikl... seems like both of you are advancing well in your points, while I'm lagging behind... sigh, too busy with work lately, not much time to frequent EE... glad you have time to go for vacation, F68 (2 month vacation? wow, I can live with that!)
DragonSlayer
because with insertmenu you have to decide between String and Bitmap
see win-api-helpfile
meikl ;-)