200分,请问屏蔽系统ALT+F4热键和不响应鼠标左右键的方法?(200分)

  • 主题发起人 主题发起人 Iveny
  • 开始时间 开始时间
I

Iveny

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样屏蔽系统ALT+F4热键<br>还有,怎样使系统不响应鼠标左右键的方法(就是使点击鼠标左右键都没反应,而鼠标却可以动)?<br><br>请给出完整例子,使用程序完成,不修改注册表,谢谢!
 
你可以在你的程序里面设一个全局热键呵<br>就是ALT+F4<br>这样在你的程序里面截获这个按键消息<br>再把它干掉不就行了吗<br><br>举个例子:<br><br>HotKeyId: Integer;<br>&nbsp; &nbsp; procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; HotKeyId := GlobalAddAtom('MyHotKey') - $C000;<br>&nbsp; RegisterHotKey(Handle, hotkeyid, 0, 49);<br>end;<br><br>procedure TForm1.HotKeyDown(var Msg: Tmessage);<br>begin<br>&nbsp; if (Msg.LParamHi = 49) then<br>&nbsp; begin<br>&nbsp; &nbsp; keybd_event(57, MapVirtualKey( 57, 0 ), 0 , 0 );<br>&nbsp; &nbsp; keybd_event(57, MapVirtualKey( 57, 0 ), KEYEVENTF_KEYUP , 0 );<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnRegisterHotKey(handle, HotKeyId);<br>end;
 
下面这个例子截获了所有键盘的按键消息并转发给edit1,你试试,也许对你有所帮助:)<br>procedure TForm1.appmsg(var msg:TMsg;var handled:boolean);<br>begin<br>&nbsp; if ((msg.message = WM_KEYDOWN) and (msg.hwnd&lt;&gt;Edit1.Handle)) then &nbsp; &nbsp; &nbsp;<br>&nbsp; begin<br>&nbsp; &nbsp; SendMessage(Edit1.Handle,257,msg.wParam,msg.lParam);<br>&nbsp; &nbsp; SendMessage(Edit1.Handle,258,msg.wParam,msg.lParam);<br>&nbsp; &nbsp; SendMessage(Edit1.Handle,280,msg.wParam,msg.lParam);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>&nbsp; Application.OnMessage := appmsg;<br>end;<br>
 
看一下能否帮到你(要用Form2.ShowSystemModal的方法来显示Form2):<br>unit Unit2;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; extctrls, StdCtrls;<br><br>type<br>&nbsp; TForm2 = 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; &nbsp; function ShowSystemModal: Integer;<br>&nbsp; end;<br><br>var<br>&nbsp; Form2: TForm2;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure SetKeyboardAndTaskbarSwitching(Enable: Boolean);<br>var<br>&nbsp; OldVal: Bool;<br>const<br>&nbsp; TaskBarWnd: HWnd = 0; { Task bar window handle }<br>&nbsp; ShowFlags: array[Boolean] of Integer = (sw_Hide, sw_ShowNoActivate);<br>{$ifdef Windows}<br>&nbsp; spi_ScreenSaverRunning = 97;<br>{$endif}<br>begin<br>&nbsp; SystemParametersInfo(spi_ScreenSaverRunning, Word(not Enable), @OldVal, 0);<br>{$ifdef Win32}<br>&nbsp; if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then<br>{$else}<br>&nbsp; if GetWinFlags and $4000 = 0 then<br>{$endif}<br>&nbsp; begin<br>&nbsp; &nbsp; if TaskBarWnd = 0 then<br>&nbsp; &nbsp; &nbsp; TaskBarWnd := FindWindow('Shell_TrayWnd', nil); { Find task bar }<br>&nbsp; &nbsp; ShowWindow(TaskBarWnd, ShowFlags[Enable]); { Hide/show task bar }<br>&nbsp; end<br>end;<br><br>function TForm2.ShowSystemModal: Integer;<br>var<br>&nbsp; Desktop: TForm;<br>&nbsp; DesktopDC: HDC;<br>begin<br>&nbsp; Desktop := TForm.CreateNew(nil);<br>&nbsp; try<br>&nbsp; &nbsp; { Clear form seems to make less flicker }<br>&nbsp; &nbsp; Desktop.Brush.Style := bsClear;<br>&nbsp; &nbsp; Desktop.WindowState := wsMaximized;<br>&nbsp; &nbsp; Desktop.BorderStyle := bsNone;<br>&nbsp; &nbsp; DesktopDC := GetWindowDC(GetDesktopWindow);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; with TImage.Create(Desktop) do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Align := alClient;<br>&nbsp; &nbsp; &nbsp; &nbsp; Picture.Bitmap.Height := Screen.Height;<br>&nbsp; &nbsp; &nbsp; &nbsp; Picture.Bitmap.Width := Screen.Width;<br>&nbsp; &nbsp; &nbsp; &nbsp; BitBlt(Canvas.Handle, 0, 0, Screen.Width,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Screen.Height, DesktopDC, 0, 0, srcCopy);<br>&nbsp; &nbsp; &nbsp; &nbsp; Parent := Desktop;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; ReleaseDC(GetDesktopWindow, DesktopDC)<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Desktop.Show;<br>&nbsp; &nbsp; { Ensure when anyone clicks on what looks like }<br>&nbsp; &nbsp; { another window, all they get is a beep }<br>&nbsp; &nbsp; Desktop.Enabled := False;<br>&nbsp; &nbsp; SetKeyboardAndTaskbarSwitching(False);<br>&nbsp; &nbsp; Result := ShowModal;<br>&nbsp; &nbsp; SetKeyboardAndTaskbarSwitching(True)<br>&nbsp; finally<br>&nbsp; &nbsp; Desktop.Free<br>&nbsp; end;<br>end;<br><br>procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br>&nbsp; CanClose := CheckBox1.Checked;<br>end;<br><br>end.
 
