Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to create an application, where if the user double on any places on the windows, it will show a messagebox displaying "this is double click".

 

* any places on the windows means desktop, program files, My computer and any places in windows.

 

Please guide me..

George C.K. Low

Posted
first of all, i wanted to catch alll the appplications' name, which are run in the computer. But, i could only find the information about processes and not applications. So, I was thinking on catching the information of application while the user double clicking on it.

George C.K. Low

  • Leaders
Posted

That doesn't sound reliable at all. How are you planning on getting the name of the application after the double-click? By the window it creates? The application isn't even going to be open at the time of the double-click. You don't have a way of knowing how long until the application's main window is displayed, if it will recieve focus when it is shown, etc. If you somehow intercept the filename, you don't know if it is an application (.exe is not the only valid executable extension), a shorcut that might run an application, a batch file that might run an application, etc.

 

Perhaps there is an API that will enumerate applications, or at least top-level windows which you could then filter by something like whether or not they are displayed in the taskbar...

[sIGPIC]e[/sIGPIC]
  • Administrators
Posted

Following is a simple Console application which will enumerate over the open windows and display the handle and caption for each. If you need to do something more complex then you will probably be able to call another API using the provided hWnd parameter in the WindowEnumerator method.

 

The sample calls three API calls to get a result - GetWindowTextLength and GetWindowText to get the caption of the window and EnumWindows to actually get the list of windows.

 

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace EnumerateWindowSample
{
/// 
/// Summary description for Class1.
/// 
class Class1
{
	
	[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
	static extern int GetWindowTextLength(IntPtr hWnd);

	[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
	static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);

	[DllImport("user32.dll")]
	static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
	delegate int EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

	static int WindowEnumerator(IntPtr hWnd, IntPtr lParam)
	{
	int length = GetWindowTextLength(hWnd);
	StringBuilder sb = new StringBuilder(length + 1);
	GetWindowText(hWnd, sb, sb.Capacity);

	Console.WriteLine("Handle {0}, \t Caption {1}", hWnd, sb.ToString());
	return -1;
	}

	/// 
	/// The main entry point for the application.
	/// 
	[sTAThread]
	static void Main(string[] args)
	{
	EnumWindowsProc wp = new EnumWindowsProc(WindowEnumerator);
	EnumWindows(wp, IntPtr.Zero);
	Console.ReadLine();
	}

}
}

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

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...