procedure user_sysmenu(var msg: twmmenuselect); message wm_syscommand;procedure TForm1.User_Sysmenu(var msg: TWMMENUSELECT); begin if Msg.Iditem = 100 then ShowMessage('响应系统菜单!') else inherited; {作缺省处理,必须调用这一过程} end;procedure TForm1.FormCreate(Sender: TObject); var hMenu: integer; begin hMenu := GetSystemMenu(Handle, False); {获取系统菜单句柄} AppendMenu(hmenu, MF_SEPARATOR, 0, nil); AppendMenu(hmenu, MF_STRING, 100, '加入系统菜单'); {加入用户菜单} end;
//全局模块中const //自定义消息,关于菜单 CM_MSG_ABOUT = WM_USER+400; SAbout = '关于(&A)...';function AddAboutMenu(Handle:THandle):boolean; //增加关于菜单 var SysMenu:HMenu; i:integer; s:array[0..225] of char; begin SysMenu:=GetSystemMenu(Handle,False); i:=GetMenuItemCount(SysMenu)-1; InsertMenu(SysMenu,i,MF_BYPOSITION+MF_SEPARATOR,0,nil); InsertMenu(SysMenu,i,MF_BYPOSITION,CM_MSG_ABOUT,PChar(SAbout)); GetMenuString(SysMenu,i-1,s,255,MF_BYPOSITION); if s[0]<>#0 then InsertMenu(SysMenu,i,MF_BYPOSITION+MF_SEPARATOR,0,nil); result:=true; end;function ShowAbout():boolean; //显示关于窗口 var hIcon,hInst:integer; begin hInst:=getwindowword(application.Handle,GWL_HINSTANCE); hIcon:=ExtractIcon(hInst,pchar(application.exename),0); Result:=boolean(shellabout(application.Handle, pchar(SAppName),pchar(SAppName+sappver),hicon)); end;//工程主窗体中 procedure TMDIMainForm.AppMessageHandler(var Msg:TMsg;var Handled:boolean); //拦截应用程序的消息 case Msg.wParam of CM_MSG_ABOUT: //自定义消息,显示关于菜单 ShowAbout; end; Handled:=false; end;//工程文件中 Application.OnMessage := MDIMainForm.AppMessageHandler; AddAboutMenu(application.Handle); Application.CreateForm(TMDIMainForm, MDIMainForm); Application.Run;
转贴:关于Delphi程序在任务栏按钮的菜单问题,以前看过一个网友化了好大力气来实现他,但是有没有记录下他说的做法,不过我昨天用一个很轻松的方法实现了。我们知道,Delphi编写的程序,在任务栏的按钮上面的菜单,只有几项:而一般的Windows的程序,菜单上面有更多的项目:虽然使用的时候没有什么关系,但始终是不舒服!那么能不能把Delphi编写的程序的菜单也改成和其他程序一样呢?当然可以!方法如下:首先,重载主窗体的CreateParams,修改如下:procedure TFrmModal.CreateParams(var Para: TCreateParams);begin inherited; Para.WndParent := GetDesktopWindow;end;然后在主窗体的OnCreate中添加如下代码:with Application do SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);OK,按F9运行你的程序看看?:-)。注意,一定要对主窗体进行上面的操作哦。BUG:感谢stanely发现这个BUG:最小化只是最小化application这个窗体,应用程序主窗体没反应阿!解决方法,拦截WM_SYSCOMMAND消息:procedure TFrmMain.WMSysCommand(var msg: TMessage);begin if msg.WParam = SC_MINIMIZE then Self.WindowState := wsMinimized else inherited;end;
回答也太快了吧。还想过来删贴呢。我也找到了。。加一个TApplicationEvents组件procedure TForm1.FormCreate(Sender: TObject); begin appendmenu(getsystemmenu(application.handle,false),mf_string,$0a01,'about...');end;procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin if Msg.message=wm_syscommand then begin if loword(Msg.wparam)=$0a01 then showmessage('yes'); end; handled:=false;end;
begin
if Msg.Iditem = 100 then
ShowMessage('响应系统菜单!')
else
inherited; {作缺省处理,必须调用这一过程}
end;procedure TForm1.FormCreate(Sender: TObject);
var
hMenu: integer;
begin
hMenu := GetSystemMenu(Handle, False); {获取系统菜单句柄} AppendMenu(hmenu, MF_SEPARATOR, 0, nil);
AppendMenu(hmenu, MF_STRING, 100, '加入系统菜单'); {加入用户菜单}
end;
//自定义消息,关于菜单
CM_MSG_ABOUT = WM_USER+400;
SAbout = '关于(&A)...';function AddAboutMenu(Handle:THandle):boolean;
//增加关于菜单
var
SysMenu:HMenu;
i:integer;
s:array[0..225] of char;
begin
SysMenu:=GetSystemMenu(Handle,False);
i:=GetMenuItemCount(SysMenu)-1;
InsertMenu(SysMenu,i,MF_BYPOSITION+MF_SEPARATOR,0,nil);
InsertMenu(SysMenu,i,MF_BYPOSITION,CM_MSG_ABOUT,PChar(SAbout));
GetMenuString(SysMenu,i-1,s,255,MF_BYPOSITION);
if s[0]<>#0 then
InsertMenu(SysMenu,i,MF_BYPOSITION+MF_SEPARATOR,0,nil);
result:=true;
end;function ShowAbout():boolean;
//显示关于窗口
var
hIcon,hInst:integer;
begin
hInst:=getwindowword(application.Handle,GWL_HINSTANCE);
hIcon:=ExtractIcon(hInst,pchar(application.exename),0);
Result:=boolean(shellabout(application.Handle,
pchar(SAppName),pchar(SAppName+sappver),hicon));
end;//工程主窗体中
procedure TMDIMainForm.AppMessageHandler(var Msg:TMsg;var Handled:boolean);
//拦截应用程序的消息
case Msg.wParam of
CM_MSG_ABOUT: //自定义消息,显示关于菜单
ShowAbout;
end;
Handled:=false;
end;//工程文件中
Application.OnMessage := MDIMainForm.AppMessageHandler;
AddAboutMenu(application.Handle);
Application.CreateForm(TMDIMainForm, MDIMainForm);
Application.Run;
begin appendmenu(getsystemmenu(application.handle,false),mf_string,$0a01,'about...');end;procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin if Msg.message=wm_syscommand then
begin
if loword(Msg.wparam)=$0a01 then
showmessage('yes');
end;
handled:=false;end;