你说的ALT+F4是指对你的程序,还是指对整个系统
 
对整个系统,如果不能,对我的程序也可以!<br><br>但屏蔽鼠标的点击,就是整个系统!
 
请问有人知道怎样使系统不响应鼠标左右键的方法<br>(就是使点击鼠标左右键都没反应,而鼠标却可以动)?<br>
 
对整个系统,用我的方法应该是可以的呵!<br><br><br>不过你的另一个问题我就不知道如何解决了
 
如果你只需要屏蔽你的程序,那么可以把窗体KeyPreview:=true;<br>procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; if (key = VK_F4) and (Shift = [ssAlt]) then<br>&nbsp; &nbsp; Key := 0;<br>end;<br>这样看起来最简单.<br>屏蔽鼠标左键可以在VCL的MouseDown添加releasecapture;<br>整个系统就不知道了,但是你可以把鼠标活动范围限制在某一范围内,<br>比如说你的窗体.
 
有没有系统屏蔽鼠标点击的API?
 
你要屏蔽鼠标点击ALT+F4这项吗?如果是,那么你使ALT+F4菜单变灰即可。<br>在formcreate里写<br>enablemenuitem(getsystemmenu(hanlde,false),Sc_close,MF_grayed);<br>这句语句将使form右上角的叉灰掉,即ALT+F4灰掉了,鼠标也就点击无效。<br>
 
不是,我要屏蔽系统的所有鼠标点击操作!!
 
