using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RGiesecke.DllExport;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
namespace control
{
public class DllImportClass
{
[DllImport("user32.dll", EntryPoint = "SetParent")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern IntPtr SendMessageA(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
}
public class button
{
private static IntPtr HandleMainWindow;
[DllExport("CreateButton", CallingConvention = CallingConvention.StdCall)]
public static int CreateButton(IntPtr handleMainWindow,string name, string text, int x, int y, int width, int height)
{
button.HandleMainWindow = handleMainWindow;
Button btnNew = new Button();
btnNew.Name = name;
btnNew.Text = text;
btnNew.Bounds = new Rectangle(new Point(x, y), new Size(width, height));
btnNew.Click += new EventHandler(button.btnNew_Click);
DllImportClass.SetParent(btnNew.Handle, handleMainWindow);
return btnNew.Handle.ToInt32();
}
private static void btnNew_Click(object sender, EventArgs e)
{
Button btnNew = sender as Button;
if (btnNew != null)
{
DllImportClass.SendMessageA(button.HandleMainWindow, 32800, btnNew.Handle, IntPtr.Zero);
}
}
}
}