From 106bd36fce0e5fafefdd56bc749c4e525459b7ec Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Mon, 3 Feb 2020 06:15:12 +0000 Subject: [PATCH] Cleanup PRF_ constants (#2792) --- .../Windows/Forms/Design/DesignerUtils.cs | 2 +- .../src/Interop/User32/Interop.PRF.cs | 22 +++++++++++++++++++ .../Windows/Forms/Internals/NativeMethods.cs | 6 +---- .../src/System/Windows/Forms/ComboBox.cs | 2 +- .../Windows/Forms/Control.ActiveXImpl.cs | 6 +---- .../src/System/Windows/Forms/Control.cs | 14 ++++++------ .../src/System/Windows/Forms/ListBox.cs | 2 +- .../src/System/Windows/Forms/ListView.cs | 2 +- .../src/System/Windows/Forms/MaskedTextBox.cs | 2 +- .../src/System/Windows/Forms/TextBox.cs | 2 +- .../src/System/Windows/Forms/ToolStrip.cs | 2 +- .../src/System/Windows/Forms/TreeView.cs | 2 +- 12 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.PRF.cs diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs index 645c715d707..6379d1e5cfd 100644 --- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs +++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs @@ -514,7 +514,7 @@ public static bool GenerateSnapShotWithWM_PRINT(Control control, ref Image image { IntPtr hDc = g.GetHdc(); //send the actual wm_print message - User32.SendMessageW(hWnd, User32.WM.PRINT, hDc, (IntPtr)(NativeMethods.PRF_CHILDREN | NativeMethods.PRF_CLIENT | NativeMethods.PRF_ERASEBKGND | NativeMethods.PRF_NONCLIENT)); + User32.SendMessageW(hWnd, User32.WM.PRINT, hDc, (IntPtr)(User32.PRF.CHILDREN | User32.PRF.CLIENT | User32.PRF.ERASEBKGND | User32.PRF.NONCLIENT)); g.ReleaseHdc(hDc); } diff --git a/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.PRF.cs b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.PRF.cs new file mode 100644 index 00000000000..46c2a8c489b --- /dev/null +++ b/src/System.Windows.Forms.Primitives/src/Interop/User32/Interop.PRF.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +internal static partial class Interop +{ + internal static partial class User32 + { + [Flags] + public enum PRF : uint + { + CHECKVISIBLE = 0x00000001, + NONCLIENT = 0x00000002, + CLIENT = 0x00000004, + ERASEBKGND = 0x00000008, + CHILDREN = 0x00000010, + OWNED = 0x00000020, + } + } +} diff --git a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs index 6105ec6a5c4..773c255270b 100644 --- a/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs +++ b/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/NativeMethods.cs @@ -136,11 +136,7 @@ public static uint MAKELCID(uint lgid, uint sort) NFR_ANSI = 1, NFR_UNICODE = 2; - public const int PRF_CHECKVISIBLE = 0x00000001, - PRF_NONCLIENT = 0x00000002, - PRF_CLIENT = 0x00000004, - PRF_ERASEBKGND = 0x00000008, - PRF_CHILDREN = 0x00000010, + public const int PATCOPY = 0x00F00021, PATINVERT = 0x005A0049; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs index be8d2de69db..5824891bfff 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs @@ -3953,7 +3953,7 @@ protected override void WndProc(ref Message m) { DefWndProc(ref m); - if ((unchecked((int)(long)m.LParam) & NativeMethods.PRF_CLIENT) == NativeMethods.PRF_CLIENT) + if ((unchecked((PRF)(long)m.LParam) & PRF.CLIENT) == PRF.CLIENT) { if (!GetStyle(ControlStyles.UserPaint) && (FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup)) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs index 46254a87e58..f1ec9c73ba4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.ActiveXImpl.cs @@ -485,11 +485,7 @@ internal unsafe HRESULT Draw( // Now do the actual drawing. We must ask all of our children to draw as well. try { - IntPtr flags = (IntPtr)(NativeMethods.PRF_CHILDREN - | NativeMethods.PRF_CLIENT - | NativeMethods.PRF_ERASEBKGND - | NativeMethods.PRF_NONCLIENT); - + IntPtr flags = (IntPtr)(User32.PRF.CHILDREN | User32.PRF.CLIENT | User32.PRF.ERASEBKGND | User32.PRF.NONCLIENT); if (hdcType != Gdi32.ObjectType.OBJ_ENHMETADC) { User32.SendMessageW(_control, User32.WM.PRINT, hdcDraw, flags); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index 093ddee4c96..d93fd078f27 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -5335,7 +5335,7 @@ public void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds) this, User32.WM.PRINT, (IntPtr)hDc, - (IntPtr)(NativeMethods.PRF_CHILDREN | NativeMethods.PRF_CLIENT | NativeMethods.PRF_ERASEBKGND | NativeMethods.PRF_NONCLIENT)); + (IntPtr)(User32.PRF.CHILDREN | User32.PRF.CLIENT | User32.PRF.ERASEBKGND | User32.PRF.NONCLIENT)); //now BLT the result to the destination bitmap. using (Graphics destGraphics = Graphics.FromImage(bitmap)) @@ -7587,7 +7587,7 @@ protected virtual void OnPrint(PaintEventArgs e) if (!(e is PrintPaintEventArgs ppev)) { - IntPtr flags = (IntPtr)(NativeMethods.PRF_CHILDREN | NativeMethods.PRF_CLIENT | NativeMethods.PRF_ERASEBKGND | NativeMethods.PRF_NONCLIENT); + IntPtr flags = (IntPtr)(User32.PRF.CHILDREN | User32.PRF.CLIENT | User32.PRF.ERASEBKGND | User32.PRF.NONCLIENT); hdc = e.HDC; if (hdc == IntPtr.Zero) @@ -9241,11 +9241,11 @@ private void PrintToMetaFile(IntPtr hDC, IntPtr lParam) { Debug.Assert(Gdi32.GetObjectType(hDC) == Gdi32.ObjectType.OBJ_ENHMETADC, "PrintToMetaFile() called with a non-Enhanced MetaFile DC."); - Debug.Assert(((long)lParam & NativeMethods.PRF_CHILDREN) != 0, + Debug.Assert(((long)lParam & (long)User32.PRF.CHILDREN) != 0, "PrintToMetaFile() called without PRF_CHILDREN."); // Strip the PRF_CHILDREN flag. We will manually walk our children and print them. - lParam = (IntPtr)((long)lParam & ~NativeMethods.PRF_CHILDREN); + lParam = (IntPtr)((long)lParam & (long)~User32.PRF.CHILDREN); // We're the root control, so we need to set up our clipping region. Retrieve the // x-coordinates and y-coordinates of the viewport origin for the specified device context. @@ -9279,7 +9279,7 @@ private protected virtual void PrintToMetaFileRecursive(IntPtr hDC, IntPtr lPara using (DCMapping mapping = new DCMapping(hDC, bounds)) { // print the non-client area - PrintToMetaFile_SendPrintMessage(hDC, (IntPtr)((long)lParam & ~NativeMethods.PRF_CLIENT)); + PrintToMetaFile_SendPrintMessage(hDC, (IntPtr)((long)lParam & (long)~User32.PRF.CLIENT)); // figure out mapping for the client area RECT windowRect = new RECT(); @@ -9292,7 +9292,7 @@ private protected virtual void PrintToMetaFileRecursive(IntPtr hDC, IntPtr lPara using (DCMapping clientMapping = new DCMapping(hDC, clientBounds)) { // print the client area - PrintToMetaFile_SendPrintMessage(hDC, (IntPtr)((long)lParam & ~NativeMethods.PRF_NONCLIENT)); + PrintToMetaFile_SendPrintMessage(hDC, (IntPtr)((long)lParam & (long)~User32.PRF.NONCLIENT)); // Paint children in reverse Z-Order int count = Controls.Count; @@ -9323,7 +9323,7 @@ private void PrintToMetaFile_SendPrintMessage(IntPtr hDC, IntPtr lParam) // good example. if (Controls.Count == 0) { - lParam = (IntPtr)((long)lParam | NativeMethods.PRF_CHILDREN); + lParam = (IntPtr)((long)lParam | (long)User32.PRF.CHILDREN); } // System controls must be painted into a temporary bitmap diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs index 8a8f361b93e..2dbd8547d52 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListBox.cs @@ -2420,7 +2420,7 @@ private unsafe void UpdateCustomTabOffsets() private void WmPrint(ref Message m) { base.WndProc(ref m); - if ((NativeMethods.PRF_NONCLIENT & (int)m.LParam) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) + if (((PRF)m.LParam & PRF.NONCLIENT) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) { using (Graphics g = Graphics.FromHdc(m.WParam)) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs index 6e7379842dd..8ce0d6f605c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs @@ -6419,7 +6419,7 @@ private unsafe void WmReflectNotify(ref Message m) private void WmPrint(ref Message m) { base.WndProc(ref m); - if ((NativeMethods.PRF_NONCLIENT & (int)m.LParam) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) + if (((User32.PRF)m.LParam & User32.PRF.NONCLIENT) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) { using (Graphics g = Graphics.FromHdc(m.WParam)) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/MaskedTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/MaskedTextBox.cs index 2d375641d9e..ca7ee927898 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/MaskedTextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/MaskedTextBox.cs @@ -3009,7 +3009,7 @@ private void WmPaste() private void WmPrint(ref Message m) { base.WndProc(ref m); - if ((NativeMethods.PRF_NONCLIENT & unchecked((int)(long)m.LParam)) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) + if ((unchecked((User32.PRF)(long)m.LParam) & User32.PRF.NONCLIENT) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) { using (Graphics g = Graphics.FromHdc(m.WParam)) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TextBox.cs index e9d7c178da7..21d7ba7c5d4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TextBox.cs @@ -837,7 +837,7 @@ private void ResetAutoCompleteCustomSource() private void WmPrint(ref Message m) { base.WndProc(ref m); - if ((NativeMethods.PRF_NONCLIENT & (int)m.LParam) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) + if (((PRF)m.LParam & PRF.NONCLIENT) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) { using (Graphics g = Graphics.FromHdc(m.WParam)) { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs index 652fa5f9ee0..629d7b73eb8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolStrip.cs @@ -3017,7 +3017,7 @@ private protected override void PrintToMetaFileRecursive(IntPtr hDC, IntPtr lPar this, User32.WM.PRINT, (IntPtr)imageHdc, - (IntPtr)(NativeMethods.PRF_CHILDREN | NativeMethods.PRF_CLIENT | NativeMethods.PRF_ERASEBKGND | NativeMethods.PRF_NONCLIENT)); + (IntPtr)(User32.PRF.CHILDREN | User32.PRF.CLIENT | User32.PRF.ERASEBKGND | User32.PRF.NONCLIENT)); // Now BLT the result to the destination bitmap. Gdi32.BitBlt( diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs index 6a5d7b2c8f8..f4f196b6bb8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs @@ -3155,7 +3155,7 @@ private void WmPrint(ref Message m) { base.WndProc(ref m); - if ((NativeMethods.PRF_NONCLIENT & (int)m.LParam) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) + if (((User32.PRF)m.LParam & User32.PRF.NONCLIENT) != 0 && Application.RenderWithVisualStyles && BorderStyle == BorderStyle.Fixed3D) { using (Graphics g = Graphics.FromHdc(m.WParam)) {