做一个系统全局的鼠标钩子,可以实现对系统所有鼠标操作进行监控。<br>键盘钩子也同理。<br><br>例子如下,我没试过。 &nbsp;分数给不给由你啦,呵呵:)<br><br>在Windows系统中提供了一种系统消息挂钩的(Message hook)功能,使用消息挂钩,可以实时监视处理系统中的各种消息。很多鼠标增强软件就是利用消息挂钩来拦截所有的鼠标消息进行处理的。<br>要设置鼠标消息挂钩,一般
先建立一个使用鼠标消息挂钩的动态连接库(DLL)文件,然后就可以在其它程序中使用这个DLL文件处理鼠标消息。<br>下面的程序介绍通过鼠标消息挂钩监视鼠标消息,从而实现类似于一些鼠标增强软件一样的使窗口上下左右滚动的功能。<br><br>1.建立动态连接库<br>选择菜单 File|New ,选择DLL产生一个DLL模版,保存为 MHook.Dpr<br>//MHook.Dpr源程序<br>library MHook;<br><br>uses<br>SysUtils,<br>Classes,<br>hkproc in 'hkproc.pas';<br><br>exports<br>EnableMouseHook,<br>DisableMouseHook;<br><br>begin<br>hNextHookProc:=0;<br>procSaveExit:=ExitProc;<br>ExitProc:=@HotKeyHookExit;<br>end.<br><br>再选择菜单 File|New ,选择Unit建立一个Pas文件,保存为 HKProc.pas<br>//HKProc.pas源程序<br>unit hkproc;<br><br>interface<br>uses<br>Windows,Messages;<br>const<br>Move_Up = 0;<br><br>Move_Down=1;<br>Move_Left=2;<br>Move_Right=3;<br>var<br>hNextHookProc:HHook;<br>procSaveExit:Pointer;<br>M_Direct:Integer;<br>LPoint:TPoint;<br>NowWindow:Integer;<br><br>function MouseProc(iCode:Integer;wParam:WPARAM;<br>lParam:Pointer):LRESULT; stdcall;export;<br>function EnableMouseHook(WndHandle:integer):BOOL;export;<br><br>function DisableMouseHook:BOOL;export;<br>function GetDirect(FPoint : TPoint;LPoint : TPoint):integer;<br>procedure HotKeyHookExit;far;<br><br> <br><br>implementation<br><br>//GetDirect函数根据光标的移动决定窗口滚动的方向。<br>function GetDirect(FPoint : TPoint;LPoint : TPoint):integer;<br>var<br>iWidth,iHeight:integer;<br>begin<br>iWidth:=LPoint.x-FPoint.x;<br>iHeight:=lPoint.y-FPoint.y;<br>Result:=-1;<br><br>if ((iWidth=0)or(iHeight=0))then<br>exit;<br><br>if ((abs(iWidth) div abs(iHeight))&gt;=2) then<br>if iWidth&lt;0 then //Move to left<br>Result:=Move_Left<br>else<br>Result:=Move_Right<br><br>else if ((abs(iHeight) div abs(iWidth))&gt;=2) then<br>if iHeight&lt;0 then //Move to top<br>Result:=Move_Up<br>else<br>Result:=Move_Down;<br><br>end;<br><br>function MouseProc(iCode:Integer;wParam:WPARAM;<br>lParam:Pointer):LRESULT; stdcall;export;<br>var<br>pMouse:^MOUSEHOOKSTRUCT;<br>l:integer;<br>begin<br>//如果用户按下鼠标右键同时Scroll Lock键为按下状态则<br>//滚动窗口。<br>if ((wParam=WM_RBUTTONDOWN) and Boolean(GetKeyState(145))) then<br>begin<br>pMouse:=lParam;<br>l:=GetDirect(lPoint,pMouse.pt);<br>if l&gt;=0 then<br>M_Direct:=l;<br>lPoint:=pMouse.pt;<br><br>NowWindow:=WindowFromPoint(lPoint);<br>if M_Direct=Move_Up then<br>SendMessage(NowWindow,WM_VSCROLL,SB_PAGEUP,0)<br>else if M_Direct=Move_Down then<br><br>SendMessage(NowWindow,WM_VSCROLL,SB_PAGEDOWN,0)<br>else if M_Direct=Move_Left then<br>SendMessage(NowWindow,WM_HSCROLL,SB_PAGELEFT,0)<br>else if M_Direct=Move_Right then<br>SendMessage(NowWindow,WM_HSCROLL,SB_PAGERIGHT,0);<br>Result:=1;<br>exit;<br>end<br>else if ((wParam=WM_RBUTTONUP) and Boolean(GetKeyState(145))) then<br>Result:=1<br>else<br>begin<br>Result:=0;<br>if iCode&lt;0 then<br>begin<br>Result:=CallNextHookEx(hNextHookProc,iCode,wParam,<br>integer(lParam));<br>Exit;<br>end;<br>end;<br>end;<br><br>function EnableMouseHook(WndHandle:integer):BOOL;export;<br>begin<br>GetCursorPos(lPoint);<br>Result:=False;<br>if hNextHookProc&lt;&gt;0 then<br>exit;<br>//设置Mouse hook<br>hNextHookProc:=SetWindowsHookEx(WH_MOUSE,@MouseProc,<br>Hinstance,0);<br>Result:=hNextHookProc&lt;&gt;0;<br>end;<br><br>function DisableMouseHook:BOOL;export;<br>begin<br>if hNextHookProc&lt;&gt;0 then<br>begin<br>UnHookWindowsHookEx(hNextHookProc);<br>hNextHookProc:=0;<br>end;<br>Result:=hNextHookProc=0;<br>end;<br><br>procedure HotKeyHookExit;<br>begin<br>if hNextHookProc&lt;&gt;0 then<br>DisableMouseHook;<br>ExitProc:=procSaveExit;<br>end;<br><br>end.<br>在菜单中选择 Project|Build MHook建立DLL文件。<br><br>2.建立程序调用动态连接库<br>在这里我们还是使用Delphi建立程序,当然也可以使用诸如VB等调用动态连接库。<br>在菜单中选 File|New Application建立一个新程序,将工程文件保存为Project1.dpr<br><br>//project1的源程序<br>program Project1;<br><br>uses<br>Forms,<br>Sample1 in 'Sample1.pas' {Form1};<br><br>{$R *.RES}<br><br>begin<br>Application.Initialize;<br>//隐藏窗口<br>Application.ShowMainForm := False;<br><br>Application.CreateForm(TForm1, Form1);<br>Application.Run;<br>end. <br><br>将Form1的源程序文件保存成Sample1.pas<br><br>//Form1的源程序<br>unit Sample1;<br><br>interface<br><br>uses<br>Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>StdCtrls, Menus, ImgList,ShellApi, ExtCtrls;<br><br>const<br>WM_ICONMESSAGE=WM_USER+$100;<br><br><br>type<br>TForm1 = class(TForm)<br><br>procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>procedure FormCreate(Sender: TObject);<br>private<br>procedure WMBarIcon(var Message:TMessage);message WM_ICONMESSAGE;<br><br>public<br><br>end;<br><br>function EnableMouseHook(WndHandle:integer):BOOL;external 'MHook.DLL';<br>function DisableMouseHook:BOOL;external'MHook.DLL';<br><br>var<br>Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.WMBarIcon (var Message:TMessage);<br>begin<br>//用户双击任务栏图标则关闭程序 <br>if Message.LParam = WM_LBUTTONDBLCLK then<br>close;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br>lpData:PNotifyIconData;<br>begin<br>//删除任务栏图标<br>lpData := new(PNotifyIconDataA);<br>lpData.cbSize := 88;//SizeOf(PNotifyIconDataA);<br>lpData.Wnd := Form1.Handle;<br>lpData.hIcon := Form1.Icon.Handle;<br>lpData.uCallbackMessage := WM_ICONMESSAGE;<br>lpData.uID :=0;<br>lpData.szTip := '鼠标演示';<br>lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>Shell_NotifyIcon(NIM_DELETE,lpData);<br>dispose(lpData);<br>//解除Mouse hook<br>DisableMouseHook;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>lpData:PNotifyIconData;<br>begin<br>EnableMouseHook(Form1.Handle);<br>Form1.Visible := False;<br>lpData := new(PNotifyIconDataA);<br>lpData.cbSize := 88;//SizeOf(PNotifyIconDataA);<br>lpData.Wnd := Form1.Handle;<br>lpData.hIcon := Form1.Icon.Handle;<br>lpData.uCallbackMessage := WM_ICONMESSAGE;<br>lpData.uID :=0;<br>lpData.szTip := '鼠标演示';<br>lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>Shell_NotifyIcon(NIM_ADD,lpData);<br>dispose(lpData);<br>end;<br><br>end.<br><br>运行程序,按下Scroll Lock键使其有效,将光标移动到文本窗口中(如IE、Word),移动鼠标,点击鼠标右键,窗口就可以依上一次移动的方向滚动。<br>利用上面的原理,将程序做一些改动,就可以象专业的鼠标增强程序一样做出例如缩放窗口,运行程序等很多鼠标增强效果来。<br>上面的程序在Windows95,Delphi4.0下运行通过。 <br><br>
 
太麻烦了,如果只是要让程序不能关闭可以在onclose中加入cation:=canone;<br>右键也很简单,放一个空的popmenu然后....
 
参考下面的代码吧<br>var <br>&nbsp; hwndHandle : THANDLE; <br>&nbsp; hMenuHandle : HMENU; <br>begin <br>&nbsp; hwndHandle := FindWindow(nil, 'Untitled - Notepad'); <br>&nbsp; if (hwndHandle &lt;&gt; 0) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; hMenuHandle := GetSystemMenu(hwndHandle, FALSE); <br>&nbsp; &nbsp; if (hMenuHandle &lt;&gt; 0) then DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND); <br>&nbsp; &nbsp; end; <br>end;
 
该说的别人都说了
 
后退
顶部