| |

VerySource

 Forgot password?
 Register
Search
View: 712|Reply: 4

There is a problem with the program.

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-6 11:30:01
| Show all posts |Read mode
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; // mouse move

        private const int WM_LBUTTONDOWN = 0x201; // left mouse button pressed
        private const int WM_RBUTTONDOWN = 0x204; // right mouse click
        private const int WM_MBUTTONDOWN = 0x207; // mouse roller pressed

        private const int WM_LBUTTONUP = 0x202; // the left mouse button is raised
        private const int WM_RBUTTONUP = 0x205; // right mouse button raised
        private const int WM_MBUTTONUP = 0x208; // mouse up

        private const int WM_LBUTTONDBLCLK = 0x203; // Double click with the left mouse button
        private const int WM_RBUTTONDBLCLK = 0x206; // right-click and double-click
        private const int WM_MBUTTONDBLCLK = 0x209; // double click with mouse

        [StructLayout (LayoutKind.Sequential)] // Declares a marshaling type
        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 is easy to use

            hHook = SetWindowsHookEx (hHook, new mouse_key_delegate (Mouse_Key_Proc), Marshal.GetHINSTANCE (Assembly.GetExecutingAssembly (). GetModules () [0]), 0); // Why is this sentence not easy
            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 ();
        }
    }
}


Please help me to see why global hooks are not easy to use? ? ? ? ? ? ? ? ? ?
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-21 21:15:01
| Show all posts
It seems that you have not yet understood the definition of global hooks. Global hooks must be made into dlls so that the process can be injected.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-5-22 12:45:01
| Show all posts
savage698
Is it a DLL?
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-15 18:30:01
| Show all posts
Yes, dll
Reply

Use magic Report

0

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-6-18 17:45:01
| Show all posts
I don’t understand. Sorry, the food is dead...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list