コード例 #1
0
ファイル: SafeDC.cs プロジェクト: Yerongn/HandyControl
        public static SafeDC CreateCompatibleDC(SafeDC hdc)
        {
            SafeDC safeDC = null;

            try
            {
                IntPtr hdc2 = IntPtr.Zero;
                if (hdc != null)
                {
                    hdc2 = hdc.handle;
                }
                safeDC = SafeDC.NativeMethods.CreateCompatibleDC(hdc2);
                if (safeDC == null)
                {
                    HRESULT.ThrowLastError();
                }
            }
            finally
            {
                if (safeDC != null)
                {
                    safeDC._created = true;
                }
            }
            if (safeDC.IsInvalid)
            {
                safeDC.Dispose();
                throw new SystemException("Unable to create a device context from the specified device information.");
            }
            return(safeDC);
        }
コード例 #2
0
 public static void SetProp(IntPtr hwnd, string lpString, IntPtr hData)
 {
     if (!Standard.NativeMethods.SetProp_1(hwnd, lpString, hData))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #3
0
 public static void SystemParametersInfo(SPI uiAction, int uiParam, string pvParam, SPIF fWinIni)
 {
     if (!NativeMethods._SystemParametersInfo_String(uiAction, uiParam, pvParam, fWinIni))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #4
0
 public static void AllowSetForegroundWindow(int dwProcessId)
 {
     if (!Standard.NativeMethods.AllowSetForegroundWindow_1(dwProcessId))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #5
0
 public static void UnregisterClass(short atom, IntPtr hinstance)
 {
     if (!NativeMethods._UnregisterClassAtom(new IntPtr((int)atom), hinstance))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #6
0
 public static void UnregisterClass(string lpClassName, IntPtr hInstance)
 {
     if (!NativeMethods._UnregisterClassName(lpClassName, hInstance))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #7
0
 public static void UpdateLayeredWindow(IntPtr hwnd, SafeDC hdcDst, ref POINT pptDst, ref SIZE psize, SafeDC hdcSrc, ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags)
 {
     if (!NativeMethods._UpdateLayeredWindow(hwnd, hdcDst, ref pptDst, ref psize, hdcSrc, ref pptSrc, crKey, ref pblend, dwFlags))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #8
0
 public static void UnregisterClass(short atom, IntPtr hinstance)
 {
     if (!Standard.NativeMethods.UnregisterClass_1(new IntPtr(atom), hinstance))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #9
0
 public static void UpdateLayeredWindow(IntPtr hwnd, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags)
 {
     if (!NativeMethods._UpdateLayeredWindowIntPtr(hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, crKey, ref pblend, dwFlags))
     {
         HRESULT.ThrowLastError();
     }
 }
コード例 #10
0
 public static RECT AdjustWindowRectEx(RECT lpRect, WS dwStyle, bool bMenu, WS_EX dwExStyle)
 {
     if (!NativeMethods._AdjustWindowRectEx(ref lpRect, dwStyle, bMenu, dwExStyle))
     {
         HRESULT.ThrowLastError();
     }
     return(lpRect);
 }
コード例 #11
0
        public static IntPtr SelectObject(SafeDC hdc, IntPtr hgdiobj)
        {
            IntPtr intPtr = Standard.NativeMethods.SelectObject_1(hdc, hgdiobj);

            if (intPtr == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
コード例 #12
0
        public static WM RegisterWindowMessage(string lpString)
        {
            uint num = NativeMethods._RegisterWindowMessage(lpString);

            if (num == 0U)
            {
                HRESULT.ThrowLastError();
            }
            return((WM)num);
        }
コード例 #13
0
        public static NONCLIENTMETRICS SystemParameterInfo_GetNONCLIENTMETRICS()
        {
            NONCLIENTMETRICS nONCLIENTMETRIC = (Utility.IsOSVistaOrNewer ? NONCLIENTMETRICS.VistaMetricsStruct : NONCLIENTMETRICS.XPMetricsStruct);

            if (!Standard.NativeMethods.SystemParametersInfoW_1(SPI.GETNONCLIENTMETRICS, nONCLIENTMETRIC.cbSize, ref nONCLIENTMETRIC, SPIF.None))
            {
                HRESULT.ThrowLastError();
            }
            return(nONCLIENTMETRIC);
        }
コード例 #14
0
        public static RECT GetWindowRect(IntPtr hwnd)
        {
            RECT rECT;

            if (!Standard.NativeMethods.GetWindowRect_1(hwnd, out rECT))
            {
                HRESULT.ThrowLastError();
            }
            return(rECT);
        }
コード例 #15
0
        public static NONCLIENTMETRICS SystemParameterInfo_GetNONCLIENTMETRICS()
        {
            NONCLIENTMETRICS nonclientmetrics = Utility.IsOSVistaOrNewer ? NONCLIENTMETRICS.VistaMetricsStruct : NONCLIENTMETRICS.XPMetricsStruct;

            if (!NativeMethods._SystemParametersInfo_NONCLIENTMETRICS(SPI.GETNONCLIENTMETRICS, nonclientmetrics.cbSize, ref nonclientmetrics, SPIF.None))
            {
                HRESULT.ThrowLastError();
            }
            return(nonclientmetrics);
        }
コード例 #16
0
        public static IntPtr GetModuleHandle(string lpModuleName)
        {
            IntPtr moduleHandleW = Standard.NativeMethods.GetModuleHandleW(lpModuleName);

            if (moduleHandleW == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(moduleHandleW);
        }
コード例 #17
0
        public static IntPtr CreateWindowEx(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam)
        {
            IntPtr intPtr = NativeMethods._CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);

            if (IntPtr.Zero == intPtr)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
コード例 #18
0
        public static RECT GetWindowRect(IntPtr hwnd)
        {
            RECT result;

            if (!NativeMethods._GetWindowRect(hwnd, out result))
            {
                HRESULT.ThrowLastError();
            }
            return(result);
        }
コード例 #19
0
        public static short RegisterClassEx(ref WNDCLASSEX lpwcx)
        {
            short num = NativeMethods._RegisterClassEx(ref lpwcx);

            if (num == 0)
            {
                HRESULT.ThrowLastError();
            }
            return(num);
        }
コード例 #20
0
        public static IntPtr GetModuleHandle(string lpModuleName)
        {
            IntPtr intPtr = NativeMethods._GetModuleHandle(lpModuleName);

            if (intPtr == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
コード例 #21
0
        public static POINT GetCursorPos()
        {
            POINT pOINT;

            if (!Standard.NativeMethods.GetCursorPos_1(out pOINT))
            {
                HRESULT.ThrowLastError();
            }
            return(pOINT);
        }
コード例 #22
0
        public static uint RegisterClipboardFormat(string formatName)
        {
            uint num = Standard.NativeMethods.RegisterClipboardFormatW(formatName);

            if (num == 0)
            {
                HRESULT.ThrowLastError();
            }
            return(num);
        }
コード例 #23
0
        public static IntPtr SelectObject(SafeDC hdc, SafeHBITMAP hgdiobj)
        {
            IntPtr intPtr = NativeMethods._SelectObjectSafeHBITMAP(hdc, hgdiobj);

            if (intPtr == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
コード例 #24
0
        public static IntPtr SetActiveWindow(IntPtr hwnd)
        {
            Verify.IsNotDefault <IntPtr>(hwnd, "hwnd");
            IntPtr intPtr = NativeMethods._SetActiveWindow(hwnd);

            if (intPtr == IntPtr.Zero)
            {
                HRESULT.ThrowLastError();
            }
            return(intPtr);
        }
コード例 #25
0
        public static SafeHBITMAP CreateDIBSection(SafeDC hdc, ref BITMAPINFO bitmapInfo, out IntPtr ppvBits, IntPtr hSection, int dwOffset)
        {
            SafeHBITMAP safeHBITMAP = null;

            safeHBITMAP = (hdc != null ? Standard.NativeMethods.CreateDIBSection_1(hdc, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset) : Standard.NativeMethods.CreateDIBSection_2(IntPtr.Zero, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset));
            if (safeHBITMAP.IsInvalid)
            {
                HRESULT.ThrowLastError();
            }
            return(safeHBITMAP);
        }
コード例 #26
0
        public static HIGHCONTRAST SystemParameterInfo_GetHIGHCONTRAST()
        {
            HIGHCONTRAST highcontrast = new HIGHCONTRAST
            {
                cbSize = Marshal.SizeOf(typeof(HIGHCONTRAST))
            };

            if (!NativeMethods._SystemParametersInfo_HIGHCONTRAST(SPI.GETHIGHCONTRAST, highcontrast.cbSize, ref highcontrast, SPIF.None))
            {
                HRESULT.ThrowLastError();
            }
            return(highcontrast);
        }
コード例 #27
0
        public static HIGHCONTRAST SystemParameterInfo_GetHIGHCONTRAST()
        {
            HIGHCONTRAST hIGHCONTRAST = new HIGHCONTRAST()
            {
                cbSize = Marshal.SizeOf(typeof(HIGHCONTRAST))
            };
            HIGHCONTRAST hIGHCONTRAST1 = hIGHCONTRAST;

            if (!Standard.NativeMethods.SystemParametersInfoW_2(SPI.GETHIGHCONTRAST, hIGHCONTRAST1.cbSize, ref hIGHCONTRAST1, SPIF.None))
            {
                HRESULT.ThrowLastError();
            }
            return(hIGHCONTRAST1);
        }
コード例 #28
0
        public static WINDOWINFO GetWindowInfo(IntPtr hWnd)
        {
            WINDOWINFO wINDOWINFO = new WINDOWINFO()
            {
                cbSize = Marshal.SizeOf(typeof(WINDOWINFO))
            };
            WINDOWINFO wINDOWINFO1 = wINDOWINFO;

            if (!Standard.NativeMethods.GetWindowInfo_1(hWnd, ref wINDOWINFO1))
            {
                HRESULT.ThrowLastError();
            }
            return(wINDOWINFO1);
        }
コード例 #29
0
        public static SafeHBITMAP CreateDIBSection(SafeDC hdc, ref BITMAPINFO bitmapInfo, out IntPtr ppvBits, IntPtr hSection, int dwOffset)
        {
            SafeHBITMAP safeHBITMAP;

            if (hdc == null)
            {
                safeHBITMAP = NativeMethods._CreateDIBSectionIntPtr(IntPtr.Zero, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset);
            }
            else
            {
                safeHBITMAP = NativeMethods._CreateDIBSection(hdc, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset);
            }
            if (safeHBITMAP.IsInvalid)
            {
                HRESULT.ThrowLastError();
            }
            return(safeHBITMAP);
        }
コード例 #30
0
        public static string GetModuleFileName(IntPtr hModule)
        {
            StringBuilder stringBuilder = new StringBuilder(260);

            for (;;)
            {
                int num = NativeMethods._GetModuleFileName(hModule, stringBuilder, stringBuilder.Capacity);
                if (num == 0)
                {
                    HRESULT.ThrowLastError();
                }
                if (num != stringBuilder.Capacity)
                {
                    break;
                }
                stringBuilder.EnsureCapacity(stringBuilder.Capacity * 2);
            }
            return(stringBuilder.ToString());
        }