c# - Pass arguments to running application -
i making image uploader (upload image image hosting website) , i'm having issues passing argument (image location running application)
- first of let's myapp.exe running
- whenever right click on image have added item in default windows context menu says "upload image".
- when that's clicked needs pass location running application.
my program.cs:
static class program { [dllimport("user32.dll")] static extern intptr findwindow(string lpclassname, string lpwindowname); [dllimport("user32.dll")] static extern intptr sendmessage(intptr hwnd, uint msg, uintptr wparam, intptr lparam); [dllimport("user32.dll", setlasterror = true, charset = charset.auto)] static extern uint registerwindowmessage(string lpstring); [stathread] static void main(params string[] arguments) { if (arguments.length > 0) { //this means the upload item in context menu clicked //here method "uploadimage(string location)" //of running application must ran } else { //just start application application.run(new controlpanel()); } } }
note controlpanel class doesn't have visible form, tray icon present since form not needed.
could on how this?
i have figured out, awesome person posted http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/a5bcfc8a-bf69-4bbc-923d-f30f9ecf5f64 link, looking for!
here's full solution:
static class program { [stathread] static void main(params string[] arguments) { singleinstanceapplication.run(new controlpanel(), newinstancehandler); } public static void newinstancehandler(object sender, startupnextinstanceeventargs e) { string imagelocation = e.commandline[1]; messagebox.show(imagelocation); e.bringtoforeground = false; controlpanel.uploadimage(imagelocation); } public class singleinstanceapplication : windowsformsapplicationbase { private singleinstanceapplication() { base.issingleinstance = true; } public static void run(form f, startupnextinstanceeventhandler startuphandler) { singleinstanceapplication app = new singleinstanceapplication(); app.mainform = f; app.startupnextinstance += startuphandler; app.run(environment.getcommandlineargs()); } } }
thanks alot all, , person posted link mentioned above guess deleted answer?
regards, kenny
Comments
Post a Comment