/// <summary> /// Gets a segment of the desktop as an image. /// </summary> /// <returns>A <see cref="System.Drawing.Image"/> containg an image of the full desktop.</returns> public Image GetDesktopBitmapBg(IntPtr hWnd, bool forcePrintWindow = false, bool forceBitBlt = false) { var rect = new User32.RECT(); User32.GetClientRect(hWnd, ref rect); bool dwmEnabled; DWM.DwmIsCompositionEnabled(out dwmEnabled); if ((!dwmEnabled && !forcePrintWindow) || forceBitBlt) { return(this.GetDesktopBitmap(hWnd, rect)); } var img = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppRgb); using (var g = Graphics.FromImage(img)) { IntPtr dc = g.GetHdc(); // User32.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, User32.RedrawWindowFlags.Frame | User32.RedrawWindowFlags.Invalidate | User32.RedrawWindowFlags.Erase | User32.RedrawWindowFlags.UpdateNow | User32.RedrawWindowFlags.AllChildren); bool success = User32.PrintWindow(hWnd, dc, 1); g.ReleaseHdc(dc); GDI32.DeleteDC(dc); if (!success && !forcePrintWindow) { return(this.GetDesktopBitmap(hWnd, rect)); } if (!forcePrintWindow && img.Width > 64 && img.Height > 64 && img.IsAllBlack()) { return(this.GetDesktopBitmap(hWnd, rect)); } } return(img); }
void ResizeClient( Client c , int x , int y , int w , int h ) { Trace.WriteLine( $"{c.Title} rect : {c.Rect}" ); Rectangle rect = new Rectangle( x , y , x + w , y + h ); DWM.resize( c , rect.Left , rect.Top , rect.Width , rect.Height , ScreenGeom.Rect ); Trace.WriteLine( $"after {c.Title} rect : {c.Rect}" ); }
public void TagSignal(HotKey item) { bool send = ScreenList[0].TagCount < item.ID; string itemID = item.ID.ToString( ); int sentDest = item.ID - ScreenList[0].TagCount; // 同じタグなら変更入らないように if (sentDest.ToString() == SelectedTag) { return; } if (send) { if (ActiveClient != null) { IsDirty = true; DWM.setClientVisibility(ActiveClient, false); CurrentTag.RemoveClient(ActiveClient); Attach(ActiveClient, sentDest.ToString( )); Tile( ); ActiveClient = TryGetMaster( ); } } else { ChangeTag(CurrentTag, itemID); } }
private void SetupWindowArea() { Trace.WriteLine(string.Format("Window frame configuration ({0})", FMUtils.WinApi.Helper.VisualStyle), string.Format("PeekPreview.SetupWindowArea [{0}]", System.Threading.Thread.CurrentThread.Name)); if (FMUtils.WinApi.Helper.VisualStyle == FMUtils.WinApi.Helper.VisualStyles.Aero) { this.BackColor = Color.Black; //if the caption was previously set to an empty string (for Basic) but now we're back to Aero, zero it again this.Text = ""; DWM.Margins GlassMargins; GlassMargins.Top = -1; GlassMargins.Left = -1; GlassMargins.Right = -1; GlassMargins.Bottom = -1; DWM.DwmExtendFrameIntoClientArea(this.Handle, ref GlassMargins); } else { this.BackColor = SystemColors.GradientActiveCaption; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; //need this to get correctly colored non-client area, at the cost of a top title bar margin this.Text = " "; } }
Client Manage( IntPtr hwnd , TileMode tileMode ) { if ( ContainClient( hwnd ) ) { return GetClient( hwnd ); } WindowInfo windowInfo = new WindowInfo( ); User32Methods.GetWindowInfo( hwnd , ref windowInfo ); Client client = CreateClient( hwnd ); if ( tileMode == TileMode.Tile ) { WindowPlacement windowPlacement = new WindowPlacement( ); if ( User32Methods.IsWindowVisible( client.Hwnd ) ) { User32Methods.SetWindowPlacement( hwnd , ref windowPlacement ); } if ( User32Methods.IsWindowVisible( client.Hwnd ) ) { Rectangle windowRect = windowInfo.WindowRect; DWM.resize( client , windowRect.Left , windowRect.Top , windowRect.Width , windowRect.Height , ScreenGeom.Rect ); } } client.TileMode = tileMode; WindowManager.Attach( client , WindowManager.SelectedTag ); return client; }
public static Rectangle GetWindowRectangleDPI(IntPtr handle) { var isMaximized = Helper.IsWindowMazimized(handle); var CurrentScreen = Screen.FromHandle(handle); Rectangle TargetWindowRect = isMaximized ? CurrentScreen.WorkingArea : Helper.GetWindowRectangle(handle); //cf. http://stackoverflow.com/questions/8060280/getting-an-dpi-aware-correct-rect-from-getwindowrect-from-a-external-window Windowing.RECT DPITargetRect = new Windowing.RECT(); DWM.DwmGetWindowAttribute(handle, DWM.DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, out DPITargetRect, (uint)Marshal.SizeOf(DPITargetRect)); DPITargetRect = DPITargetRect.ToRectangle(); if (TargetWindowRect == DPITargetRect) { Trace.WriteLine("Scaling modes are the same, no adjustment necessary.", string.Format("Helper.GetWindowRectangleDPI[{0}]", System.Threading.Thread.CurrentThread.Name)); } else if (TargetWindowRect.Width > DPITargetRect.Width && TargetWindowRect.Height > DPITargetRect.Height) { Trace.WriteLine("Target larger than DPI assessment", string.Format("Helper.GetWindowRectangleDPI[{0}]", System.Threading.Thread.CurrentThread.Name)); } else if (TargetWindowRect.Width < DPITargetRect.Width && TargetWindowRect.Height < DPITargetRect.Height) { Trace.WriteLine("Target smaller than DPI assessment", string.Format("Helper.GetWindowRectangleDPI[{0}]", System.Threading.Thread.CurrentThread.Name)); TargetWindowRect = DPITargetRect; } return(TargetWindowRect); }
public void UnregisterThumbnail() { if (this._spyWindowHandle != IntPtr.Zero) { DWM.DwmUnregisterThumbnail(this._spyWindowHandle); this._spyWindowHandle = IntPtr.Zero; } }
private void UnregisterThumbnail() { if (_thumbnailHandle != IntPtr.Zero) { DWM.DwmUnregisterThumbnail(_thumbnailHandle); _thumbnailHandle = IntPtr.Zero; } }
public void Visible(bool visible) { foreach (var item in ClientList) { DWM.setClientVisibility(item, visible); } ClientsAreVisible = visible; }
private void DrawPreviews() { for (int i = 0; i < windows.Count; i++) { var window = windows[i]; var rectangle = GetRectForIndex(i); DWM.RegisterThumbnails(window.Handle, TaskSwitchForm.Handle, rectangle); } }
private void hideThumbnail() { if (thumbnailHandle != IntPtr.Zero) { DWM.DwmUnregisterThumbnail(thumbnailHandle); thumbnailHandle = IntPtr.Zero; thumbnailForm.Hide(); } }
private Bitmap ScreenshotWindowGDI(IntPtr targetWindow, bool withOpaqueGlass) { Trace.WriteLine(string.Format("Creating screenshot of window {0}: '{1}'...", this.WindowClass, targetWindow), string.Format("Screenshot.ScreenshotWindowGDI [{0}]", System.Threading.Thread.CurrentThread.Name)); Bitmap ss = null; isMaximized = Helper.IsWindowMazimized(targetWindow); //var transparent = new Unmanaged.DWM_COLORIZATION_PARAMS(0x664b968a, 0x664b968a, 0x5, 0x2d, 0x32, 0x32, 0x0); //var opaque = new Unmanaged.DWM_COLORIZATION_PARAMS(0x664b968a, 0x664b968a, 0x28, 0x255, 0x32, 0x32, 0x1); CaptureRect = isMaximized ? this.TargetScreen.WorkingArea : TargetRect; //: BackingWindow.RectangleToScreen(ThumbRect); try { DWM.DWM_COLORIZATION_PARAMS OriginalColorization = Helper.GetColorization(); if (withOpaqueGlass && Helper.isCompositionEnabled && OriginalColorization.OpaqueBlend == 0) { DWM.DWM_COLORIZATION_PARAMS OpaqueColorization = OriginalColorization; OpaqueColorization.OpaqueBlend = 1; OpaqueColorization.ColorBalance = Math.Min(255, OpaqueColorization.ColorBalance * 8); OpaqueColorization.AfterglowBalance = (uint)(OpaqueColorization.AfterglowBalance / 4.5); DWM.DwmSetColorizationParameters(ref OpaqueColorization, 0); ss = Core.ScreenshotWindow(targetWindow); DWM.DwmSetColorizationParameters(ref OriginalColorization, 0); } else { ss = Core.ScreenshotWindow(targetWindow); } } catch (ArgumentException ae) { Trace.WriteLine("Argument Exception: " + ae.GetBaseException().Message); } catch (NullReferenceException nre) { Trace.WriteLine("Null Reference Exception: " + nre.GetBaseException().Message); } finally { ss = ss ?? Core.ScreenshotWindow(targetWindow); } Trace.WriteLine("Done.", string.Format("Screenshot.ScreenshotWindowGDI [{0}]", System.Threading.Thread.CurrentThread.Name)); var debug_path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), @"prosnap-debug"); if (System.IO.Directory.Exists(debug_path)) { ss.Save(System.IO.Path.Combine(debug_path, "raw.png"), System.Drawing.Imaging.ImageFormat.Png); } return(ss); }
private ScreenCaptureHelper() { if (DWM.isDWMEnabled()) { // with DWM Composition disabled the capture goes ~2x faster DWM.DisableComposition(); disabledDWM = true; } }
public override int On進行描画() { if (!base.b活性化してない) { IDirect3DQuery9.Issue(Issue.End); DWM.Flush(); IDirect3DQuery9.GetData <int>(true); // flush GPU queue } return(0); }
public override int OnUpdateAndDraw() { if (!base.bNotActivated) { IDirect3DQuery9.Issue(Issue.End); DWM.Flush(); IDirect3DQuery9.GetData <int>(out _, true); // flush GPU queue } return(0); }
/// <summary> /// Free resources /// </summary> private void Cleanup() { if (hOldObject != IntPtr.Zero && hDCDest != IntPtr.Zero) { // restore selection (old handle) GDI32.SelectObject(hDCDest, hOldObject); GDI32.DeleteDC(hDCDest); } if (hDCDesktop != IntPtr.Zero) { User32.ReleaseDC(hWndDesktop, hDCDesktop); } if (hDIBSection != IntPtr.Zero) { // free up the Bitmap object GDI32.DeleteObject(hDIBSection); } if (disabledDWM) { DWM.EnableComposition(); } if (aviWriter != null) { aviWriter.Dispose(); aviWriter = null; string ffmpegexe = PluginUtils.GetExePath("ffmpeg.exe"); if (ffmpegexe != null) { try { string webMFile = filename.Replace(".avi", ".webm"); string arguments = "-i \"" + filename + "\" -codec:v libvpx -quality good -cpu-used 0 -b:v 1000k -qmin 10 -qmax 42 -maxrate 1000k -bufsize 4000k -threads 4 \"" + webMFile + "\""; LOG.DebugFormat("Starting {0} with arguments {1}", ffmpegexe, arguments); ProcessStartInfo processStartInfo = new ProcessStartInfo(ffmpegexe, arguments); processStartInfo.CreateNoWindow = false; processStartInfo.RedirectStandardOutput = false; processStartInfo.UseShellExecute = false; Process process = Process.Start(processStartInfo); process.WaitForExit(); if (process.ExitCode == 0) { MessageBox.Show("Recording written to " + webMFile); } } catch (Exception ex) { MessageBox.Show("Recording written to " + filename + " couldn't convert due to an error: " + ex.Message); } } else { MessageBox.Show("Recording written to " + filename); } } }
public void CleanUp() { foreach (var tagMan in TagClientDic.Values) { foreach (var client in tagMan.ClientList) { DWM.setClientVisibility(client, true); //User32Methods.MoveWindow( client.Hwnd , client.X , client.Y , client.W , client.H , true ); } } }
public void ShowThumbnail(IntPtr thumbnailHandle) { this.UnregisterThumbnail(); DWM.DwmRegisterThumbnail(this.Handle, thumbnailHandle, out this._spyWindowHandle); if (this._spyWindowHandle != IntPtr.Zero) { DWM.DwmQueryThumbnailSourceSize(this._spyWindowHandle, out SIZE size); DWM.DwmUpdateThumbnailProperties(this._spyWindowHandle, ref _dwm_THUMBNAIL_PROPERTIES); } }
public WindowBase() { this.ContentRendered += delegate { //添加窗口阴影 ShadowWindow.Attach(this); }; if (DWM.IsDwmSupported) { dwmHelper = new DWM(this); dwmHelper.AeroGlassEffectChanged += DwmHelper_AeroGlassEffectChanged; } }
internal static Color GetWindowGlassColor() { try { Trace.WriteLine("Attempting to get DWM color info...", string.Format("Screenshot.Core [{0}]", System.Threading.Thread.CurrentThread.Name)); object RegColor = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\DWM").GetValue("ColorizationColor"); object RegBalance = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\DWM").GetValue("ColorizationColorBalance"); uint RawColor = (uint)(int)RegColor; //http://stackoverflow.com/questions/1085097/why-cant-i-unbox-an-int-as-a-decimal Color glass = Color.FromArgb((byte)((RawColor & 0x00FF0000) >> 16), (byte)((RawColor & 0x0000FF00) >> 8), (byte)(RawColor & 0x000000FF)); double h, s, v; ColorExtensions.ColorToHSV(glass, out h, out s, out v); Color better = ColorExtensions.ColorFromHSV(h, s * ((double)(int)RegBalance) / 85, 1 - ((double)(int)RegBalance / 170)); return(better); } catch (NullReferenceException nre) { Trace.WriteLine(string.Format("That failed: {0}", nre.GetBaseException()), string.Format("Screenshot.Core [{0}]", System.Threading.Thread.CurrentThread.Name)); Trace.WriteLine("Could not extract DWM color info from the registry, trying a direct API call...", string.Format("Screenshot.Core [{0}]", System.Threading.Thread.CurrentThread.Name)); try { uint RawColor; bool opaque; DWM.DwmGetColorizationColor(out RawColor, out opaque); Color glass = Color.FromArgb((byte)((RawColor & 0x00FF0000) >> 16), (byte)((RawColor & 0x0000FF00) >> 8), (byte)(RawColor & 0x000000FF)); double h, s, v; ColorExtensions.ColorToHSV(glass, out h, out s, out v); return(glass); } catch (Exception e) { Trace.WriteLine(string.Format("That failed too: {0}", e.GetBaseException()), string.Format("Screenshot.Core [{0}]", System.Threading.Thread.CurrentThread.Name)); return(Color.Transparent); } } }
private void SetWindowCaptureMode(WindowCaptureMode selectedWindowCaptureMode) { WindowCaptureMode[] availableModes; if (!DWM.IsDwmEnabled()) { // Remove DWM from configuration, as DWM is disabled! if (coreConfiguration.WindowCaptureMode == WindowCaptureMode.Aero || coreConfiguration.WindowCaptureMode == WindowCaptureMode.AeroTransparent) { coreConfiguration.WindowCaptureMode = WindowCaptureMode.GDI; } availableModes = new[] { WindowCaptureMode.Auto, WindowCaptureMode.Screen, WindowCaptureMode.GDI }; } else { availableModes = new[] { WindowCaptureMode.Auto, WindowCaptureMode.Screen, WindowCaptureMode.GDI, WindowCaptureMode.Aero, WindowCaptureMode.AeroTransparent }; } PopulateComboBox(combobox_window_capture_mode, availableModes, selectedWindowCaptureMode); }
/// <summary> /// Show the thumbnail of the supplied window above (or under) the parent Control /// </summary> /// <param name="window">WindowDetails</param> /// <param name="parentControl">Control</param> public void ShowThumbnail(WindowDetails window, Control parentControl) { UnregisterThumbnail(); DWM.DwmRegisterThumbnail(Handle, window.Handle, out _thumbnailHandle); if (_thumbnailHandle != IntPtr.Zero) { SIZE sourceSize; DWM.DwmQueryThumbnailSourceSize(_thumbnailHandle, out sourceSize); int thumbnailHeight = 200; int thumbnailWidth = (int)(thumbnailHeight * (sourceSize.Width / (float)sourceSize.Height)); if (parentControl != null && thumbnailWidth > parentControl.Width) { thumbnailWidth = parentControl.Width; thumbnailHeight = (int)(thumbnailWidth * (sourceSize.Height / (float)sourceSize.Width)); } Width = thumbnailWidth; Height = thumbnailHeight; // Prepare the displaying of the Thumbnail DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES { Opacity = 255, Visible = true, SourceClientAreaOnly = false, Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight) }; DWM.DwmUpdateThumbnailProperties(_thumbnailHandle, ref props); if (parentControl != null) { AlignToControl(parentControl); } if (!Visible) { Show(); } // Make sure it's on "top"! if (parentControl != null) { User32.SetWindowPos(Handle, parentControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE); } } }
public void ShowThumbnail() { this.UnregisterThumbnail(); DWM.DwmRegisterThumbnail(base.Handle, window.Handle, out this._thumbnailHandle); if (this._thumbnailHandle != IntPtr.Zero) { SIZE size; DWM.DwmQueryThumbnailSourceSize(this._thumbnailHandle, out size); DWM.DwmUpdateThumbnailProperties(this._thumbnailHandle, ref dwm_THUMBNAIL_PROPERTIES); if (!base.Visible) { base.Show(); } User32.SetWindowPos(base.Handle, this.Handle, 0, 0, 0, 0, WindowPos.SWP_NOACTIVATE | WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE); } }
public void AddCaptureWindowMenuItems(ToolStripMenuItem menuItem, EventHandler eventHandler) { menuItem.DropDownItems.Clear(); // check if thumbnailPreview is enabled and DWM is enabled bool thumbnailPreview = conf.ThumnailPreview && DWM.isDWMEnabled(); List <WindowDetails> windows = WindowDetails.GetVisibleWindows(); foreach (WindowDetails window in windows) { ToolStripMenuItem captureWindowItem = new ToolStripMenuItem(window.Text); captureWindowItem.Tag = window; captureWindowItem.Image = window.DisplayIcon; captureWindowItem.Click += new System.EventHandler(eventHandler); // Only show preview when enabled if (thumbnailPreview) { captureWindowItem.MouseEnter += new System.EventHandler(ShowThumbnailOnEnter); captureWindowItem.MouseLeave += new System.EventHandler(HideThumbnailOnLeave); } menuItem.DropDownItems.Add(captureWindowItem); } }
public void AddCaptureWindowMenuItems(ToolStripMenuItem menuItem) { menuItem.DropDownItems.Clear(); bool flag = DWM.IsDwmEnabled(); foreach (WindowDetails windowDetails in WindowDetails.GetTopLevelWindows()) { string text = windowDetails.Text; if (text != null) { if (text.Length > 50) { text = text.Substring(0, Math.Min(text.Length, 50)); } ToolStripItem toolStripItem = menuItem.DropDownItems.Add(text); toolStripItem.Tag = windowDetails; toolStripItem.Image = windowDetails.DisplayIcon; if (flag) { toolStripItem.MouseEnter += ShowThumbnailOnEnter; } } } }
private static void Main() { mutex二重起動防止用 = new Mutex(false, "DTXManiaMutex"); if (mutex二重起動防止用.WaitOne(0, false)) { string newLine = Environment.NewLine; bool bDLLnotfound = false; Trace.WriteLine("Current Directory: " + Environment.CurrentDirectory); Trace.WriteLine("EXEのあるフォルダ: " + Path.GetDirectoryName(Application.ExecutablePath)); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; #region [DLLの存在チェック] if (!tDLLの存在チェック("dll\\SlimDX" + CDTXMania.SLIMDXDLL + ".dll", "SlimDX" + CDTXMania.SLIMDXDLL + ".dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "SlimDX" + CDTXMania.SLIMDXDLL + ".dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\FDK.dll", "FDK.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "FDK.dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\xadec.dll", "xadec.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "xadec.dll is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\SoundDecoder.dll", "SoundDecoder.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "SoundDecoder.dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック(CDTXMania.D3DXDLL, CDTXMania.D3DXDLL + " が存在しません。" + newLine + "DirectX Redist フォルダの DXSETUP.exe を実行し、" + newLine + "必要な DirectX ランタイムをインストールしてください。", CDTXMania.D3DXDLL + " is not found." + newLine + "Please execute DXSETUP.exe in \"DirectX Redist\" folder, to install DirectX runtimes required for DTXMania.", true )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\bass.dll", "bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "baas.dll is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\Bass.Net.dll", "Bass.Net.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "Bass.Net.dll is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\bassmix.dll", "bassmix.dll を読み込めません。bassmix.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "bassmix.dll is not loaded. bassmix.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\bassasio.dll", "bassasio.dll を読み込めません。bassasio.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "bassasio.dll is not loaded. bassasio.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\basswasapi.dll", "basswasapi.dll を読み込めません。basswasapi.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "basswasapi.dll is not loaded. basswasapi.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\bass_fx.dll", "bass_fx.dll を読み込めません。bass_fx.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "bass_fx.dll is not loaded. bass_fx.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } if (!tDLLの存在チェック("dll\\DirectShowLib-2005.dll", "DirectShowLib-2005.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "DirectShowLib-2005.dll is not found." + newLine + "Please download DTXMania again." )) { bDLLnotfound = true; } #endregion if (!bDLLnotfound) { #if DEBUG && TEST_ENGLISH Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); #endif DWM.EnableComposition(false); // Disable AeroGrass temporally // BEGIN #23670 2010.11.13 from: キャッチされない例外は放出せずに、ログに詳細を出力する。 // BEGIM #24606 2011.03.08 from: DEBUG 時は例外発生箇所を直接デバッグできるようにするため、例外をキャッチしないようにする。 #if !DEBUG try #endif { using (var mania = new CDTXMania()) mania.Run(); Trace.WriteLine(""); Trace.WriteLine("遊んでくれてありがとう!"); } #if !DEBUG catch (Exception e) { Trace.WriteLine(""); Trace.Write(e.ToString()); Trace.WriteLine(""); Trace.WriteLine("エラーだゴメン!(涙"); AssemblyName asmApp = Assembly.GetExecutingAssembly().GetName(); MessageBox.Show("エラーが発生しました。\n" + "原因がわからない場合は、以下のエラー文を添えて、エラー送信フォームに送信してください。\n" + e.ToString(), asmApp.Name + " Ver." + asmApp.Version.ToString().Substring(0, asmApp.Version.ToString().Length - 2) + " Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // #23670 2011.2.28 yyagi to show error dialog DialogResult result = MessageBox.Show("エラー送信フォームを開きますか?(ブラウザが起動します)", asmApp.Name + " Ver." + asmApp.Version.ToString().Substring(0, asmApp.Version.ToString().Length - 2), MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result == DialogResult.Yes) { Process.Start("" + System.Web.HttpUtility.UrlEncode(e.ToString())); } } #endif // END #24606 2011.03.08 from // END #23670 2010.11.13 from if (Trace.Listeners.Count > 1) { Trace.Listeners.RemoveAt(1); } } // BEGIN #24615 2011.03.09 from: Mutex.WaitOne() が true を返した場合は、Mutex のリリースが必要である。 mutex二重起動防止用.ReleaseMutex(); mutex二重起動防止用 = null; // END #24615 2011.03.09 from } else // DTXManiaが既に起動中 { // → 引数が0個の時はそのまま終了 // 1個( コンパクトモード or DTXV -S) か2個 (DTXV -Nxxx ファイル名)のときは、そのプロセスにコマンドラインを丸々投げて終了する for (int i = 0; i < 5; i++) // 検索結果のハンドルがZeroになることがあるので、200ms間隔で5回リトライする { #region [ 既に起動中のDTXManiaプロセスを検索する。] // このやり方だと、ShowInTaskbar=falseでタスクバーに表示されないパターンの時に検索に失敗するようだが // DTXManiaでそのパターンはない?のでこのままいく。 // FindWindowを使えばこのパターンにも対応できるが、C#でビルドするアプリはウインドウクラス名を自前指定できないので、これは使わない。 Process current = Process.GetCurrentProcess(); Process[] running = Process.GetProcessesByName(current.ProcessName); Process target = null; //IntPtr hWnd = FindWindow( null, "DTXMania .NET style release " + CDTXMania.VERSION ); foreach (Process p in running) { if (p.Id != current.Id) // プロセス名は同じでかつ、プロセスIDが自分自身とは異なるものを探す { if (p.MainModule.FileName == current.MainModule.FileName && p.MainWindowHandle != IntPtr.Zero) { target = p; break; } } } #endregion #region [ 起動中のDTXManiaがいれば、そのプロセスにコマンドラインを投げる ] if (target != null) { string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs != null && commandLineArgs.Length > 1) { string arg = null; for (int j = 1; j < commandLineArgs.Length; j++) { if (j == 1) { arg += commandLineArgs[j]; } else { arg += " " + "\"" + commandLineArgs[j] + "\""; } } //Trace.TraceInformation( "Message=" + arg + ", len(w/o null)=" + arg.Length ); if (arg != null) { FDK.CSendMessage.sendmessage(target.MainWindowHandle, current.MainWindowHandle, arg); } } break; } #endregion else { Trace.TraceInformation("メッセージ送信先のプロセスが見つからず。5回リトライします。"); Thread.Sleep(200); } } } }
public static DWM.DWM_COLORIZATION_PARAMS GetColorization() { DWM.DWM_COLORIZATION_PARAMS colorization = new DWM.DWM_COLORIZATION_PARAMS(); DWM.DwmGetColorizationParameters(out colorization); return(colorization); }
private Bitmap ScreenshotWindowDWM(IntPtr targetWindow, bool withOpaqueGlass) { if (!withOpaqueGlass) { return(Core.ScreenshotWindow(targetWindow)); } Trace.WriteLine(string.Format("Creating screenshot of window {0}: '{1}'...", this.WindowClass, targetWindow), string.Format("Screenshot.ScreenshotWindowDWM [{0}]", System.Threading.Thread.CurrentThread.Name)); ////todo- don't reposition if there's another monitor //var CurrentScreen = Screen.FromHandle(TargetHandle); //TargetWindowRect.X = Math.Max(TargetWindowRect.X, CurrentScreen.WorkingArea.Left); //TargetWindowRect.Y = Math.Max(TargetWindowRect.Y, CurrentScreen.WorkingArea.Top); var DPIScaleFactor = Helper.GetDPIScaleFactor(); var WindowBorderWidth = Helper.GetWindowBorderWidth() * DPIScaleFactor; var BackingPositionRect = isMaximized ? new Rectangle(TargetRect.Left, TargetRect.Top, TargetRect.Width, TargetRect.Height) : new Rectangle(TargetRect.Left, TargetRect.Top, TargetRect.Width, TargetRect.Height); if (Environment.OSVersion.Version.CompareTo(new Version(6, 2)) > 0) { if (Helper.VisualStyle == Helper.VisualStyles.Aero) { BackingPositionRect.X += isMaximized && DPIScaleFactor == 1 ? 0 : 2; BackingPositionRect.Height -= 2; BackingPositionRect.Width -= 4; } } var ThumbRect = new Windowing.RECT(0, 0, BackingPositionRect.Width, BackingPositionRect.Height); if (Environment.OSVersion.Version.CompareTo(new Version(6, 2)) > 0) { if (Helper.VisualStyle == Helper.VisualStyles.Aero) { ThumbRect.Left -= 2; ThumbRect.Right += 2; ThumbRect.Bottom += 2; } } Bitmap screenshot = new Bitmap(1, 1); using (var BackingWindow = new DWMBackingForm(Core.GetWindowGlassColor(), BackingPositionRect)) { try { IntPtr ThumbHandle; var ThumbProps = new DWM.DWM_THUMBNAIL_PROPERTIES() { dwFlags = DWM.DWM_TNP_VISIBLE | DWM.DWM_TNP_RECTDESTINATION | DWM.DWM_TNP_OPACITY, fVisible = true, fSourceClientAreaOnly = true, opacity = (byte)255, rcDestination = ThumbRect }; DWM.DwmRegisterThumbnail(BackingWindow.Handle, targetWindow, out ThumbHandle); DWM.DwmUpdateThumbnailProperties(ThumbHandle, ref ThumbProps); BackingWindow.Disposed += (s, e) => DWM.DwmUnregisterThumbnail(ThumbHandle); BackingWindow.Visible = true; ////Discovered by experimentation //double offset = Math.Floor(7.0 * DPIScaleFactor); //double extra_offset_left = 0; //double extra_offset_top = 0; //switch (Helper.OperatingSystem) //{ // case Helper.OperatingSystems.Win8: // offset = Math.Floor(9.0 * DPIScaleFactor); // extra_offset_left = -3.3 * DPIScaleFactor + (Helper.VisualStyle == Helper.VisualStyles.Aero ? -2 : 0); // extra_offset_top = -3.3 * DPIScaleFactor; // break; //} CaptureRect = isMaximized ? this.TargetScreen.WorkingArea : BackingPositionRect; //: BackingWindow.RectangleToScreen(ThumbRect); //CaptureRect = isMaximized && Helper.HasNonClientBorder(TargetHandle) ? new Rectangle((int)(BackingPositionRect.Left + WindowBorderWidth + offset + extra_offset_left), (int)(BackingPositionRect.Top + WindowBorderWidth + offset + extra_offset_top), (int)(BackingPositionRect.Width - WindowBorderWidth * 2 - offset * 2 - extra_offset_left * 2 - (2 - Math.Floor(DPIScaleFactor))), (int)(BackingPositionRect.Height - WindowBorderWidth * 2 - offset * 2 - extra_offset_top * 2 - (2 - Math.Floor(DPIScaleFactor)))) : BackingPositionRect; screenshot = Core.ScreenshotArea(CaptureRect); BackingWindow.Close(); } catch (Exception e) { //mystery gdi exception when closing the backing form... sometimes... } } Trace.WriteLine("Done.", string.Format("Screenshot.ScreenshotWindowDWM [{0}]", System.Threading.Thread.CurrentThread.Name)); return(screenshot); }
private static void Main() { mutex二重起動防止用 = new Mutex(false, "TJAPlayer3-f"); bool mutexbool = mutex二重起動防止用.WaitOne(0, false); kidou: if (mutexbool) { string newLine = Environment.NewLine; bool bDLLnotfound = false; Trace.WriteLine("Current Directory: " + Environment.CurrentDirectory); Trace.WriteLine("EXEのあるフォルダ: " + Path.GetDirectoryName(Application.ExecutablePath)); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; if (!bDLLnotfound) { #if DEBUG && TEST_ENGLISH Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); #endif DWM.EnableComposition(false); // Disable AeroGrass temporally // BEGIN #23670 2010.11.13 from: キャッチされない例外は放出せずに、ログに詳細を出力する。 // BEGIM #24606 2011.03.08 from: DEBUG 時は例外発生箇所を直接デバッグできるようにするため、例外をキャッチしないようにする。 //2020.04.15 Mr-Ojii DEBUG 時も例外をキャッチするようにした。 try { using (var mania = new TJAPlayer3()) mania.Run(); Trace.WriteLine(""); Trace.WriteLine("遊んでくれてありがとう!"); } catch (Exception e) { Trace.WriteLine(""); Trace.Write(e.ToString()); Trace.WriteLine(""); Trace.WriteLine("エラーだゴメン!(涙"); AssemblyName asmApp = Assembly.GetExecutingAssembly().GetName(); MessageBox.Show("エラーが発生しました。\n" + "原因がわからない場合は、以下のエラー文を添えて、エラー送信フォームに送信してください。\n" + e.ToString(), asmApp.Name + " Ver." + asmApp.Version.ToString().Substring(0, asmApp.Version.ToString().Length - 2) + " Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // #23670 2011.2.28 yyagi to show error dialog DialogResult result = MessageBox.Show("エラー送信フォームを開きますか?(ブラウザが起動します)\n", asmApp.Name + " Ver." + asmApp.Version.ToString().Substring(0, asmApp.Version.ToString().Length - 2), MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result == DialogResult.Yes) { DialogResult result2 = MessageBox.Show("GitHubのエラー送信フォームを開きますか?※GitHubアカウントが必要です。\n\nGoogleのエラー送信フォームを開きますか?※アカウントの必要なし\n\nGitHubのからのエラー報告のほうが「Mr.おじい」が早くエラーの存在に気づけます。\n(Y:GitHub / N:Google)", asmApp.Name + " Ver." + asmApp.Version.ToString().Substring(0, asmApp.Version.ToString().Length - 2), MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result2 == DialogResult.Yes) { Process.Start("https://github.com/Mr-Ojii/TJAPlayer3-f/issues/new?body=エラー文(TJAPlayer3-fから開いた場合は自動入力されます)%0D%0A" + System.Web.HttpUtility.UrlEncode(e.ToString()) + "%0D%0A" + "%0D%0A" + "使用しているスキン名・バージョン%0D%0A" + "%0D%0A" + "%0D%0A" + "バグを引き起こすまでの手順を書いてください%0D%0A" + "%0D%0A" + "%0D%0A" + "再生していた譜面(.tja)または画面%0D%0A" + "%0D%0A" + "%0D%0A" + "使用しているOS%0D%0A" + "%0D%0A" + "%0D%0A" + "不具合の内容%0D%0A" + "%0D%0A" + "%0D%0A" + "(追加情報を自由に書いてください(任意))%0D%0A"); } else { Process.Start("https://docs.google.com/forms/d/e/1FAIpQLSffkhp-3kDJIZH23xMoweik5sAgy2UyaIkEQd1khn9DuR_RWg/viewform?entry.1025217940=" + System.Web.HttpUtility.UrlEncode(e.ToString())); } } } // END #24606 2011.03.08 from // END #23670 2010.11.13 from if (Trace.Listeners.Count > 1) { Trace.Listeners.RemoveAt(1); } } // BEGIN #24615 2011.03.09 from: Mutex.WaitOne() が true を返した場合は、Mutex のリリースが必要である。 mutex二重起動防止用.ReleaseMutex(); mutex二重起動防止用 = null; // END #24615 2011.03.09 from } else // DTXManiaが既に起動中 { DialogResult dr = MessageBox.Show("すでにTJAPlayer3-fが起動していますが、起動しますか?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dr == DialogResult.Yes) { mutexbool = true; goto kidou; } else { Environment.Exit(0); } } }
private static void Main() { mutex二重起動防止用 = new Mutex(false, "DTXManiaMutex"); if (mutex二重起動防止用.WaitOne(0, false)) { string newLine = Environment.NewLine; bool bDllNotFound = false; Trace.WriteLine("Current Directory: " + Environment.CurrentDirectory); Trace.WriteLine("EXEのあるフォルダ: " + Path.GetDirectoryName(Application.ExecutablePath)); Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath); #region [DLL Existence check] if (!tDLLの存在チェック("dll\\FDK.dll", "FDK.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "FDK.dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック(CDTXMania.D3DXDLL, CDTXMania.D3DXDLL + " が存在しません。" + newLine + "DirectX Redist フォルダの DXSETUP.exe を実行し、" + newLine + "必要な DirectX ランタイムをインストールしてください。", CDTXMania.D3DXDLL + " is not found." + newLine + "Please execute DXSETUP.exe in \"DirectX Redist\" folder, to install DirectX runtimes required for DTXMania.", true )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\bass.dll", "bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "baas.dll is not found." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\Bass.Net.dll", "Bass.Net.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "Bass.Net.dll is not found." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\bassmix.dll", "bassmix.dll を読み込めません。bassmix.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "bassmix.dll is not loaded. bassmix.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\bassasio.dll", "bassasio.dll を読み込めません。bassasio.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "bassasio.dll is not loaded. bassasio.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\basswasapi.dll", "basswasapi.dll を読み込めません。basswasapi.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "basswasapi.dll is not loaded. basswasapi.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\bass_fx.dll", "bass_fx.dll を読み込めません。bass_fx.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "bass_fx.dll is not loaded. bass_fx.dll or bass.dll must not exist." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } if (!tDLLの存在チェック("dll\\DirectShowLib-2005.dll", "DirectShowLib-2005.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。", "DirectShowLib-2005.dll is not found." + newLine + "Please download DTXMania again." )) { bDllNotFound = true; } #endregion if (!bDllNotFound) { #if DEBUG && TEST_ENGLISH Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); #endif DWM.EnableComposition(false); // Disable AeroGrass temporally string path = Path.GetDirectoryName(Application.ExecutablePath); /* For future 64bit migration * SetDllDirectory(null); * if (Environment.Is64BitProcess) * { * SetDllDirectory(Path.Combine(path, @"dll\x64")); * } * else */ { SetDllDirectory(Path.Combine(path, @"dll")); } #if !DEBUG try #endif { using (var mania = new CDTXMania()) mania.Run(); Trace.WriteLine(""); Trace.WriteLine("遊んでくれてありがとう!"); } #if !DEBUG catch (Exception e) { Trace.WriteLine(""); Trace.Write(e.ToString()); Trace.WriteLine(""); Trace.WriteLine("エラーだゴメン!(涙"); MessageBox.Show(e.ToString(), "DTXMania Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // #23670 2011.2.28 yyagi to show error dialog } #endif // END #24606 2011.03.08 from // END #23670 2010.11.13 from if (Trace.Listeners.Count > 1) { Trace.Listeners.RemoveAt(1); } } // BEGIN #24615 2011.03.09 from: Mutex.WaitOne() が true を返した場合は、Mutex のリリースが必要である。 mutex二重起動防止用.ReleaseMutex(); mutex二重起動防止用 = null; // END #24615 2011.03.09 from } else // DTXManiaが既に起動中 { // → 引数が0個の時はそのまま終了 // 1個( コンパクトモード or DTXV -S) か2個 (DTXV -Nxxx ファイル名)のときは、そのプロセスにコマンドラインを丸々投げて終了する for (int i = 0; i < 5; i++) // 検索結果のハンドルがZeroになることがあるので、200ms間隔で5回リトライする { #region [ 既に起動中のDTXManiaプロセスを検索する。] // このやり方だと、ShowInTaskbar=falseでタスクバーに表示されないパターンの時に検索に失敗するようだが // DTXManiaでそのパターンはない?のでこのままいく。 // FindWindowを使えばこのパターンにも対応できるが、C#でビルドするアプリはウインドウクラス名を自前指定できないので、これは使わない。 Process current = Process.GetCurrentProcess(); Process[] running = Process.GetProcessesByName(current.ProcessName); Process target = null; //IntPtr hWnd = FindWindow( null, "DTXMania .NET style release " + CDTXMania.VERSION ); foreach (Process p in running) { if (p.Id != current.Id) // プロセス名は同じでかつ、プロセスIDが自分自身とは異なるものを探す { if (p.MainModule.FileName == current.MainModule.FileName && p.MainWindowHandle != IntPtr.Zero) { target = p; break; } } } #endregion #region [ 起動中のDTXManiaがいれば、そのプロセスにコマンドラインを投げる ] if (target != null) { string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs != null && commandLineArgs.Length > 1) { string arg = null; for (int j = 1; j < commandLineArgs.Length; j++) { if (j == 1) { arg += commandLineArgs[j]; } else { arg += " " + "\"" + commandLineArgs[j] + "\""; } } Trace.TraceInformation("Message=" + arg + ", len(w/o null)=" + arg.Length); if (arg != null) { FDK.CSendMessage.sendmessage(target.MainWindowHandle, current.MainWindowHandle, arg); } } break; } #endregion else { Trace.TraceInformation("メッセージ送信先のプロセスが見つからず。5回リトライします。"); Thread.Sleep(200); } } } }