[Roam-commit] SF.net SVN: roam: [131] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2008-03-27 18:18:10
|
Revision: 131
http://roam.svn.sourceforge.net/roam/?rev=131&view=rev
Author: jonfroehlich
Date: 2008-03-27 11:18:03 -0700 (Thu, 27 Mar 2008)
Log Message:
-----------
1. added StopwatchCe that can be used on the desktop and/or in WM
2. changed SqlCeConnectionManager to use StopwatchCe
3. added GetClassName functionality to WindowUtils
Modified Paths:
--------------
Trunk/Source/Roam.Common/Roam.Common.csproj
Trunk/Source/Roam.SqlCe/SqlCeConnectionManager.cs
Trunk/Source/Roam.UI/Utils/WindowUtils.cs
Added Paths:
-----------
Trunk/Source/Roam.Common/Utils/StopwatchCe.cs
Modified: Trunk/Source/Roam.Common/Roam.Common.csproj
===================================================================
--- Trunk/Source/Roam.Common/Roam.Common.csproj 2008-03-20 21:26:21 UTC (rev 130)
+++ Trunk/Source/Roam.Common/Roam.Common.csproj 2008-03-27 18:18:03 UTC (rev 131)
@@ -81,6 +81,7 @@
<Compile Include="Utils\FileUtils.cs" />
<Compile Include="Utils\ImagingUtils.cs" />
<Compile Include="Utils\MeasurementUtils.cs" />
+ <Compile Include="Utils\StopwatchCe.cs" />
<Compile Include="Utils\SummaryStatistics.cs" />
<Compile Include="Utils\Vector2.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Added: Trunk/Source/Roam.Common/Utils/StopwatchCe.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/StopwatchCe.cs (rev 0)
+++ Trunk/Source/Roam.Common/Utils/StopwatchCe.cs 2008-03-27 18:18:03 UTC (rev 131)
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Roam.Common.Utils
+{
+ public class StopwatchCe
+ {
+ #region Fields
+ private int _startTickCount = 0;
+ private int _accumulatedTicks = 0;
+ private bool _isRunning = false;
+ #endregion Fields
+
+
+ public StopwatchCe()
+ {
+ }
+
+ public TimeSpan Elapsed
+ {
+ get { return TimeSpan.FromMilliseconds(ElapsedMilliseconds); }
+ }
+
+ public long ElapsedMilliseconds
+ {
+ get
+ {
+ return _accumulatedTicks +
+ ((_startTickCount > 0) ?
+ Environment.TickCount - _startTickCount : 0);
+ }
+ }
+
+ public bool IsRunning
+ {
+ get { return _isRunning; }
+ }
+
+ public void Reset()
+ {
+ _startTickCount = 0;
+ _accumulatedTicks = 0;
+ _isRunning = false;
+ }
+
+ //
+ // Summary:
+ // Starts, or resumes, measuring elapsed time for an interval.
+ public void Start()
+ {
+ _isRunning = true;
+ _startTickCount = Environment.TickCount;
+ }
+
+ //
+ // Summary:
+ // Stops measuring elapsed time for an interval.
+ public void Stop()
+ {
+ _isRunning = false;
+ _accumulatedTicks += Environment.TickCount - _startTickCount;
+ _startTickCount = 0;
+ }
+
+ //
+ // Summary:
+ // Initializes a new System.Diagnostics.Stopwatch instance, sets the elapsed
+ // time property to zero, and starts measuring elapsed time.
+ //
+ // Returns:
+ // A System.Diagnostics.Stopwatch that has just begun measuring elapsed time.
+ public static StopwatchCe StartNew()
+ {
+ StopwatchCe stopwatch = new StopwatchCe();
+ stopwatch.Start();
+ return stopwatch;
+ }
+ }
+}
Modified: Trunk/Source/Roam.SqlCe/SqlCeConnectionManager.cs
===================================================================
--- Trunk/Source/Roam.SqlCe/SqlCeConnectionManager.cs 2008-03-20 21:26:21 UTC (rev 130)
+++ Trunk/Source/Roam.SqlCe/SqlCeConnectionManager.cs 2008-03-27 18:18:03 UTC (rev 131)
@@ -107,7 +107,7 @@
/// <param name="connectionString"></param>
public static void Initialize(string connectionString)
{
- Stopwatch sw = Stopwatch.StartNew();
+ StopwatchCe sw = StopwatchCe.StartNew();
lock (_objLock)
{
if (_connectionPool != null)
@@ -384,7 +384,7 @@
{
lock (_objLock)
{
- Stopwatch sw = Stopwatch.StartNew();
+ StopwatchCe sw = StopwatchCe.StartNew();
SqlCeConnection sqlConn;
Thread threadCurrent = Thread.CurrentThread;
@@ -448,7 +448,7 @@
{
lock (_objLock)
{
- Stopwatch sw = Stopwatch.StartNew();
+ StopwatchCe sw = StopwatchCe.StartNew();
Thread threadCurrent = Thread.CurrentThread;
bool returnVal = false;
Modified: Trunk/Source/Roam.UI/Utils/WindowUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/WindowUtils.cs 2008-03-20 21:26:21 UTC (rev 130)
+++ Trunk/Source/Roam.UI/Utils/WindowUtils.cs 2008-03-27 18:18:03 UTC (rev 131)
@@ -211,6 +211,37 @@
}
}
+ public static void PrintWindowHandles(IntPtr hWnd)
+ {
+ string s = GetWindowString(hWnd);
+ Debug.WriteLine(s);
+ IntPtr childHWnd = GetChildWindow(hWnd);
+ if (childHWnd != IntPtr.Zero)
+ {
+ PrintWindowHandles(childHWnd);
+ }
+
+ IntPtr nextHWnd = GetWindow(hWnd, GetWindowConstants.GW_HWNDNEXT);
+ if (nextHWnd != IntPtr.Zero)
+ {
+ PrintWindowHandles(nextHWnd);
+ }
+ }
+
+ private static string GetWindowString(IntPtr hWnd)
+ {
+ string title = GetWindowText(hWnd);
+ string className = GetWindowClassName(hWnd);
+ StringBuilder sb = new StringBuilder();
+ sb.Append("Handle=");
+ sb.Append(string.Format("{0:X2}", hWnd.ToInt32()));
+ sb.Append("|Title=");
+ sb.Append(title);
+ sb.Append("|ClassName=");
+ sb.Append(className);
+ return sb.ToString();
+ }
+
public static void FindAndPrintFocusedControl(Control control)
{
Control controlFocused = FindFocusedControl(control);
@@ -286,6 +317,29 @@
}
/// <summary>
+ /// This function retrieves the name of the class to which the specified window belongs.
+ /// A remote application interface (RAPI) version of this function exists and is called CeGetClassName.
+ /// </summary>
+ /// <param name="hWnd"></param>
+ /// <param name="lpClassName"></param>
+ /// <param name="nMaxCount"></param>
+ /// <returns></returns>
+ [DllImport("coredll.dll", SetLastError = true)]
+ private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
+
+ public static string GetWindowClassName(IntPtr hWnd)
+ {
+ return GetClassName(hWnd, 1000);
+ }
+
+ public static string GetClassName(IntPtr hWnd, int nMaxCount)
+ {
+ StringBuilder sb = new StringBuilder(nMaxCount);
+ GetClassName(hWnd, sb, sb.Capacity);
+ return sb.ToString();
+ }
+
+ /// <summary>
/// The GetWindow function retrieves a handle to a window that has the specified relationship (Z-Order or owner) to the specified window.
/// </summary>
/// <param name="hWnd">[in] Handle to a window. The window handle retrieved is relative to this window, based on the value of the uCmd parameter. </param>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|