GetMessage函数()给予System.ExecutionEngineException [英] GetMessage() given an System.ExecutionEngineException

查看:179
本文介绍了GetMessage函数()给予System.ExecutionEngineException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern
            bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, int vk);
        [DllImport("user32")]
        public static extern
            bool GetMessage(ref Message lpMsg, IntPtr handle, uint mMsgFilterInMain, uint mMsgFilterMax);

        public const int MOD_ALT = 0x0001;
        public const int MOD_CONTROL = 0x0002;
        public const int MOD_SHIFT = 0x004;
        public const int MOD_NOREPEAT = 0x400;
        public const int WM_HOTKEY = 0x312;
        public const int DSIX = 0x36;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            bool r = RegisterHotKey(Handle, 1, MOD_ALT, DSIX);

            if (!r)
            {
                MessageBox.Show("can't do..");
                return;
            }

            Message msg = new Message();

            while (GetMessage(ref msg,IntPtr.Zero, 0, 0))
            {
                if (msg.message == WM_HOTKEY)
                {
                    MessageBox.Show("do work..");
                }
            }


        }
    }


    public class Message
    {
        public int message { get; set; }
    }
}

当目标pressed,我得到以下错误:

when the target is pressed, I get the following error:

Exception of type 'System.ExecutionEngineException' was thrown.

什么是呢?如何解决这一问题?先谢谢了。

what's is this? how to fix this? Thanks in advance.

推荐答案

这是注定要失败的。如果你写你自己的消息循环将停止接收任何消息的WinForms。

This is doomed to failure. If you write your own message loop it will stop WinForms receiving any messages.

相反,覆盖 preProcessMessage 的WndProc 功能。

这篇关于GetMessage函数()给予System.ExecutionEngineException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