Click here to Skip to main content
15,894,405 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I create a dynamic webservice client in C# Pin
Nick Parker29-Jul-04 8:45
protectorNick Parker29-Jul-04 8:45 
GeneralWMI Windows Service Pin
silverbullet28-Jul-04 9:12
silverbullet28-Jul-04 9:12 
GeneralRe: WMI Windows Service Pin
Heath Stewart28-Jul-04 10:10
protectorHeath Stewart28-Jul-04 10:10 
QuestionHow do I disconnect my crystal report from it's datasource Pin
kornstyle28-Jul-04 8:24
kornstyle28-Jul-04 8:24 
AnswerRe: How do I disconnect my crystal report from it's datasource Pin
Heath Stewart28-Jul-04 8:50
protectorHeath Stewart28-Jul-04 8:50 
Generallogg/scan open windows Pin
pat27088128-Jul-04 6:25
pat27088128-Jul-04 6:25 
GeneralRe: logg/scan open windows Pin
pat27088128-Jul-04 6:55
pat27088128-Jul-04 6:55 
GeneralRe: logg/scan open windows Pin
Heath Stewart28-Jul-04 7:04
protectorHeath Stewart28-Jul-04 7:04 
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.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: logg/scan open windows Pin
pat27088128-Jul-04 7:41
pat27088128-Jul-04 7:41 
GeneralRe: logg/scan open windows Pin
Nick Parker28-Jul-04 8:11
protectorNick Parker28-Jul-04 8:11 
GeneralRe: logg/scan open windows Pin
pat27088128-Jul-04 8:23
pat27088128-Jul-04 8:23 
GeneralRe: logg/scan open windows Pin
Nick Parker28-Jul-04 8:33
protectorNick Parker28-Jul-04 8:33 
GeneralRe: logg/scan open windows Pin
pat27088128-Jul-04 11:25
pat27088128-Jul-04 11:25 
GeneralRe: logg/scan open windows Pin
pat27088128-Jul-04 23:01
pat27088128-Jul-04 23:01 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 3:04
pat27088129-Jul-04 3:04 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 4:30
protectorHeath Stewart29-Jul-04 4:30 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 4:49
pat27088129-Jul-04 4:49 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 5:46
protectorHeath Stewart29-Jul-04 5:46 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 6:46
pat27088129-Jul-04 6:46 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 6:49
protectorHeath Stewart29-Jul-04 6:49 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 7:45
pat27088129-Jul-04 7:45 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 9:09
protectorHeath Stewart29-Jul-04 9:09 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 10:27
pat27088129-Jul-04 10:27 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 10:48
protectorHeath Stewart29-Jul-04 10:48 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 0:39
pat27088130-Jul-04 0:39 

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.