/////////////////////////////////////////////////////////////////////////////////////////// #region Public Methods public ReturnCode Populate( ref bool returnValue, ref Result error ) { try { returnValue = UnsafeNativeMethods.EnumWindows( EnumWindowCallback, IntPtr.Zero); if (!returnValue) { error = NativeOps.GetErrorMessage(); } return(ReturnCode.Ok); } catch (Exception e) { if (traceException) { TraceOps.DebugTrace( e, typeof(WindowOps).Name, TracePriority.NativeError); } error = e; } return(ReturnCode.Error); }
/////////////////////////////////////////////////////////////////////////////////////////////// public static ReturnCode SimulateReturnKey( IntPtr handle, ref Result error ) { try { if (handle != IntPtr.Zero) { UIntPtr virtualKey = new UIntPtr(UnsafeNativeMethods.VK_RETURN); if (UnsafeNativeMethods.PostMessage( handle, UnsafeNativeMethods.WM_KEYDOWN, virtualKey, IntPtr.Zero)) { if (UnsafeNativeMethods.PostMessage( handle, UnsafeNativeMethods.WM_KEYUP, virtualKey, IntPtr.Zero)) { return(ReturnCode.Ok); } } error = NativeOps.GetErrorMessage(); } else { error = "invalid window handle"; } } catch (Exception e) { if (traceException) { TraceOps.DebugTrace( e, typeof(WindowOps).Name, TracePriority.NativeError); } error = e; } return(ReturnCode.Error); }
/////////////////////////////////////////////////////////////////////////////////////////////// public static ReturnCode GetWindowThreadProcessId( IntPtr handle, ref int processId, ref int threadId, ref Result error ) { try { if (handle != IntPtr.Zero) { int localProcessId = 0; int localThreadId = UnsafeNativeMethods.GetWindowThreadProcessId( handle, ref localProcessId); if (localThreadId != 0) { processId = localProcessId; threadId = localThreadId; return(ReturnCode.Ok); } error = NativeOps.GetErrorMessage(); } else { error = "invalid window handle"; } } catch (Exception e) { if (traceException) { TraceOps.DebugTrace( e, typeof(WindowOps).Name, TracePriority.NativeError); } error = e; } return(ReturnCode.Error); }
/////////////////////////////////////////////////////////////////////////////////////////////// public static ReturnCode CloseWindow( IntPtr handle, ref bool returnValue, ref Result error ) { try { if (handle != IntPtr.Zero) { IntPtr result = UnsafeNativeMethods.SendMessage( handle, UnsafeNativeMethods.WM_CLOSE, UIntPtr.Zero, IntPtr.Zero); returnValue = (result == IntPtr.Zero); if (returnValue) { return(ReturnCode.Ok); } else { error = NativeOps.GetErrorMessage(); } } else { error = "invalid window handle"; } } catch (Exception e) { if (traceException) { TraceOps.DebugTrace( e, typeof(WindowOps).Name, TracePriority.NativeError); } error = e; } return(ReturnCode.Error); }
/////////////////////////////////////////////////////////////////////////////////////////////// #if NATIVE && WINDOWS && WINFORMS private static bool HasMessageQueue( int threadId, ref Result error ) { try { if (UnsafeNativeMethods.PostThreadMessage(threadId, UnsafeNativeMethods.WM_NULL, UIntPtr.Zero, IntPtr.Zero)) { return(true); } else { int lastError = Marshal.GetLastWin32Error(); if (lastError == UnsafeNativeMethods.ERROR_INVALID_THREAD_ID) { return(false); } error = NativeOps.GetErrorMessage(lastError); } } catch (Exception e) { if (traceException) { TraceOps.DebugTrace( e, typeof(WindowOps).Name, TracePriority.NativeError); } error = e; } return(false); }
/////////////////////////////////////////////////////////////////////////////////////////////// #if NATIVE && WINDOWS public static ReturnCode GetLastInputTickCount( ref Result result ) { try { UnsafeNativeMethods.LASTINPUTINFO lastInputInfo = new UnsafeNativeMethods.LASTINPUTINFO(); lastInputInfo.cbSize = (uint)Marshal.SizeOf( typeof(UnsafeNativeMethods.LASTINPUTINFO)); if (UnsafeNativeMethods.GetLastInputInfo( ref lastInputInfo)) { result = lastInputInfo.dwTime; return(ReturnCode.Ok); } else { result = NativeOps.GetErrorMessage(); } } catch (Exception e) { if (traceException) { TraceOps.DebugTrace( e, typeof(WindowOps).Name, TracePriority.NativeError); } result = e; } return(ReturnCode.Error); }