如何在屏幕上恢复最小化窗口?(50分)

  • 主题发起人 主题发起人 huiyugan
  • 开始时间 开始时间
H

huiyugan

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; &nbsp;我如何让已经最小化的窗口通过热键恢复到屏幕上?<br>&nbsp; &nbsp; 比如说,我在某个应用程序里定义了一个热键F1,我希望<br>在这个应用程序最小化后,我一按F1键这个应用程序的窗口便<br>弹出来,而不仅仅是任务条上的FLASH?<br>&nbsp; &nbsp; 谢谢各位!
 
写代码最复杂, 表述最简单的方法:<br>全局hook键盘, 监视热键, 如果出现则用showwindow显示特定窗口
 
TO ANOTYER_eYes:<br>&nbsp; &nbsp; 最好能给出代码!<br>&nbsp; &nbsp; 登记热键可用REGISTERHOTKEY,要是用HOOK是不是太复杂了?
 
我想必须用hook才能达到你的要求。然后就是application.restore.
 
能给出代码吗?
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMHotKey(var msg:Tmessage);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>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; registerhotkey(form1.handle,1,mod_alt,vk_f10);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; unregisterhotkey(form1.handle,1);<br>end;<br><br>procedure TForm1.WMHotKey;<br>begin<br>&nbsp; application.restore ;<br>end;<br><br>end.<br><br>menxin:要分吗?<br>
 
F1肯定是不行的,它是系统的帮助热键。改用别的如F2<br>可以动态在桌面创一快捷方式,快捷键为F2,<br>它的快捷方式为带参数启动此EXE程序,<br>通过辨别参数起动恢复的作用,应该不难。
 
&nbsp; &nbsp;to 3h:<br>&nbsp; &nbsp; 前面有MOD-ALT表示要ALT键和F10同时按下!
 
我贴你还没贴。
 
你的办法确实简单!又学一招。
 
hui,我试了一下你的小程序,当该程序获得焦点的时候是可以的,但当我先点击另<br>外的程序,再用按alt_f10的时候,就不行了!<br>所以我想还是应该用HOOK来解决你的问题。<br><br>不好意思,你的程序还是可以的,但是有点小问题,我把你源程序改了一下:<br>procedure TForm1.WMHotKey(var msg: Tmessage);<br>begin<br>&nbsp; if IsIconic(application.handle) then<br>&nbsp; &nbsp; Application.restore<br>&nbsp; else<br>&nbsp; &nbsp; Application.BringToFront;<br>end;<br>这样就更好了--无论什么时候按ALT_F10,窗口都弹到你面前!<br>:-))<br><br>
 
&nbsp; &nbsp;谁能给出HOOK的实现方式
 
我想既然已经能够做到“而不仅仅是任务条上的FLASH”了,<br>表明已经激活了你的窗口,<br>只需要用Application.BringToFront显示出来就行了
 
huiyugan:<br>&nbsp; &nbsp; 刚刚做了一个HOOK的例子给你,有点小问题,但肯定能用了,试试吧:<br><br>unit hooktest;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, <br>&nbsp; Dialogs,StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; HookKey: TButton;<br>&nbsp; &nbsp; UnhookKey: TButton;<br>&nbsp; &nbsp; procedure HookKeyClick(Sender: TObject);<br>&nbsp; &nbsp; procedure UnhookKeyClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<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>&nbsp; hNextHookProc: HHook;<br>&nbsp; AppHandle &nbsp; &nbsp;: HWND;<br><br>implementation<br><br>{$R *.DFM}<br>function KeyboardHookHandler(iCode: Integer;<br>&nbsp; wPm: WPARAM;lPm: LPARAM): LRESULT; stdcall;<br>const<br>&nbsp; _KeyPressMask = $80000000;<br>begin<br>&nbsp; Result := 0;<br>&nbsp; If iCode &lt; 0 Then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := CallNextHookEx(hNextHookProc, iCode, wPm, lPm);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; if ((lPm and _KeyPressMask) = 0) and<br>&nbsp; &nbsp; (GetKeyState(vk_Control) &lt; 0) and (wPm = ord('H')) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := 1;<br>&nbsp; &nbsp; if AppHandle =0 then<br>&nbsp; &nbsp; &nbsp; AppHandle := FindWindow(nil,'Hook Demo');<br>&nbsp; &nbsp; if AppHandle &lt;&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; if IsIconic(AppHandle) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowWindow(AppHandle,sw_restore);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForeGroundWindow(AppHandle);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.HookKeyClick(Sender: TObject);<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then Exit;<br>&nbsp; hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,<br>&nbsp; &nbsp; KeyboardHookHandler,<br>&nbsp; &nbsp; HInstance,<br>&nbsp; &nbsp; 0);<br>&nbsp; if hNextHookProc&lt;&gt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('hook ok!');<br>&nbsp; end;<br>end;<br><br>procedure TForm1.UnhookKeyClick(Sender: TObject);<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowshookEx(hNextHookProc);<br>&nbsp; &nbsp; hNextHookProc := 0;<br>&nbsp; &nbsp; MessageBeep(0);<br>&nbsp; end;<br>&nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp;ShowMessage('unhook failed!');<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then UnhookKeyClick(nil);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; hNextHookProc :=0;<br>&nbsp; AppHandle :=0;<br>&nbsp; Application.Title := 'Hook Demo';<br>end;<br><br>end.<br><br>哦,我把热键改成ctrl-h了! &nbsp;:-))
 
给你两个地址, 去下载两个范例程序, 对于学做Keyboard Hook很有帮助.<br><br>http://vcl.vclxx.com/delphi/d32free/hookdemo.zip -- 钱达智的大作, 教你<br>做Keyboard Hook, 所举实例就是怎样实现你所要的热键,说明详细, 值得一看。<br><br>http//vcl.vclxx.com/delphi/d32free/hotkeys.zip -- Keyboard Hook的范例,<br>完整的应用程序, 用户化设置为Windows增加热键
 
本题可以结束了吧?<br>BTW:钱 的例子有小问题,可以参见本论坛有关问题的讨论
 
多人接受答案了。
 

Similar threads

回复
0
查看
815
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部