Click here to Skip to main content
16,021,004 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error: The given path's format is not supported. Pin
Lutosław27-Aug-07 22:36
Lutosław27-Aug-07 22:36 
GeneralRe: Error: The given path's format is not supported. Pin
Martin#27-Aug-07 22:38
Martin#27-Aug-07 22:38 
GeneralRe: Error: The given path's format is not supported. Pin
Vasudevan Deepak Kumar27-Aug-07 23:06
Vasudevan Deepak Kumar27-Aug-07 23:06 
QuestionNo source code available Pin
kbalias27-Aug-07 22:03
kbalias27-Aug-07 22:03 
AnswerRe: No source code available Pin
Vasudevan Deepak Kumar27-Aug-07 22:24
Vasudevan Deepak Kumar27-Aug-07 22:24 
AnswerRe: No source code available Pin
Lutosław27-Aug-07 22:27
Lutosław27-Aug-07 22:27 
QuestionGet external application name Pin
Lilupa27-Aug-07 21:56
Lilupa27-Aug-07 21:56 
AnswerRe: Get external application name [modified] Pin
Martin#27-Aug-07 23:50
Martin#27-Aug-07 23:50 
Hello,

I think the "System.Diagnostics.Process" in combination with "user32.dll" method "IsIconic" could help you.

I did a little test:
First I Import the method from the user32.dll:
[System.Runtime.InteropServices.DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsIconic(IntPtr hWnd);

I declare two ArrayList: one for all processes (with mainwindowhandle), and one for the Procceses which state is Iconic.
using System.Collections;
 
private ArrayList ProcessesWithMainWindow = new ArrayList();
private ArrayList ProcessesIconic = new ArrayList();

Then I have a method which checks all Process.
If the process has a mainwindowhandle, it will be added to a ArrayList for further usage.
Additionally I enable the "EnableRaisingEvents" property of the processes and handle the "Exited" Event.
private void SearchRunningProcesses()
{
	Process[] allRunningProcesses= Process.GetProcesses();
	foreach(Process actProcess in allRunningProcesses)
	{
		if(actProcess.MainWindowHandle!=IntPtr.Zero)
		{
			if(!ProcessesWithMainWindow.Contains(actProcess))
			{
				ProcessesWithMainWindow.Add(actProcess);
				actProcess.EnableRaisingEvents = true;
				actProcess.Exited+=new EventHandler(actProcess_Exited);
			}
		}
		else
		{
			actProcess.Dispose();
		}
	}
}

Then I added a method which validates the Processes inside the "ProcessesWithMainWindow " List, by checking "IsIconic".
If a processes mainwindow is iconic, I add it to the "ProcessesIconic" List.
If it is not iconic but is in the "ProcessesIconic" List, it would mean that the state of the meinwindow has changed and you could show your messagebox there.
private void ValidateProcesses()
{
	foreach(object actObject in ProcessesWithMainWindow)
	{
		Process actProcess = actObject as Process;
		if(actProcess.MainWindowHandle!=IntPtr.Zero)
		{
			if(IsIconic(actProcess.MainWindowHandle))
			{
				if(!ProcessesIconic.Contains(actProcess))
				{
					ProcessesIconic.Add(actProcess);
				}
			}
			else
			{
				if(ProcessesIconic.Contains(actProcess))
				{
					ProcessesIconic.Remove(actProcess);
					//Process was Iconic and is now on an other state
					//You can now show your messagebox here
					//actProcess.ProcessName will give you the Info
				}
			}
		}
	}
}

If the Exited event of a process get's fired, I remove the instance out of the collections, unregister the event and dispose it.
private void actProcess_Exited(object sender, EventArgs e)
{
	Process actProcess = sender as Process;
 
	ProcessesWithMainWindow.Remove(actProcess);
 
	if(ProcessesIconic.Contains(actProcess))
	{
		ProcessesIconic.Remove(actProcess);
	}
	actProcess.Exited-=new EventHandler(actProcess_Exited);
	actProcess.Dispose();
}

You can call the two methods in a tick or elapsed event of a timer.
SearchRunningProcesses();
ValidateProcesses();


Note: I just did a quick test, which means that it might not work under all conditions.

Hope it helps!


-- modified at 6:17 Tuesday 28th August, 2007
actProcess = null;

All the best,

Martin

GeneralRe: Get external application name Pin
Lilupa28-Aug-07 5:59
Lilupa28-Aug-07 5:59 
GeneralRe: Get external application name Pin
Martin#28-Aug-07 6:14
Martin#28-Aug-07 6:14 
QuestionModify the App.Config File at Run Time Pin
BhuMan27-Aug-07 21:48
BhuMan27-Aug-07 21:48 
Questionmemory exception Pin
arkiboys27-Aug-07 21:25
arkiboys27-Aug-07 21:25 
AnswerRe: memory exception Pin
Martin#27-Aug-07 22:25
Martin#27-Aug-07 22:25 
AnswerRe: memory exception Pin
Vasudevan Deepak Kumar27-Aug-07 22:28
Vasudevan Deepak Kumar27-Aug-07 22:28 
AnswerRe: memory exception Pin
Rudolf Jan28-Aug-07 9:05
Rudolf Jan28-Aug-07 9:05 
QuestionSorted List and Garbage Collector Pin
JoZ CaVaLLo27-Aug-07 21:14
JoZ CaVaLLo27-Aug-07 21:14 
AnswerRe: Sorted List and Garbage Collector Pin
Martin#27-Aug-07 22:20
Martin#27-Aug-07 22:20 
GeneralRe: Sorted List and Garbage Collector Pin
Luc Pattyn28-Aug-07 0:54
sitebuilderLuc Pattyn28-Aug-07 0:54 
GeneralRe: Sorted List and Garbage Collector Pin
Martin#28-Aug-07 1:01
Martin#28-Aug-07 1:01 
AnswerRe: Sorted List and Garbage Collector Pin
Luc Pattyn28-Aug-07 0:59
sitebuilderLuc Pattyn28-Aug-07 0:59 
Questionpicture viewer?? Pin
jith - iii27-Aug-07 21:14
jith - iii27-Aug-07 21:14 
AnswerRe: picture viewer?? Pin
Christian Graus27-Aug-07 21:19
protectorChristian Graus27-Aug-07 21:19 
GeneralRe: picture viewer?? [modified] Pin
jith - iii27-Aug-07 22:07
jith - iii27-Aug-07 22:07 
AnswerRe: picture viewer?? Pin
Vasudevan Deepak Kumar27-Aug-07 22:50
Vasudevan Deepak Kumar27-Aug-07 22:50 
GeneralRe: picture viewer?? Pin
jith - iii27-Aug-07 23:54
jith - iii27-Aug-07 23:54 

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.