delphi 新增系統選單,點選新選單沒有反應的問題
阿新 • • 發佈:2019-02-17
program Psysmenu; uses Forms, Sysmenu in '\SYSMENU.PAS' {Form1}; {$R *.RES} begin Application.CreateForm(TForm1, Form1); Application.Run; end. unit Sysmenu; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private procedure user_sysmenu(var msg:twmmenuselect); message wm_syscommand; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.user_sysmenu(var msg:TWMMENUSELECT); begin if msg.iditem=100 then showmessage(' 響應系統選單!') { 也 可 以setwindowpos()來實現處於最前端功能} 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; end.
//出錯的主要原因是:缺少一句程式碼 message wm_syscommand;
//這句程式碼的主要作用是:A window receives this message when the user chooses a commond from the window menu.
//而如果註釋了inherited ,則所有系統選單都不能用。