/// <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); }