它适用于其他 winform 程序,但不适用于游戏本身。我正在尝试制作一个额外的菜单或“mod menu”,但它是不可见的。
用于测试 winform 是否有效的消息框按钮。当我单击"nowhere"
左上角时,它会"hello"
在消息框中显示我。
我尝试编辑代码但找不到问题。我应该怎么办?
namespace myapp
{
public partial class Form1 : Form
{
[System.ComponentModel.Browsable(false)]
public bool AllowTransparency { get; set; }
[System.ComponentModel.Browsable(false)]
public bool AllowTransparencykey { get; set; }
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public static int GWL_STYLE = -16;
public static int WS_CHILD = 0x40000000;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Process hostProcess = Process.GetProcessesByName("game").FirstOrDefault();
if (hostProcess != null)
{
Hide();
FormBorderStyle = FormBorderStyle.None;
SetBounds(0, 0, 0, 0, BoundsSpecified.Location);
IntPtr hostHandle = hostProcess.MainWindowHandle;
IntPtr guestHandle = this.Handle;
SetWindowLong(guestHandle, GWL_STYLE, GetWindowLong(guestHandle, GWL_STYLE) | WS_CHILD);
SetParent(guestHandle, hostHandle);
Show();
FormBorderStyle = FormBorderStyle.None;
SetBounds(0, 0, 0, 0, BoundsSpecified.Location);
}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello");
}
}
}