问题描述
我写了个服务程序,需要和用户交互。程序如下:protectedoverridevoidOnStart(string[]args){if(threadForm==null){threadForm=newThread(newThreadStart(FormShow));threadForm.Start();}}voidFormShow(){GetDesktopWindow();IntPtrhwinstaSave=GetProcessWindowStation();IntPtrdwThreadId=GetCurrentThreadId();IntPtrhdeskSave=GetThreadDesktop(dwThreadId);IntPtrhwinstaUser=OpenWindowStation("WinSta0",false,33554432);if(hwinstaUser==IntPtr.Zero){RpcRevertToSelf();return;}SetProcessWindowStation(hwinstaUser);IntPtrhdeskUser=OpenDesktop("Default",0,false,33554432);RpcRevertToSelf();if(hdeskUser==IntPtr.Zero){SetProcessWindowStation(hwinstaSave);CloseWindowStation(hwinstaUser);return;}SetThreadDesktop(hdeskUser);IntPtrdwGuiThreadId=dwThreadId;Form1f=newForm1();System.Windows.Forms.Application.Run(f);dwGuiThreadId=IntPtr.Zero;SetThreadDesktop(hdeskSave);SetProcessWindowStation(hwinstaSave);CloseDesktop(hdeskUser);CloseWindowStation(hwinstaUser);}Form1中定义注册快捷键RegisterHotKey(Handle,100,9,80);//Alt+Win+P程序运行良好,按Alt+Win+P快捷键程序能够响应。但是当用户注销后又重新登陆时,按Alt+Win+P快捷键程序不再响应。为什么??
解决方案
解决方案二:
RegisterHotKey在哪里写的还有注销哪里代码怎么写的!什么样子???
解决方案三:
RegisterHotKey在Form.load事件中装载。用户注销是windows操作系统中注销用户,可以再以其他用户身份登陆windows系统。
解决方案四:
privatevoidForm1_Load(objectsender,System.EventArgse){RegisterHotKey(Handle,100,9,80);//Alt+Win+P}protectedoverridevoidWndProc(refMessagem){switch(m.Msg){caseWM_HOTKEY:ProcessHotkey(refm);break;}base.WndProc(refm);}privatevoidProcessHotkey(refMessagemsg){intkey=msg.WParam.ToInt32();switch(key){case100:DoSomeThing();break;default:break;}//endswitch}