georgepatotk Posted May 28, 2005 Posted May 28, 2005 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.. Quote George C.K. Low
Moderators Robby Posted May 28, 2005 Moderators Posted May 28, 2005 why do you want to do that? Quote Visit...Bassic Software
georgepatotk Posted May 30, 2005 Author Posted May 30, 2005 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. Quote George C.K. Low
Leaders snarfblam Posted May 30, 2005 Leaders Posted May 30, 2005 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... Quote [sIGPIC]e[/sIGPIC]
Administrators PlausiblyDamp Posted May 30, 2005 Administrators Posted May 30, 2005 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(); } } } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted May 31, 2005 Author Posted May 31, 2005 thanks, PlausiblyDamp. that's a good guide for me. Quote George C.K. Low
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.