zoukankan      html  css  js  c++  java
  • Delphi在系统菜单中添加菜单项

    unit dy219;
    
    interface
    
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs;
    
    type
    TForm1 = class(TForm)
      procedure FormCreate(Sender: TObject);
    private
      procedure sysmenu(var msg: twmmenuselect);message wm_syscommand;
    { Private declarations }
    public
    { Public declarations }
    end;
    
    var
    Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
    i: integer;
    begin
    i := getsystemmenu(handle,false);
    appendmenu(i,mf_separator,0,nil);
    appendmenu(i,mf_string,100,'我的菜单(&E)');
    end;
    
    procedure TForm1.sysmenu(var msg: twmmenuselect);
    begin
    if msg.IDItem = 100 then
      showmessage('您选择了自己添加的菜单!')
    else
      inherited;
    end;
    
    end.
    复制代码

    API函数

    function GetSystemMenu(hWnd:HWND;bRevert:BOOL):HMENU;stdcall;

      参数说明:

      hWnd: 所要取得系统菜单句柄的目标窗口句柄。

      bRevert:是否修改原始菜单。

      返回一个HMENU型的菜单句柄。

      通过GetSystemMenu得到句柄后可以使用AppendMenu函数为系统菜单增加一个菜单项,该函数原型为:

    function AppendMenu(hMenu:HMENU;uFlags,uIDNewItem:UNIT;lpNewItem:Pchar):BOOL;stdcall;

      参数说明:

      hMenu: 用GetSystemMenu函数得到的菜单句柄。

      uFlag,uIDNewItem:菜单唯一标志,弹出菜单唯一标志。

      lpNewItem:菜单的类型。

    容易出现问题:

      缺少代码 message wm_syscommand;这句代码的主要作用是:A window receives this message when the user chooses a commond from the window menu.而如果注释了inherited ,则所有系统菜单都不能用。

    http://blog.csdn.net/zang141588761/article/details/51992368

  • 相关阅读:
    select 标签的数据绑定
    JQ选择器-选择符合条件的元素,获取对应关系元素
    Velocity中判断表达式是不是为空
    重要的serialVersionUID
    编译nginx的时候报错 需要安装PCRE
    Mac 允许安装任何来源的app
    Charles
    Excel_日期和时间函数、EDATE、EOMONTH
    项目9: 成绩中国式排名(难度:中等)
    Mysql:IFNULL的使用说明
  • 原文地址:https://www.cnblogs.com/findumars/p/6711258.html
Copyright © 2011-2022 走看看