private static IntPtr SelectBitmap(SafeDCHandle targetDCHandle, IntPtr bitmapHandle) { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、オブジェクト選択処理を呼び出す Win32ApiResult Function() { IntPtr win32ReturnValue = Win32Api.SelectObject(targetDCHandle, bitmapHandle); bool win32Result = Win32Api.SelectObjectParameter.IsSuccess(win32ReturnValue, false); return(new Win32ApiResult(win32ReturnValue, win32Result)); } // 実行 string dllName = "gdi32.dll"; string methodName = nameof(Win32Api.SelectObject); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName, result.ErrorCode); } // 以前に選択されていたビットマップオブジェクトへのハンドルを返却 return((IntPtr)result.ReturnValue); }
/// <summary> /// 指定されたデバイスと互換性のあるメモリデバイスコンテキスト(DC)を作成する /// </summary> /// <param name="targetDCHandle"> /// 既存のデバイスコンテキスト(DC)へのハンドル /// 指定したデバイスコンテキスト(DC)関連するメモリデバイスコンテキスト(DC)を作成する /// NULL(<see cref="IntPtr.Zero"/>)を指定した場合、 /// アプリケーションの現在の画面と互換性のあるメモリデバイスコンテキストを作成する /// </param> /// <exception cref="PlatformInvokeException"> /// Win32Apiの処理「DLL:gdi32.dll、メソッド:CreateCompatibleDC」の呼び出しに失敗した場合に発生 /// </exception> /// <exception cref="Win32OperateException"> /// Win32Apiの処理「DLL:gdi32.dll、メソッド:CreateCompatibleDC」の処理に失敗した場合に発生 /// </exception> /// <returns>作成したメモリデバイスコンテキスト(DC)へのハンドル</returns> private static SafeDCHandle CreateCompatibleDC(IntPtr targetDCHandle) { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、メモリデバイスコンテキストの作成処理を呼び出す Win32ApiResult Function() { SafeDCHandle win32ReturnValue = Win32Api.CreateCompatibleDC(targetDCHandle); int win32ErrorCode = Marshal.GetLastWin32Error(); bool win32Result = Win32Api.CreateCompatibleDCParameter.IsSuccess(win32ReturnValue); return(new Win32ApiResult(win32ReturnValue, win32Result, win32ErrorCode)); } // 実行 string dllName = "gdi32.dll"; string methodName = nameof(Win32Api.CreateCompatibleDC); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result && result.ErrorCode != (int)ErrorCode.NO_ERROR) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName, result.ErrorCode); } // 作成したメモリデバイスコンテキスト(DC)へのハンドルを返却 return((SafeDCHandle)result.ReturnValue); }
/// <summary> /// 引数で指定された他のモジュールのアイコンへのハンドル(<paramref name="iconCursorHandle"/>)を /// 現在のモジュールのアイコンへのハンドルに複製する /// </summary> /// <remarks> /// この機能は、別のモジュールが所有しているアイコンを、現在のモジュールへの独自のハンドルで取得する /// 他のモジュールが解放されてもアプリケーションアイコンはアイコンとして使用することができる /// </remarks> /// <param name="iconCursorHandle">アイコン/カーソルへのハンドル</param> /// <exception cref="PlatformInvokeException"> /// Win32Apiの処理「DLL:user32.dll、メソッド:CopyIcon」の呼び出しに失敗した場合に発生 /// </exception> /// <exception cref="Win32OperateException"> /// Win32Apiの処理「DLL:user32.dll、メソッド:CopyIcon」の処理に失敗した場合に発生 /// </exception> /// <returns>複製したアイコンへのハンドル</returns> private static SafeCopyIconHandle CopyIcon(IntPtr iconCursorHandle) { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、アイコンの複製処理を呼び出す Win32ApiResult Function() { SafeCopyIconHandle win32ReturnValue = Win32Api.CopyIcon(iconCursorHandle); int win32ErrorCode = Marshal.GetLastWin32Error(); bool win32Result = !Win32Api.CopyIconParameter.IsSuccess(win32ReturnValue); return(new Win32ApiResult(win32ReturnValue, win32Result, win32ErrorCode)); } // 実行 string dllName = "user32.dll"; string methodName = nameof(Win32Api.CopyIcon); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result && result.ErrorCode != (int)ErrorCode.NO_ERROR) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName, result.ErrorCode); } // 複製したアイコンへのハンドルを返却 return((SafeCopyIconHandle)result.ReturnValue); }
/// <summary> /// アイコンの情報を取得する /// (取得したアイコン情報のカラーBitmapハンドル(<see cref="IconInfo.ICONINFO.ColorBitmapHandle"/>) /// マスクBitmapハンドル(<see cref="IconInfo.ICONINFO.ColorBitmapHandle"/>)は /// <see cref="DeleteObject(IntPtr)"/> で破棄する必要がある) /// </summary> /// <param name="iconCursorHandle">アイコン/カーソルへのハンドル</param> /// <exception cref="PlatformInvokeException"> /// Win32Apiの処理「DLL:user32.dll、メソッド:GetIconInfo」の呼び出しに失敗した場合に発生 /// </exception> /// <exception cref="Win32OperateException"> /// Win32Apiの処理「DLL:user32.dll、メソッド:GetIconInfo」の処理に失敗した場合に発生 /// </exception> /// <returns>取得したアイコン情報</returns> private static IconInfo.ICONINFO GetIconInfo(SafeCopyIconHandle iconCursorHandle) { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、アイコンの情報を取得処理を呼び出す Win32ApiResult Function() { bool win32Result = Win32Api.GetIconInfo(iconCursorHandle, out IconInfo.ICONINFO info); int win32ErrorCode = Marshal.GetLastWin32Error(); return(new Win32ApiResult(info, win32Result, win32ErrorCode)); } // 実行 string dllName = "user32.dll"; string methodName = nameof(Win32Api.GetIconInfo); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result && result.ErrorCode != (int)ErrorCode.NO_ERROR) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName, result.ErrorCode); } // 取得したアイコン情報を返却 return((IconInfo.ICONINFO)result.ReturnValue); }
/// <summary> /// グローバルのカーソルの情報を取得する /// </summary> /// <exception cref="PlatformInvokeException"> /// Win32Apiの処理「DLL:user32.dll、メソッド:GetCursorInfo」の呼び出しに失敗した場合に発生 /// </exception> /// <exception cref="Win32OperateException"> /// Win32Apiの処理「DLL:user32.dll、メソッド:GetCursorInfo」の処理に失敗した場合に発生 /// </exception> /// <returns>取得したカーソル情報</returns> private static Cursor.CURSORINFO GetCursorInfo() { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、グローバルのカーソルの情報を取得処理を呼び出す Win32ApiResult Function() { Cursor.CURSORINFO info = new Cursor.CURSORINFO { StructureSize = Marshal.SizeOf(typeof(Cursor.CURSORINFO)), }; bool win32Result = Win32Api.GetCursorInfo(ref info); int win32ErrorCode = Marshal.GetLastWin32Error(); return(new Win32ApiResult(info, win32Result, win32ErrorCode)); } // 実行 string dllName = "user32.dll"; string methodName = nameof(Win32Api.GetCursorInfo); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result && result.ErrorCode != (int)ErrorCode.NO_ERROR) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName, result.ErrorCode); } // 取得したカーソル情報を返却 return((Cursor.CURSORINFO)result.ReturnValue); }
/// <summary> /// 送信元のデバイスコンテキストに設定されたビットマップ情報(ピクセル情報)を /// 送信先のデバイスコンテキスにビットブロック転送する /// </summary> /// <param name="destDCHandle">送信先のデバイスコンテキストへのハンドル</param> /// <param name="destPointX">送信先の描画位置:X(左上が基準)</param> /// <param name="destPointY">送信先の描画位置:Y(左上が基準)</param> /// <param name="width">転送元 及び、転送先の幅(転送するデータの幅)</param> /// <param name="height">転送元 及び、転送先の高さ(転送するデータの高さ)</param> /// <param name="sourceDCHandle">送信元のデバイスコンテキストへのハンドル</param> /// <param name="sourcePointX">送信元の基準位置:X(左上が基準)</param> /// <param name="sourcePointY">送信元の基準位置:Y(左上が基準)</param> /// <param name="ropCode">合成方法を定めるラスタオペレーションコード</param> /// <exception cref="PlatformInvokeException"> /// Win32Apiの処理「DLL:gdi32.dll、メソッド:BitBlt」の呼び出しに失敗した場合に発生 /// </exception> /// <exception cref="Win32OperateException"> /// Win32Apiの処理「DLL:gdi32.dll、メソッド:BitBlt」の処理に失敗した場合に発生 /// </exception> private static void BitBlt( SafeDCHandle destDCHandle, int destPointX, int destPointY, int width, int height, SafeDCHandle sourceDCHandle, int sourcePointX, int sourcePointY, ROPCode ropCode) { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、ビットブロック転送処理を呼び出す Win32ApiResult Function() { bool win32Result = Win32Api.BitBlt( destDCHandle: destDCHandle, destPointX: destPointX, destPointY: destPointY, width: width, height: height, sourceDCHandle: sourceDCHandle, sourcePointX: sourcePointX, sourcePointY: sourcePointY, ropCode: (uint)ropCode); int win32ErrorCode = Marshal.GetLastWin32Error(); return(new Win32ApiResult(win32Result, win32ErrorCode)); } // 実行 string dllName = "gdi32.dll"; string methodName = nameof(Win32Api.BitBlt); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result && result.ErrorCode != (int)ErrorCode.NO_ERROR) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName, result.ErrorCode); } }
private static void DeleteObject(IntPtr objectHandle) { // Win32Apiの実行処理 // Win32ApiのWindou共通の呼び出し機能を用いて、オブジェクトの破棄処理を呼び出す Win32ApiResult Function() { bool win32Result = Win32Api.DeleteObject(objectHandle); return(new Win32ApiResult(win32Result)); } // 実行 string dllName = "gdi32.dll"; string methodName = nameof(Win32Api.DeleteObject); Win32ApiResult result = Win32ApiCommon.Run(Function, dllName, methodName); // 正常終了したかチェック if (!result.Result) { throw Win32ApiCommon.GetWin32OperateException(dllName, methodName); } }