您的位置:程序门 -> .net技术 -> c#



程序有问题,帮看看(vs2005)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


程序有问题,帮看看(vs2005)
发表于:2007-01-05 12:10:15 楼主
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.reflection;

namespace   a4
{
        public   partial   class   form1   :   form
        {
                private   const   int   wm_mousemove   =   0x200;                   //鼠标移动

                private   const   int   wm_lbuttondown   =   0x201;               //鼠标左键按下
                private   const   int   wm_rbuttondown   =   0x204;               //鼠标右键按下
                private   const   int   wm_mbuttondown   =   0x207;               //鼠标滚轴按下

                private   const   int   wm_lbuttonup   =   0x202;                   //鼠标左键抬起  
                private   const   int   wm_rbuttonup   =   0x205;                   //鼠标右键抬起
                private   const   int   wm_mbuttonup   =   0x208;                   //鼠标滚轴抬起

                private   const   int   wm_lbuttondblclk   =   0x203;           //鼠标左键双击
                private   const   int   wm_rbuttondblclk   =   0x206;           //鼠标右键双击
                private   const   int   wm_mbuttondblclk   =   0x209;           //鼠标滚轴双击

                [structlayout(layoutkind.sequential)]               //声明一个封送类型
                public   class   mousehookstruct
                {
                        public   point   pt;
                        public   int   hwnd;
                        public   int   whittestcode;
                        public   int   dwextrainfo;
                }

                int   hhook=0;
                private   delegate   int   mouse_key_delegate(
                                                                            int   ncode,int   wparam,intptr   lparam);

                [dllimport( "kernel32.dll "   ,   charset   =   charset.auto   ,   callingconvention   =   callingconvention.stdcall,   setlasterror   =   true   ,   entrypoint   =   "getcurrentthreadid ")]
                private   static   extern   int   getcurrentthreadid();

                [dllimport( "user32.dll ",     charset   =   charset.auto   ,   callingconvention   =   callingconvention.stdcall,   setlasterror   =   true   ,   entrypoint   =   "setwindowshookexa ")]
                private   static   extern   int   setwindowshookex(int   hhook,   mouse_key_delegate   mkdelegate,   intptr   wparam,   int   lparam);

                [dllimport( "user32.dll "   ,   charset   =   charset.auto,   callingconvention   =   callingconvention.stdcall,   setlasterror   =   true   ,   entrypoint   =   "unhookwindowshookex ")]
                private   static   extern   bool   unhookwindowshookex(int   hhook);

                [dllimport( "user32.dll ",   charset   =   charset.auto,   callingconvention   =   callingconvention.stdcall,   setlasterror   =   true   ,   entrypoint   =   "callnexthookex ")]
                private   static   extern   int   callnexthookex(int   hhook,   int   ncode,   int   wparam,   intptr   lparam);


                public   form1()
                {
                        initializecomponent();
                }

                public   form1(int   hhook)
                {
                        this.hhook   =   hhook;
                        this.initializecomponent();
                }

                private   int   mouse_key_proc(int   ncode,   int   wparam,   intptr   lparam)
                {
                        mousehookstruct   mymousehookstruct   =   (mousehookstruct)marshal.ptrtostructure(lparam,   typeof(mousehookstruct));

                        if   (ncode   >   0   &&   wparam   ==   wm_lbuttondown)
                        {
                                this.toolstripstatuslabel1.text   =   "   x=   "   +   mymousehookstruct.pt.x   +   ",   y=   "   +   mymousehookstruct.pt.y;
                                return   1;  
                        }

                        return   callnexthookex(hhook,   ncode,   wparam,   lparam);
                }

                private   bool   start()
                {
                        //hhook   =   setwindowshookex(hhook,   new   mouse_key_delegate(mouse_key_proc),   intptr.zero,   getcurrentthreadid());//hhook=2好用

                        hhook   =   setwindowshookex(hhook,   new   mouse_key_delegate(mouse_key_proc),   marshal.gethinstance(assembly.getEXECutingassembly().getmodules()[0]),   0);//这句为什么不好用
                        messagebox.show( "hhook=   "   +   hhook);

                        if   (hhook   !=   0)
                                return   true;
                        return   false;
                }

                private   bool   stop()
                {
                        if   (hhook   ==   0)
                        {
                                unhookwindowshookex(hhook);
                                return   true;
                        }
                        return   false;
                }

                private   void   form1_load(object   sender,   eventargs   e)
                {
                        hhook   =   14;
                        start();
                }
        }
}


请帮我看看全局钩子为什么不好用??????????
发表于:2007-01-05 12:15:381楼 得分:0
看来你还没有理解全局钩子的定义,全局钩子要作成dll的,这样才能进程注入
发表于:2007-01-05 12:16:052楼 得分:0
http://www.souzz.net/html/edu/net/net7/11518.html
发表于:2007-01-05 12:20:563楼 得分:0
superxiaomm(小美)  
非要做成dll吗?
发表于:2007-01-05 16:42:234楼 得分:0
是的,dll
发表于:2007-01-05 17:05:015楼 得分:0
有点看不懂     抱歉     菜死了....


快速检索

最新资讯
热门点击