public static extern bool PhysicalToLogicalPoint(NativeMethods.HWND hwnd, ref NativeMethods.POINT pt);
public static extern int GetWindowThreadProcessId(NativeMethods.HWND hWnd, out int lpdwProcessId);
public static extern bool GetWindowPlacement(NativeMethods.HWND hwnd, ref WINDOWPLACEMENT wp);
public static extern int GetWindowLong(NativeMethods.HWND hWnd, int nIndex);
public static extern IntPtr SendMessageTimeout( NativeMethods.HWND hwnd, int Msg, IntPtr wParam, StringBuilder lParam, int flags, int uTimeout, out IntPtr pResult);
public static extern bool PeekMessage( ref MSG msg, NativeMethods.HWND hwnd, int nMsgFilterMin, int nMsgFilterMax, int wRemoveMsg);
public static extern bool IsWindowVisible(NativeMethods.HWND hwnd);
public static extern void SwitchToThisWindow(NativeMethods.HWND hwnd, bool fAltTab);
public static extern bool GetWindowRect(NativeMethods.HWND hwnd, out NativeMethods.RECT rc);
public static extern bool IsWindowEnabled(NativeMethods.HWND hwnd);
public static extern bool GetClientRect(NativeMethods.HWND hwnd, out NativeMethods.RECT rc);
public static extern NativeMethods.HWND GetAncestor(NativeMethods.HWND hwnd, int gaFlags);
public static extern IntPtr SendMessage(NativeMethods.HWND hWnd, int nMsg, IntPtr wParam, StringBuilder lParam);
public static extern bool RegisterHotKey(NativeMethods.HWND hWnd, int id, int fsModifiers, int vk);
public static extern bool IsIconic(NativeMethods.HWND hwnd);
public static extern bool UnregisterHotKey(NativeMethods.HWND hWnd, int id);
public static extern int GetClassName(NativeMethods.HWND hWnd, StringBuilder classname, int nMax);
public static extern IntPtr SendMessageTimeout( NativeMethods.HWND hwnd, int Msg, IntPtr wParam, ref MINMAXINFO lParam, int flags, int uTimeout, out IntPtr pResult);
public static extern int RealGetWindowClass(NativeMethods.HWND hWnd, StringBuilder classname, int nMax);
public static extern int GetMessage( ref MSG msg, NativeMethods.HWND hwnd, int nMsgFilterMin, int nMsgFilterMax);
internal extern static bool IsChild(NativeMethods.HWND parent, NativeMethods.HWND child);
public static extern bool PostMessage( NativeMethods.HWND hWnd, int nMsg, IntPtr wParam, IntPtr lParam);
internal static extern int DwmGetWindowAttribute( NativeMethods.HWND hwnd, int dwAttributeToGet, //DWMWA_* values ref int pvAttributeValue, int cbAttribute);
internal static extern bool SetWindowPos(NativeMethods.HWND hWnd, NativeMethods.HWND hWndInsertAfter, int x, int y, int cx, int cy, int flags);
public HwndTarget(IntPtr hwnd) { bool exceptionThrown = true; AttachToHwnd(hwnd); try { if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordGeneral, EventTrace.Level.Info)) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientCreateVisual, EventTrace.Keyword.KeywordGeneral, EventTrace.Level.Info, Dispatcher.GetHashCode(), hwnd.ToInt64()); } _hWnd = NativeMethods.HWND.Cast(hwnd); // Get the client rectangle... GetWindowRectsInScreenCoordinates(); // Set device independent resolution to 96 DPI. // NativeMethods.HDC hdc = NativeMethods.GetDC(_hWnd); _devicePixelsPerInchX = 96.0f; _devicePixelsPerInchY = 96.0f; _lastWakeOrUnlockEvent = DateTime.MinValue; // // Determine whether hWnd corresponds to MIL or GDI window. // IntPtr hdcW = UnsafeNativeMethods.GetDC( new HandleRef(this, _hWnd)); if (hdcW == IntPtr.Zero) { // // If we were unable to obtain HDC for the given // window, assume the default of 96 DPI. // _devicePixelsPerInchX = 96.0f; _devicePixelsPerInchY = 96.0f; } else { // // Obtain and cache DPI values for window's HDC. // _devicePixelsPerInchX = (double)UnsafeNativeMethods.GetDeviceCaps( new HandleRef(this, hdcW), NativeMethods.LOGPIXELSX); _devicePixelsPerInchY = (double)UnsafeNativeMethods.GetDeviceCaps( new HandleRef(this, hdcW), NativeMethods.LOGPIXELSY); // // Release DC object. // UnsafeNativeMethods.ReleaseDC( new HandleRef(this, _hWnd), new HandleRef(this, hdcW)); } _worldTransform = new MatrixTransform(new Matrix( _devicePixelsPerInchX * (1.0f / 96.0f), 0, 0, _devicePixelsPerInchY * (1.0f / 96.0f), 0, 0)); // // Register CompositionTarget with MediaContext. // MediaContext.RegisterICompositionTarget(Dispatcher, this); // Initialize dispatcher timer to work-around a restore issue. _restoreDT = new DispatcherTimer(); _restoreDT.Tick += new EventHandler(InvalidateSelf); _restoreDT.Interval = TimeSpan.FromMilliseconds(100); exceptionThrown = false; } finally { // // If exception has occurred after we attached this target to // the window, we need to detach from this window. Otherwise, window // will be left in a state when no other HwndTarget can be created // for it. // if(exceptionThrown) { #pragma warning suppress 6031 // Return value ignored on purpose. VisualTarget_DetachFromHwnd(hwnd); } } }