2个困扰多日的问题(300分)

  • 主题发起人 主题发起人 7030
  • 开始时间 开始时间
7

7030

Unregistered / Unconfirmed
GUEST, unregistred user!
1.如何捕获application.terminate消息?application.onmessage里wm_query和wm_close都捕获不了<br>2.如何实现一个TForm.show(不能用showmodal)能实现showmodal的效果,也就是这个Form一直位于当前应用程序的最顶端,并且其它窗体不能获得焦点?
 
第一个问题:使用ApplicationEvents1组件,<br>第二个问题:你只能使用API自己处理了。<br>方法啊,使用VC的方法转换代码就可以了。VC的第一科就直接处理这些消息,你把它改成控制台DELPHI的,和VC代码相同,。。。。
 
1.用applicationevents组件和application.onmessage捕获消息的机制一样的,试了各种消息ID,如wm_close,wm_destroy,wm_command,WM_QUERYENDSESSION还是捕获不了<br>2.看vcl的showmodal源码了
 
既然是实现showmodal的效果为什么不直接使用showmodal呢
 
1. 可以通过检查 Application.Terminated 标志来得知Application是否中止。<br>2. 修改属性:FormStyle=&gt;fsStayOnTop
 
使用VCL,你的两个问题都能解决。。自己编写了。DELPHI估计这些都封装了。
 
看帖来的
 
第2个问题,可以用函数<br>DisableTaskWindows<br>EnableTaskWindows
 
2: show之后加个HOOK就可以实现你的要求啦.
 
先谢谢各位大虾指点,偶先照你们说的研究研究...
 
1 使用ApplicationEvents1组件,
 
搞定了<br>1.wndproc可以捕获到wm_quit消息<br>2.用disabletaskwindow和enabletaskwindow
 
代码:Unit1单元<br>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;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations<br> &nbsp; &nbsp;}<br> &nbsp; &nbsp;procedure WMClose(var Msg: TMessage); Message WM_CLOSE;<br> &nbsp; &nbsp;procedure WMQUERYENDSESSION(var Msg: TMessage); Message WM_QUERYENDSESSION;<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp; &nbsp;<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;Form2.Show;<br>end;<br><br>procedure TForm1.WMClose(var Msg: Tmessage);<br>begin<br> &nbsp;if msg.Msg=WM_CLOSE then<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('WM_CLOSE');<br> &nbsp; &nbsp;close;<br> &nbsp;end;<br>end;<br><br>procedure TForm1.WMQUERYENDSESSION(var Msg: Tmessage);<br>begin<br> &nbsp;if msg.Msg=WM_QUERYENDSESSION then<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('WM_QUERYENDSESSION');<br> &nbsp; &nbsp;close;<br> &nbsp;end;<br>end;<br><br>end.<br>//----------------------------------------------<br>Unit2单元<br>unit Unit2;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs;<br><br>type<br> &nbsp;TForm2 = class(TForm)<br> &nbsp; &nbsp;procedure FormShow(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form2: TForm2;<br> &nbsp;WindowList: Pointer;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm2.FormShow(Sender: TObject);<br>begin<br> &nbsp;WindowList := DisableTaskWindows(0);<br>end;<br><br>procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp;EnableTaskWindows(WindowList);<br>end;<br><br>end.
 
后退
顶部