日期:2014-05-20  浏览次数:20704 次

用C#实现一个热键关闭IE,急!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project5
{
    
     public class ClassTForm
    {
        int hotkeyid;

        procedure TForm.FormCreate();


        //procedure FormCreate();
      
    //public
             bool RegisterHotKey(string Handle,int hotkeyid, uint MOD_ALT ,uint VK_F4);  
        
       procedure WMHotKey(var Msg,string TWMHotKey); message WM_HOTKEY;   //action hotkey   public    { Public declarations }  end; 
       procedure   TfrmAdKiller.WMHotKey(var   Msg,   string TWMHotKey); 
   
                   
           if   Msg.HotKey   =   hotkeyid   then;            
            begin                 
               if   Visible   then;                
                   LoadAppIcon                
                       else   UnLoadIcon;             
              end;
         end; 
        bool UnRegisterHotKey(string handle,   int HotKeyId);   //注销HotKey,   释放资源

       
       //procedure OnHotKey(var msg:Tmessage);message WM_HOTKEY;
    }
}
不能实现相应功能,请高手指教。
------解决方案--------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections;
using System.Diagnostics;
namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public delegate void HotkeyEventHandler(int HotKeyID);//热键事件委托        
        private int Hotkey1;
        private const int WM_HOTKEY = 0x0312;       // 热键消息编号    
        public class Hotkey : System.Windows.Forms.IMessageFilter
        {
            Hashtable keyIDs = new Hashtable();//热键哈希表  
            IntPtr hWnd;

            public event HotkeyEventHandler OnHotkey;  //热键事件   

            public enum KeyFlags//控制键编码    
            {
                MOD_ALT = 0x1,
                MOD_CONTROL = 0x2,
                MOD_SHIFT = 0x4,
                MOD_WIN = 0x8
            }
            [DllImport("user32.dll")]