To get the application handle in C# to use as the first parameter of the SendMessage function, you can use the Process.GetCurrentProcess().MainWindowHandle property.

Here's an example:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

class Program
{
    // Import the SendMessage function from user32.dll
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint wmMsg, IntPtr wParam, string lParam);

    static void Main()
    {
        // Get the application handle
        IntPtr appHandle = Process.GetCurrentProcess().MainWindowHandle;

        // Use the application handle in SendMessage function
        IntPtr result = SendMessage(appHandle, 0x123, IntPtr.Zero, "Hello");

        // Do something with the result...
    }
}

In this example, we're using the Process.GetCurrentProcess().MainWindowHandle property to obtain the application handle, and then passing it as the first parameter of the SendMessage function

how do I get the application handle in c# to use in first parameter of private static extern IntPtr SendMessageIntPtr hWnd uint wmMsg IntPtr wParam string lParam;

原文地址: https://www.cveoy.top/t/topic/hUD6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录