I created some template project that implements this material using Windows messaging. The template is huge and contains some other things (such as localization, updates, formatting, clipboard and interface for documents, so actions in MDI can be easily redirected to MDI children). If you want to view the template, try this link (or this link )
Some of the code:
Win32.cs:
public partial class Win32 { //public const int WM_CLOSE = 16; //public const int BN_CLICKED = 245; public const int WM_COPYDATA = 0x004A; public struct CopyDataStruct : IDisposable { public IntPtr dwData; public int cbData; public IntPtr lpData; public void Dispose() { if (this.lpData != IntPtr.Zero) { LocalFree(this.lpData); this.lpData = IntPtr.Zero; } } } [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref CopyDataStruct lParam); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr LocalAlloc(int flag, int size); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr LocalFree(IntPtr p); }
Program.cs:
static class Program { static Mutex mutex = new Mutex(true, guid()); static string guid() {
MainFrom.cs:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] protected override void WndProc(ref Message m) { switch (m.Msg) { case Win32.WM_COPYDATA: Win32.CopyDataStruct st = (Win32.CopyDataStruct)Marshal.PtrToStructure(m.LParam, typeof(Win32.CopyDataStruct)); string strData = Marshal.PtrToStringUni(st.lpData); OpenFile(strData); Activate(); break; default:
It works even when running up to 15 files at a time.
source share