Alt+F4(100分)

  • 主题发起人 主题发起人 changku
  • 开始时间 开始时间
C

changku

Unregistered / Unconfirmed
GUEST, unregistred user!
我怎样才能让Alt+F4不丐作用呢?
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; Button3: TButton;<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button3Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMHotKey(var Message: TWMHotkey); message wm_hotkey;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br><br>procedure TForm1.WMHotKey(var Message: TWMHotkey);<br>begin<br>&nbsp;case Message.HotKey of<br>&nbsp; &nbsp;1: showmessage('1');<br>&nbsp;else<br>&nbsp; &nbsp;Showmessage(inttostr(message.HotKey));<br>&nbsp;end;<br>end;<br><br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp;RegisterHotKey(handle,1,MOD_ALT ,VK_F4); <br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>&nbsp;UnregisterHotKey(handle,1);<br>end;<br><br>end.
 
hook<br><br>或<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, AppEvnts, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; CheckBox1: TCheckBox;<br>&nbsp; &nbsp; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br>&nbsp;CanClose:=not CheckBox1.Checked;<br>end;<br><br>end.<br><br>object Form1: TForm1<br>&nbsp; Left = 192<br>&nbsp; Top = 107<br>&nbsp; Width = 544<br>&nbsp; Height = 375<br>&nbsp; Caption = 'Form1'<br>&nbsp; Color = clBtnFace<br>&nbsp; Font.Charset = DEFAULT_CHARSET<br>&nbsp; Font.Color = clWindowText<br>&nbsp; Font.Height = -11<br>&nbsp; Font.Name = 'MS Sans Serif'<br>&nbsp; Font.Style = []<br>&nbsp; OldCreateOrder = False<br>&nbsp; OnCloseQuery = FormCloseQuery<br>&nbsp; PixelsPerInch = 96<br>&nbsp; TextHeight = 13<br>&nbsp; object CheckBox1: TCheckBox<br>&nbsp; &nbsp; Left = 128<br>&nbsp; &nbsp; Top = 112<br>&nbsp; &nbsp; Width = 97<br>&nbsp; &nbsp; Height = 17<br>&nbsp; &nbsp; Caption = '不能关闭'<br>&nbsp; &nbsp; TabOrder = 0<br>&nbsp; end<br>end<br><br><br>
 
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>var<br>&nbsp;akey:Integer;<br>&nbsp;iRtn:Shortint;<br>begin<br>&nbsp;aKey := VK_MENU;<br>&nbsp;iRtn := GetKeyState(akey);<br>&nbsp;if (iRtn And $80) &lt;&gt; 0 then<br>&nbsp;begin<br>&nbsp; &nbsp;aKey := VK_F4;<br>&nbsp; &nbsp;iRtn := GetKeyState(akey);<br>&nbsp; &nbsp;if (iRtn And $80) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp;CanClose:=False;<br>&nbsp;end;<br>end;<br>这样可以屏蔽Alt+F4,同时允许点击关闭按钮。<br>/////////消息<br>procedure ON_WM_CLOSE(var m:TMessage);message WM_CLOSE;<br>procedure TForm1.ON_WM_CLOSE(var m:TMessage);<br>begin<br>//不干任何事<br>end;<br><br><br>
 
很简单的问题不要搞复杂话了,<br>在窗口上加个ActionList,双击它,创建一个Action<br>然后在这个Action 的ShortCut属性上写上alt+f4<br>编辑这个Action的Execute事件<br>procedure TForm1.Action1Execute(Sender: TObject);<br>begin<br>//<br>end;<br>alt+f4就没有效果了<br>你还可以在事件中写其它的处理代码,<br><br>
 
木子的方法很简单,小生怎么没有想到。:(
 
木子的方法太好了!
 
以上方法我试了一下都不行呀<br>是不是有些地主各位高手没讲明白呢<br>
 
procedure TForm1.Action1Execute(Sender: TObject);<br>begin<br>//<br>end;<br><br>一定得怎么写,不加 // 或者别的代码,就没有效果
 
ActionList是什么呀<br>我不知道请讲一下好吗?
 
不用actionlist用菜单也可以.
 
ActionList和Menu对快捷键的处理是相同的<br><br>to:changku<br>ActionList是Delphi的组件<br><br>就在Standard组件页的最后一个。<br><br>攒点分真不容易.......汗<br>
 
木子<br>不过那样也不行的
 
其实这样最简单:<br>procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br>&nbsp; &nbsp; CanClose:=false;<br>end;<br><br>问题解决了。<br>
 
好恨呀<br>想关闭都关不掉
 
说具体点嘛,我的方法怎么不行?
 
后退
顶部