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

C#

 
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 
hello,

i looked at delegates and TimerCallback and so on, but i don't still look really through it. I tried to write the code but i'm very insecure if this is correct.

I implement a TimeExample Class which calls the timerDelegate which calls the checkWindows method which should check which windows are open.

using System;
using System.Threading;

public class TimeExample
{
public TimeExample()
{
//
// TODO: Add constructor logic here
//
}

public static void Main()
{
AutoResetEvent autoEvent = new AutoResetEvent(false);
WindowsChecker windowsChecker = new WindowsChecker(100);

}

TimerCallback timerDelegate = new TimerCallback(windowsChecker.checkWindows);
Timer stateTimer = new Timer(timerDelegate, autoEvent, 1000, 250);

//autoEvent.WaitOne(5000, false);
//stateTimer.Dispose();
//Console.WriteLine("\nDestroying timer.");
}
--------------------------------------------------------------------------

In the WindowsChecker-class i fill in your code fragment and i defined a checkWindow-method in which should be checked which windows are open and this should be then logged in a file. For now there is only a check about the counter in the checkWindow-Method.

public class WindowsChecker
{

int invokeCount, maxCount;

public WindowsChecker(int count)
{
maxCount = count;
}

[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);
}

public void checkWindows (Object stateInfo)
{
AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
++invokeCount;

if (maxCount==invokeCount)
{
invokeCount = 0;
autoEvent.Set();
}
}
}
----------------------------------------------------------------------------

I hope you can give me any further help? either i'm too stupid to solve this problem or i don't know...Sigh | :sigh:

thanks in advance.

yours sincerely,

patrick
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 3:43
protectorHeath Stewart30-Jul-04 3:43 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 4:58
pat27088130-Jul-04 4:58 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 5:33
protectorHeath Stewart30-Jul-04 5:33 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 6:21
pat27088130-Jul-04 6:21 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 7:30
protectorHeath Stewart30-Jul-04 7:30 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 7:47
pat27088130-Jul-04 7:47 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 8:04
protectorHeath Stewart30-Jul-04 8:04 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 9:17
pat27088130-Jul-04 9:17 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 9:29
protectorHeath Stewart30-Jul-04 9:29 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 9:52
pat27088130-Jul-04 9:52 
GeneralRe: logg/scan open windows - important question! Pin
pat2708812-Aug-04 4:28
pat2708812-Aug-04 4:28 
GeneralError while deploying with the emulator Pin
mathon16-Aug-04 7:53
mathon16-Aug-04 7:53 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 5:43
pat27088129-Jul-04 5:43 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 6:21
protectorHeath Stewart29-Jul-04 6:21 
GeneralA Comprehensive Logging Package for .NET Pin
pat27088128-Jul-04 5:40
pat27088128-Jul-04 5:40 
GeneralRe: A Comprehensive Logging Package for .NET Pin
Heath Stewart28-Jul-04 6:39
protectorHeath Stewart28-Jul-04 6:39 
GeneralRe: A Comprehensive Logging Package for .NET Pin
pat27088128-Jul-04 6:53
pat27088128-Jul-04 6:53 

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.