using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using WinAPI;
using static WinAPI.Struct;
namespace MyDb
{
///
/// Win32 API
///
public class RyWin32
{
///
///
///
public const int GWL_WNDPROC = (-4);
///
/// WM_COPYDATA消息的主要目的是允许在进程间传递只读数据。
///
public const int WM_COPYDATA = 0x004A;
///
/// 系统通道ID
///
public const int Sys_chanel_id = 1000;
///
/// 用户通道ID
///
public const int User_chanel_id = 1001;
///
/// 获取消息
///
///
///
///
public static string GetMsg(Message m,out IntPtr handle)
{
COPYDATASTRUCT cdata = new COPYDATASTRUCT();
Type mytype = cdata.GetType();
cdata = (COPYDATASTRUCT)m.GetLParam(mytype);
handle = cdata.dwData;
return cdata.lpData;
}
///
/// 发送消息
///
///
///
///
///
///
public static int SendMsg(IntPtr from_handle, IntPtr to_handle, int wParam, string str)
{
byte[] arr = System.Text.Encoding.Default.GetBytes(str);
int len = arr.Length;
COPYDATASTRUCT cdata;
cdata.dwData = from_handle;
cdata.lpData = str;
cdata.cData = len + 1;
return User32.SendMessage(to_handle, WM_COPYDATA, wParam, ref cdata);
}
///
/// 设置父窗口
///
///
///
///
///
public static bool SetParentWin(IntPtr sub_form, IntPtr parent_form,Size size)
{
User32.SetParent(sub_form, parent_form);
User32.MoveWindow(sub_form, 0, 0, size.Width, size.Height, false);
return true;
}
}
}