1

プログラミングは初めてです。

マインクラフトと呼ばれるゲームに入力/テキストを送信できるプログラムを作成する予定です-そのゲームはJavaで作成されました。

SendMessage API を使用しようとしていますが、使用方法がわかりません。

これはこれまでの私のコードです:

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;

namespace MinecraftTest2_Sendinput
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImportAttribute("User32.dll")]
        private static extern int FindWindow(String ClassName, String
        WindowName);

        [DllImportAttribute("User32.dll")]
        private static extern int SetForegroundWindow(int hWnd);

        [System.Runtime.InteropServices.PreserveSig]
        [DllImport("User32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi)]
        public static extern int SendMessage(int hWnd, uint Msg, int wParam, long lParam);


        private void button1_Click(object sender, EventArgs e)
        {
            int hWnd = FindWindow(null, "Minecraft");
            if (hWnd > 0)
            {
                SetForegroundWindow(hWnd);
                //I need to call the SendMessage here! but what should i type in the arguments? 
            }

        }
    }
}
4

1 に答える 1

1

これは、ウィンドウに送信するメッセージによって異なります。Windows メッセージの完全なリストは、ここここにあります。wParam と lParam はメッセージに依存し、ウィンドウ メッセージ キューに送信されるメッセージのパラメーターとして機能します。

左マウス ボタンのクリック メッセージをウィンドウに送信するための小さなスニペットを次に示します。パラメーターは両方とも null です。

 int WM_LBUTTONDOWN = &H201;
 int WM_LBUTTONUP = &H202;
 SendMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero); // Mouse Down
 SendMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero); // Mouse Up

たとえば、Control キーが押されたことをウィンドウに通知する場合は、wParam に MK_CONTROL を使用します。座標を指定する場合は、lParam を次のように使用します。

 int lParam = X + Y<<16;
 SendMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, lParam); // Mouse Down
于 2011-06-12T23:17:14.737 に答える