Skip to content

Commit

Permalink
Cleanup PRF_ constants (dotnet#2792)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughbe authored Feb 3, 2020
1 parent e021dc7 commit 106bd36
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit 106bd36

Please sign in to comment.