Exception GenerateInstallFailureException() { var errorCode = Marshal.GetLastWin32Error(); var existingOwner = clipboardNativeApi.GetClipboardOwner(); var ownerTitle = windowNativeApi.GetWindowTitle(existingOwner); return (new InvalidOperationException( $"Could not install a clipboard hook for the main window. The window '{ownerTitle}' currently owns the clipboard. The last error code was {errorCode}.")); }
public IDataSource GetDataSource() { var activeWindowHandle = windowNativeApi.GetForegroundWindow(); var windowTitle = windowNativeApi.GetWindowTitle(activeWindowHandle); var windowIcon = GetWindowIcon(activeWindowHandle); var iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon); return(new DataSource(iconBytes, windowTitle)); }
public IDataSource GetDataSource() { var activeWindowHandle = windowNativeApi.GetForegroundWindow(); var windowTitle = windowNativeApi.GetWindowTitle(activeWindowHandle); lock (this) { byte[] iconBytes; if (dataSourceIconCache.ContainsKey(activeWindowHandle)) { iconBytes = dataSourceIconCache[activeWindowHandle]; } else { var windowIcon = GetWindowIcon(activeWindowHandle); iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon); dataSourceIconCache.Add(activeWindowHandle, iconBytes); } var dataSource = new DataSource(iconBytes, windowTitle); return(dataSource); } }
public string GetWindowTitleFromWindowHandle(IntPtr handle) { var windowTitle = windowNativeApi.GetWindowTitle(handle); return(windowTitle); }