在Windows Service中接收Windows消息(WM_messages)
2014-04-22 17:45
281 查看
窗口程序接收系统消息,会有相应的WndProc函数。在Service中则没有这样的函数,所以必须想办法进行消息的获取。
首先,我们建立一个类,类继承与System.Windows.Forms.Form。
参考:http://bytes.com/topic/c-sharp/answers/610416-listening-windows-messages-windows-service
参考:http://msdn2.microsoft.com/en-us/library/system.windows.forms.message.aspx
首先,我们建立一个类,类继承与System.Windows.Forms.Form。
#pragma once #using <System.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> #include <Windows.h> #include <fstream> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; using namespace System::Security::Permissions; public ref class MessageForm : public System::Windows::Forms::Form { public: MessageForm(void){}; ~MessageForm(void){}; protected: [SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)] virtual void WndProc( Message% m ) override { // Listen for operating system messages. switch ( m.Msg ) { case WM_Message: //Your code. break; } Form::WndProc( m ); stream.close(); } };之后,我们在服务开启之后,建立这个对象。
Application::Run( gcnew MessageForm );这样就能在服务中,进行Windows消息的处理了。
参考:http://bytes.com/topic/c-sharp/answers/610416-listening-windows-messages-windows-service
参考:http://msdn2.microsoft.com/en-us/library/system.windows.forms.message.aspx
相关文章推荐
- 如何使对话框中接收到WM_CHAR消息(Windows编程)
- 如何使对话框中接收到WM_CHAR消息(Windows编程)
- WinForm 和 Windows Service 通信 消息队列
- WinForm 和 Windows Service 通信 - 消息队列(转)
- 常用Windows消息(Common Windows Messages)
- Windows程序设计零基础自学_2_Windows程序的显示和更新_之WM_PAINT消息
- WinForm 和 Windows Service 通信 - 消息队列
- Windows(WinAPI)窗口创建后,依次接收的消息
- 详解Windows消息分类以及WM_COMMAND与WM_NOTIFY的区别,以及模拟发送控件通知消息
- ROS_Kinetic_26 使用rosserial_windows实现windows与ROS master发送与接收消息
- Receiver 无法接收service传递的消息
- Windows 编程[10] - WM_LBUTTONDOWN、WM_LBUTTONUP 和 WM_MOUSEMOVE 消息
- windows 无窗口线程消息接收
- Windows消息投递流程:一般窗口消息投递(WM_LBUTTONCLICK)
- 进程通信(用户自定义消息,用户注册消息,windows剪贴板,WM_COPY, 内存映射,对目标进程的内存)
- 让自己写的Delphi控件具备接收windows消息的能力
- 关于Windows消息的发送和接收入门
- windows——消息——WM_CREATE WM_DESTROY
- 实现在vista和win7中使用管理员权限接收WM_DROPFILES(OnDropFiles())消息的方法
- WM_DROPFILES消息怎么用?一个界面上怎么让多个组件同时支持windows外部文件拖拽。DragAcceptFiles。