|
 |
|
|
 |
|
|
I am a newbi to this stuff, but is there any easy way to get this working on Compact Framework
Best Regards Mikael
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
This solution works for me
public class ThisApp : Form { private const int WM_ACTIVATE = 0x0006; private const int WA_ACTIVE = 1;
public static void Main(string[] args) { IntPtr prevInstance = FindWindow(IntPtr.Zero, "This app name"); // this will find also hidden forms if (prevInstance != IntPtr.Zero) PostMessage(prevInstance, WM_ACTIVATE, WA_ACTIVE, 0); else Application.Run(new ThisApp()); }
public ThisApp() { loaded = false; // do initialization here loaded = true; }
protected override void OnActivated(EventArgs e) { if (loaded) { // do what you want to do if somebody runs this app again (eg. Visible = true; etc.) }
base.OnActivated(e); }
[DllImport("coredll.dll", SetLastError=true)] private static extern int PostMessage(IntPtr hWnd, int nMsg, int wParam, int lParam);
[DllImport("coredll.dll", SetLastError=true)] private static extern IntPtr FindWindow(IntPtr wClass, string title); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I saw the unanswared question and I still needs it. Anyone knows what can be done to show an application that is hidden in the notification area? Is there a way to raise an event on this application and hande it?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
With stuff like remote desktop you could have multiple user using on different location running on the same PC.
thus user A could bring windows of user B and fail it launch on his desktop, if you see what I mean.
What do you think of that? Any work around?.... maybe this new SessionId in 2.0 ?....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
hi,
Anybody try to change the name of the application. Suppose the app name is "abc.exe", I copy this one into another place and named "ac.exe". For the code uses GetProcessByName, there is always 1 item in array, and 2 instance of 2 1-code-base-but-different-name-app instances. I've looked at another solution that using GetProcessByID and also do simple test by running abc.exe and ac.exe, 2 instance create 2 different process id. It seems a solution that assign a specific process id when create instance (i didn't try) but it sounds bad. Using MainWindowHandle, do you mean to get the handle of the main window of the app (as documented: "Gets the window handle of the main window of the associated process")? What if my app does not start by create an instance of a form but I have some initialization before. I mean, if get the handle of the window, it's too late for I initialize my variables (or something else) before. Any solution for this? (Sorry for my poor English )
wdyl
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hello,
In addition to bringing the application into the foreground I need the window to be "active". Specifically, my form hosts a WebBrowser control and has a page up. The HTML components on the page can be navigated using the arrow keys (from a keyboard or those on an infrared remote control) to go from one component to the next. I need the control selected in order for this to work and I've tried everying (well, everything I could think of).
The only way I have been able to activate it is to click on it with a mouse and I need to avoid that as I use the infrared remote control to move around the page and interact with it.
Can anyone help?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi,
There is an easier way to detect single instance by using a Mutex.
Example code (c#)
bool wasCreated; Mutex MyMutex = new Mutex(true,"myappshouldrunonce",out wasCreated); if (!wasCreated) { return; }
// .. continue with app as planned
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Guido_d wrote: There is an easier way to detect single instance by using a Mutex.
Functionally, this is different. The code I presented brings the other application to the foreground. The code you suggest simply exits the current application. Imagine the deluge of technical support calls "I keep clicking on the icon, and nothing happens!" Even a "this application is already open" message is a sad excuse--if the program can detect that the same app is running, then why not help the user out a bit?
This is the difference between programmer oriented thinking and user oriented thinking--sure, your code is easier for the programmer, but it isn't easier for the user.
Marc
Latest AAL Article My blog Join my forum!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
In my app(just like yahoo/msn messenger) i hide the window when the user minimises, so when he he tries to open a new instance "processes[n].MainWindowHandle" will always return 0...
Any easy solution for this ???????
right now i do a Findwindow then do a sendmessage "SendMessage(FindWindow(0,"My app"),786,0,0);" then do a override of winproc , capture the message and do a .Show() there
Regards, Neo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Extracted from MSDN Library:
You can get the MainWindowHandle property only for processes that are running on the local computer. The MainWindowHandle property is a value that uniquely identifies the window that is associated with the process.
A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window, the MainWindowHandle value is zero.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
First of all thanks for a great article that clearly explains how to solve the presented problem. I've implemented the code in a real life solution and thereby came across the following problem.
There is a slight problem with the Process class when the name of the process exeeds 15 characters. Process.ProcessName wil only return the first 15 characters of the name, but passing these 15 characters to Process.GetProcessesByName wil return no processes as this method needs the full name.
As far as I'm able to see the only solution to the problem is to keep the name of the process below 15 characters.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Your code is now included in RSS Bandit 1.0d. 
Added code to ensure that only one instance of RSS Bandit can be launched at a given time. Used code from http://www.codeproject.com/csharp/oneProcessOnly.asp
RSS Bandit[^]
Don't and drive.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello all highly friends
The article is very good, but I have a small question If I close the application but it doesn't exit completely. It just goes to the right of the task bar. And then I had made a new proccess with the same application, of course it didn't make a new proccess but the application doesn't restore So how can I restore it?
Thanks alot for your reading 
Qui
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
public class ProcessRunning { public ProcessRunning(){}
public static void InstanceCheck() { // get the name of our process string proc=Process.GetCurrentProcess().ProcessName; // get the list of all processes by that name Process[] processes=Process.GetProcessesByName(proc); // if there is more than one process... if (processes.Length > 1) { // get our process Process p=Process.GetCurrentProcess(); if(MessageBox.Show("There is already another instance of this app Running, Would you like to end it and Contine with this one?","App already Running",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes) { //Loop throught and kill the other processes for(int j=0;j { //Kill the processes if (processes[j].Id!=p.Id) processes[j].Kill(); } } else { //Loop throught and kill the other processes for(int j=0;j { //Kill the processes if (processes[j].Id == p.Id) processes[j].Kill(); } } }
} }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Yes, this is a good idea for certain applications where it would be wierd to simply pop up an already running app. I guess I wanted to leave this option to the specific programmer's requirement, instead of hardcoding it in this class. Of course, what I really should have done is made this into a function that returns a bool indicating whether the app is already running!
Marc
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
right -- this is a great solution! I have some apps that only run in UI mode if they are not scheduled. And now I can kill the scheduled app if it is running and let the IT admins run the app manually when necessary.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |