using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class User32 { /// /// Indicates the screen orientation preference for a desktop app process. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ne-winuser-orientation_preference typedef enum ORIENTATION_PREFERENCE // { ORIENTATION_PREFERENCE_NONE, ORIENTATION_PREFERENCE_LANDSCAPE, ORIENTATION_PREFERENCE_PORTRAIT, // ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED, ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED } ; [PInvokeData("winuser.h", MSDNShortId = "7399DD9F-F993-40CC-B9C6-20673D39C069")] [Flags] public enum ORIENTATION_PREFERENCE { /// The process has no device orientation preferences. The system may choose any available setting. ORIENTATION_PREFERENCE_NONE = 0x00, /// The process represents a desktop app that can be used in landscape mode. ORIENTATION_PREFERENCE_LANDSCAPE = 0x01, /// The process represents a desktop app that can be used in portrait mode. ORIENTATION_PREFERENCE_PORTRAIT = 0x02, /// The process represents a desktop app that can be used in flipped landscape mode. ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x04, /// The process represents a desktop app that can be used in flipped portrait mode. ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x08, } /// The ClientToScreen function converts the client-area coordinates of a specified point to screen coordinates. /// A handle to the window whose client area is used for the conversion. /// /// A pointer to a POINT structure that contains the client coordinates to be converted. The new screen coordinates are copied into /// this structure if the function succeeds. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. /// /// /// /// The ClientToScreen function replaces the client-area coordinates in the POINT structure with the screen coordinates. The /// screen coordinates are relative to the upper-left corner of the screen. Note, a screen-coordinate point that is above the /// window's client area has a negative y-coordinate. Similarly, a screen coordinate to the left of a client area has a negative x-coordinate. /// /// All coordinates are device coordinates. /// Examples /// For an example, see "Drawing Lines with the Mouse" in Using Mouse Input. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-clienttoscreen BOOL ClientToScreen( HWND hWnd, LPPOINT // lpPoint ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "3b1e2699-7f5f-444d-9072-f2ca7c8fa511")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ClientToScreen(HWND hWnd, ref POINT lpPoint); /// Retrieves the screen auto-rotation preferences for the current process. /// /// Pointer to a location in memory that will receive the current orientation preference setting for the calling process. /// /// TRUE if the method succeeds, otherwise FALSE. // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdisplayautorotationpreferences BOOL // GetDisplayAutoRotationPreferences( ORIENTATION_PREFERENCE *pOrientation ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "48D609CC-3E2B-4E0E-9566-FE02853DD831")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetDisplayAutoRotationPreferences(out ORIENTATION_PREFERENCE pOrientation); /// /// The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one window to a coordinate space /// relative to another window. /// /// /// A handle to the window from which points are converted. If this parameter is NULL or HWND_DESKTOP, the points are presumed to be /// in screen coordinates. /// /// /// A handle to the window to which points are converted. If this parameter is NULL or HWND_DESKTOP, the points are converted to /// screen coordinates. /// /// /// A pointer to an array of POINT structures that contain the set of points to be converted. The points are in device units. This /// parameter can also point to a RECT structure, in which case the cPoints parameter should be set to 2. /// /// The number of POINT structures in the array pointed to by the lpPoints parameter. /// /// If the function succeeds, the low-order word of the return value is the number of pixels added to the horizontal coordinate of /// each source point in order to compute the horizontal coordinate of each destination point. (In addition to that, if precisely one /// of hWndFrom and hWndTo is mirrored, then each resulting horizontal coordinate is multiplied by -1.) The high-order word is the /// number of pixels added to the vertical coordinate of each source point in order to compute the vertical coordinate of each /// destination point. /// /// If the function fails, the return value is zero. Call SetLastError prior to calling this method to differentiate an error return /// value from a legitimate "0" return value. /// /// [PInvokeData("WinUser.h", MSDNShortId = "")] [DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)] public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, ref RECT lpPoints, uint cPoints = 2); /// /// The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one window to a coordinate space /// relative to another window. /// /// /// A handle to the window from which points are converted. If this parameter is NULL or HWND_DESKTOP, the points are presumed to be /// in screen coordinates. /// /// /// A handle to the window to which points are converted. If this parameter is NULL or HWND_DESKTOP, the points are converted to /// screen coordinates. /// /// /// A pointer to an array of POINT structures that contain the set of points to be converted. The points are in device units. This /// parameter can also point to a RECT structure, in which case the cPoints parameter should be set to 2. /// /// The number of POINT structures in the array pointed to by the lpPoints parameter. /// /// If the function succeeds, the low-order word of the return value is the number of pixels added to the horizontal coordinate of /// each source point in order to compute the horizontal coordinate of each destination point. (In addition to that, if precisely one /// of hWndFrom and hWndTo is mirrored, then each resulting horizontal coordinate is multiplied by -1.) The high-order word is the /// number of pixels added to the vertical coordinate of each source point in order to compute the vertical coordinate of each /// destination point. /// /// If the function fails, the return value is zero. Call SetLastError prior to calling this method to differentiate an error return /// value from a legitimate "0" return value. /// /// [PInvokeData("WinUser.h", MSDNShortId = "")] [DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)] public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, ref POINT lpPoints, uint cPoints = 1); /// /// The MapWindowPoints function converts (maps) a set of points from a coordinate space relative to one window to a coordinate space /// relative to another window. /// /// /// A handle to the window from which points are converted. If this parameter is NULL or HWND_DESKTOP, the points are presumed to be /// in screen coordinates. /// /// /// A handle to the window to which points are converted. If this parameter is NULL or HWND_DESKTOP, the points are converted to /// screen coordinates. /// /// /// A pointer to an array of POINT structures that contain the set of points to be converted. The points are in device units. This /// parameter can also point to a RECT structure, in which case the cPoints parameter should be set to 2. /// /// The number of POINT structures in the array pointed to by the lpPoints parameter. /// /// If the function succeeds, the low-order word of the return value is the number of pixels added to the horizontal coordinate of /// each source point in order to compute the horizontal coordinate of each destination point. (In addition to that, if precisely one /// of hWndFrom and hWndTo is mirrored, then each resulting horizontal coordinate is multiplied by -1.) The high-order word is the /// number of pixels added to the vertical coordinate of each source point in order to compute the vertical coordinate of each /// destination point. /// /// If the function fails, the return value is zero. Call SetLastError prior to calling this method to differentiate an error return /// value from a legitimate "0" return value. /// /// [PInvokeData("WinUser.h", MSDNShortId = "")] [DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)] public static extern int MapWindowPoints(HWND hWndFrom, HWND hWndTo, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] POINT[] lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints); /// The ScreenToClient function converts the screen coordinates of a specified point on the screen to client-area coordinates. /// A handle to the window whose client area will be used for the conversion. /// A pointer to a POINT structure that specifies the screen coordinates to be converted. /// /// If the function succeeds, the return value is true. If the function fails, the return value is false. To get extended error /// information, call GetLastError. /// [DllImport(Lib.User32, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [System.Security.SecurityCritical] public static extern bool ScreenToClient(HWND hWnd, [In, Out] ref POINT lpPoint); /// Sets the orientation preferences of the display. /// The orientation. /// /// Type: BOOL /// If this function set the orientation preferences, the return value is nonzero. /// If the orientation preferences weren't set, the return value is zero. /// /// /// An app can remove the orientation preferences of the display after it sets them by passing ORIENTATION_PREFERENCE_NONE to /// SetDisplayAutoRotationPreferences. An app can change the orientation preferences of the display by passing a different /// combination of ORIENTATION_PREFERENCE-typed values to SetDisplayAutoRotationPreferences. /// // https://docs.microsoft.com/en-us/previous-versions/dn376361(v=vs.85) BOOL WINAPI SetDisplayAutoRotationPreferences( _In_ // ORIENTATION_PREFERENCE orientation ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winuser.h", MSDNShortId = "")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetDisplayAutoRotationPreferences([In] ORIENTATION_PREFERENCE orientation); } }