pat27

pat27

  • NA
  • 15
  • 0

logg/scan the open windows

Jul 29 2004 4:48 AM
hello, does anybody know how i can scan and/or log in a file, that e.g. for all 5 seconds or when a window opens, it would be logged in a file, which windows are opened?(the title of the window or something else) i need this mechanism for usability tests. i have spoken with a developer of microsoft austria and he gave me the following solution: Enumerating the top-level windows is easy: P/Invoke the EnumWindows native API: [DllImport("user32.dll")]# private static extern bool EnumWindows(EnumWindowsProc proc, IntPtr lParam); private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); [DllImport("user32.dll", CharSet=CharSet.Auto)] private static extern IntPtr GetWindowText(IntPtr hWnd, [Out] string title, IntPtr maxCount); public void EnumWindows() { EnumWindows(new EnumWindowsProc(Callback), IntPtr.Zero); } private bool Callback(IntPtr hWnd, IntPtr lParam) { string title = new string('\0', 260); if (GetWindowText(hWnd, title, 260) != IntPtr.Zero) Log(string.Format("{0:x8}: {1}", hWnd, title); } If instead of windows you want to enumerate all running processes (and perhaps filter those that do not have application windows), you can use Process.GetProcesses and, optionally, check if Process.MainWindowHandle is IntPtr.Zero (not graphical). Responding when a window opens is a bit more tricky. You must efficiently implement a Windows hook and handle the WH_CBT (0x05) message. This message is documented in the Platform SDK along with related APIs like SetWindowsHookEx. The callback (CBTProc) is called whenever a window is about to be activated, created, destroyed, minimized, maximized, moved, or resized (so you'll need to filter these appropriately based on your needs). You can read more about implementing windows hooks in .NET (using the C# language) by reading Using Hooks from C#[^] here on this site. Any questions specific to this article should be directed to the article's message board at the bottom of the page. --------------- i think i need this solution with the Windows Hooks, i also read something in the MSDN about Hooks but unfortunately i do not really look through it. Can anybode explain it to me in a simpler way? - This would be very nice, because it would be very important to me. I looked in the MSDN for Windows Hooks and I think for my problem i need the WH_CBT Hook and the HCBT_ACTIVATE, HCBT_CREATEWND, HCBT_DESTROYWND, HCBT_MINMAX, HCBT_MOVESIZE, HCBT_SYSCOMMAND. With these hooks i can log when a window opens (whereby i do not exactly know the difference between activate and createwnd), a window closes, a window minimizes or maximises and when a command executes. But now if my thoughts are right i miss the practical relation to the c# and how i can implement that. i hope you can give me further help. thanks in advance. yours sincerely, patrick PS: I hope you know that it still concern the event logging of the PDA, where Windows Mobile 2003, Second Edition and the .NET Compact Framework is installed. I thought this method with logging the open windows and so on is the best way to know what the user do with the PDA, because that is what i want to know and this should be logged in any wise.

Answers (2)