Click here to Skip to main content
15,900,108 members
Home / Discussions / C#
   

C#

 
QuestionEvent that fires on existing form when another is selected Pin
Member 1212588812-Nov-15 9:58
Member 1212588812-Nov-15 9:58 
AnswerRe: Event that fires on existing form when another is selected Pin
Richard Andrew x6412-Nov-15 10:12
professionalRichard Andrew x6412-Nov-15 10:12 
AnswerRe: Event that fires on existing form when another is selected Pin
BillWoodruff12-Nov-15 10:57
professionalBillWoodruff12-Nov-15 10:57 
QuestionHow to design a keypad in C#? Pin
naouf1012-Nov-15 9:34
naouf1012-Nov-15 9:34 
AnswerRe: How to design a keypad in C#? Pin
BillWoodruff12-Nov-15 10:40
professionalBillWoodruff12-Nov-15 10:40 
AnswerRe: How to design a keypad in C#? Pin
Gerry Schmitz13-Nov-15 1:37
mveGerry Schmitz13-Nov-15 1:37 
AnswerRe: How to design a keypad in C#? Pin
GrooverFromHolland13-Nov-15 15:40
GrooverFromHolland13-Nov-15 15:40 
GeneralRe: How to design a keypad in C#? Pin
BillWoodruff14-Nov-15 8:39
professionalBillWoodruff14-Nov-15 8:39 
Generalcreating a packet using c# or vb Pin
Member 1140244512-Nov-15 2:52
Member 1140244512-Nov-15 2:52 
GeneralRe: creating a packet using c# or vb Pin
John Torjo12-Nov-15 3:40
professionalJohn Torjo12-Nov-15 3:40 
GeneralRe: creating a packet using c# or vb Pin
Dave Kreskowiak12-Nov-15 3:53
mveDave Kreskowiak12-Nov-15 3:53 
GeneralRe: creating a packet using c# or vb Pin
Member 1140244512-Nov-15 4:44
Member 1140244512-Nov-15 4:44 
GeneralRe: creating a packet using c# or vb Pin
Gerry Schmitz12-Nov-15 6:57
mveGerry Schmitz12-Nov-15 6:57 
Questionin c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766511-Nov-15 23:08
Member 1212766511-Nov-15 23:08 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Pete O'Hanlon11-Nov-15 23:16
mvePete O'Hanlon11-Nov-15 23:16 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
John Torjo12-Nov-15 2:56
professionalJohn Torjo12-Nov-15 2:56 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Dave Kreskowiak12-Nov-15 4:10
mveDave Kreskowiak12-Nov-15 4:10 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766512-Nov-15 2:58
Member 1212766512-Nov-15 2:58 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Richard Andrew x6412-Nov-15 3:08
professionalRichard Andrew x6412-Nov-15 3:08 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Bernhard Hiller12-Nov-15 4:12
Bernhard Hiller12-Nov-15 4:12 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
BillWoodruff12-Nov-15 5:45
professionalBillWoodruff12-Nov-15 5:45 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
BillWoodruff12-Nov-15 6:03
professionalBillWoodruff12-Nov-15 6:03 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766512-Nov-15 21:26
Member 1212766512-Nov-15 21:26 
Questionrun file with associated extension in current instance (ddeexec?) Pin
robinsc10-Nov-15 9:51
robinsc10-Nov-15 9:51 
AnswerRe: run file with associated extension in current instance (ddeexec?) Pin
John Torjo10-Nov-15 10:21
professionalJohn Torjo10-Nov-15 10:21 
I don't think it's possible. Anyway, long story short - that's not the way to do it.
It's your job to find out if another instance is running, and if so, to notify it. It's not an easy task though. There's quite a bit of code required to do this. Namely, first find out if another instance of your app is running, and if so, you need to notify it and send it the new file to open.

More or less, something like this:

C#
// step 1 - win32 api functions used
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT {
  public IntPtr dwData;
  public int cbData;
  [MarshalAs(UnmanagedType.LPStr)] public string lpData;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);

public const int WM_COPYDATA = 0x004A;

...

// step 2 - in your Main()
var running_already = Process.GetProcessesByName("Yourapp").ToDictionary(x => x.Id, x => x);
running_already.Remove(Process.GetCurrentProcess().Id);
if (running_already.Count > 0) {
    // there's another instance running
    if (args.Length == 0)
        // just let the other instance run
        return;
    // for the other instance - what to open
    string open = args[0];

    var cds = new win32.COPYDATASTRUCT {
        dwData = new IntPtr(0),
        cbData = open.Length * 2 + 1,
        lpData = open
    };
    var handle = running_already.First().Value.MainWindowHandle;
    win32.SendMessage(handle, win32.WM_COPYDATA, IntPtr.Zero, ref cds);
    return;
}

// step 3 - in your main window
protected override void WndProc(ref Message m) {
	if (m.Msg == win32.WM_COPYDATA) {
		var st = (win32.COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof (win32.COPYDATASTRUCT));
		string open = st.lpData;
		util.postpone(() => on_file_drop(open), 100);
	}

	base.WndProc(ref m);
}

-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.