/// <summary> /// 获取指定窗口的设备上下文句柄 /// </summary> /// <param name="hwnd">将获取其设备场景的窗口的句柄。若为 0,则要获取整个屏幕的DC</param> /// <returns><see cref="NativeApiResult{IntPtr}.Result"/>指定窗口的设备上下文的句柄,出错则为 0</returns> public static NativeApiResult <IntPtr> GetDC(IntPtr hwnd) { NativeApiResult <IntPtr> result = null; var dcIntPtr = GetDCNative(hwnd); var errorCode = NativeApiResult.GetLastError(); result = new NativeApiResult <IntPtr>(dcIntPtr, errorCode); return(result); }
/// <summary> /// 使用指定的新值替换指定窗口的有关信息 /// </summary> /// <param name="hWnd">窗口的句柄</param> /// <param name="type">设置的信息的类型</param> /// <param name="newValue">新的值</param> /// <returns><see cref="NativeApiResult{Int32}.Result"/> 值表示替换前的值</returns> public static NativeApiResult <Int32> SetWindowLong(IntPtr hWnd, WindowsLongType type, Int32 newValue) { NativeApiResult <Int32> result = null; var value = SetWindowLongNative(hWnd, (Int32)type, (Int32)newValue); var errorCode = NativeApiResult.GetLastError(); result = new NativeApiResult <Int32>(value, errorCode); return(result); }
/// <summary> /// 释放由 <see cref="GetDC(IntPtr)"/> 函数获取的上下文句柄关联的资源 /// </summary> /// <param name="hwnd">窗体的句柄</param> /// <param name="hdc">上下文的句柄</param> /// <returns><see cref="NativeApiResult{Int32}.Result"/>执行成功为1,否则为 0</returns> public static NativeApiResult <Int32> ReleaseDC(IntPtr hwnd, IntPtr hdc) { NativeApiResult <Int32> result = null; var releaseResult = ReleaseDCNative(hwnd, hdc); var errorCode = NativeApiResult.GetLastError(); result = NativeApiResult.Create(releaseResult, errorCode); return(result); }
/// <summary> /// 设置进程 Dpi 感知的类型, /// 此函数在 Windows Vista 以及以上的系统中受支持, /// 否则调用无效,返回 <see cref="LastErrorCode.UnKnown"/> 未知错误的结果。 /// </summary> public static NativeApiResult <Int32> SetProcessDpiAwareness(ProcessDPIAwareness dpiAwarenessValue) { NativeApiResult <Int32> result = null; if (Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 2) { var setResult = SetProcessDpiAwarenessNative((Int32)dpiAwarenessValue); result = NativeApiResult.Create(setResult, NativeApiResult.GetLastError()); } else { result = NativeApiResult.Create(-1, (Int32)LastErrorCode.UnKnown); } return(result); }
/// <summary> /// 获取指定设备上下文中具体位置上的像素信息 /// </summary> /// <param name="hdc">设备上下文的句柄</param> /// <param name="nXPos">像素点的横向坐标</param> /// <param name="nYPos">像素点的纵向坐标</param> /// <returns>结果1 表示尝试转换的颜色信息对象,结果2 表示原始的像素信息</returns> public static NativeApiResult <Color?, UInt32> GetPixel(IntPtr hdc, Int32 nXPos, Int32 nYPos) { NativeApiResult <Color?, UInt32> result = null; Color?color = null; var pixel = GetPixelNative(hdc, nXPos, nYPos); var errorCode = NativeApiResult.GetLastError(); if (errorCode == (Int32)LastErrorCode.Normal) { // color= Color.FromArgb((Int32)pixel); color = Color.FromArgb( // (Int32)(pixel & 0xFF000000) >> 24, (Int32)(pixel & 0x000000FF), (Int32)(pixel & 0x0000FF00) >> 8, (Int32)(pixel & 0x00FF0000) >> 16); } else { } result = NativeApiResult.Create(color, pixel, errorCode); return(result); }