Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

what I really need is not a list of processes running, but a list of applications running ;)

press Ctrl-Alt-Del and see the difference between Processes and Applications .

 

I need to know what documents are open with what programs .

For example :

My Document1.doc - Ms Word,

Metallica - Fade to black - Winamp,

My doc2.rtf - Ms Word,

Question.txt - Notepad,

Xtreme .NET Talk - List of applications running - Microsoft Internet Explorer :) etc

Development & Research Department @ Elven Soft
Posted

though that code will only show the processes that have a mainwindow attached to them. items like Explorer and second and on instances of IE won't show.

 

i recommend that you use the EnumWindows API call in user32.dll and then filter the iwndows that you want.

 

Declarations that you'll need for proper filtering

// delegate declaration used for EnumWindows() callback function
private delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);

// importing the function
[DllImport("user32.dll")] private static extern int EnumWindows(
EnumWindowsProc ewp,	// Callback function
int lParam		// Optional parameter to pass to the callback
); 

// this function helps filter out the Program Manager
[DllImport("user32.dll")] private static extern int GetClassName(      
IntPtr hWnd,				// handle to the window to get the class
System.Text.StringBuilder lpClassName,	// StringBuilder where to store the classname
int nMaxCount				// Max count of characters to retrieve from the classname
);

// this function is to retrieve the window's title
[DllImport("User32.Dll")]private static extern void GetWindowText(
IntPtr h,			// Handle to the window to get the text from
System.Text.StringBuilder s,	// StringBuilder where to store the title
int nMaxCount			// Max count of characters to retrieve from the name
);

// find out if window is visible or hidden
[DllImport("user32.dll")]private static extern bool IsWindowVisible(
IntPtr hWnd		// Handle to the window
);

 

Calling the function

EnumWindows(new EnumWindowsProc(WindowReceived), 0);

 

The filtering being done by the callback

// the EnumWindows filtering the selected windows
private bool WindowReceived(IntPtr hWnd, int lParam)
{
System.Text.StringBuilder class=new System.Text.StringBuilder(256);
GetClassName(hWnd, class, 256);
string WndClass=class.ToString().Trim();

System.Text.StringBuilder title=new System.Text.StringBuilder(256);
GetWindowText(hWnd, title, 256);
string WndTitle=title.ToString().Trim();

RECT r;
GetWindowRect(hWnd, out r);
if(r.right-r.left<=0 || r.bottom-r.top<=0)
	return true;

if(WndTitle!="" && IsWindowVisible(hWnd) && WndClass!="Progman")
{
	// put valid window listing code here
               // always return true on this callback.
               // return false only if you want to stop enumerating
}
return true;
}

 

i think that's about it. simple huh? :P

Menge

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...