Skip to content

Instantly share code, notes, and snippets.

Avatar

Tocchann Tocchann

  • Japan
  • 19:10 (UTC +09:00)
View GitHub Profile
@Tocchann
Tocchann / RelayCommand.cs
Created March 31, 2022 11:23
ICommand のミニマムベースクラス
View RelayCommand.cs
using System;
using System.Diagnostics;
using System.Windows.Input;
namespace SimpleMVVM
{
public class RelayCommand : ICommand
{
private readonly Action<object> execute;
private readonly Predicate<object> canExecute;
@Tocchann
Tocchann / StdinPipe.ps1
Created February 6, 2022 08:39
PowerShellスクリプトでパイプ処理
View StdinPipe.ps1
# StdinPipe.ps1 [-InputObject] <string[]> [-ReqireParam] <string> [[-OptionalParam] <string>] [<CommonParameters>]
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="標準入力か引数で受け取るデータ")]
[string[]]$InputObject,
[parameter(Mandatory=$true,ValueFromPipeline=$false,HelpMessage="必須パラメータ")]
[string]$ReqireParam,
[parameter(Mandatory=$false,ValueFromPipeline=$false,HelpMessage="オプションパラメータ")]
[string]$OptionalParam
)
@Tocchann
Tocchann / ParallelRendering.cs
Last active November 23, 2021 15:31
レンダリング丸ごと並列化
View ParallelRendering.cs
// 排他制御せずにレンダリングしてもらう(メモリイータータイプ)
private ImageSource CreateThumbnail( stirng filePath, Cube.Pdf.Page page )
{
using( var renderer = new DocumentRenderer( filePath ) )
using( var image = renderer.Render( page, page.Size ) )
using( var stream = new MemoryStream() )
{
image.Save( stream, ImageFormat.png );
stream.Seek( 0, SeekOrigin.Begin );
return BitmapFrame( stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad );
View ClassA.h
class ClassA
{
public:
static bool IsValidHandle( HANDLE handle )
{
//return handle != INVALID_HANDLE_VALUE;
return handle != INVALID_HANDLE_VALUE && handle != nullptr;
//return handle != nullptr;
}
// ハンドルの複製をどうするかは何のハンドルかに依存するのでここでは言及しない
@Tocchann
Tocchann / LoadPngFromResouce
Created September 27, 2021 15:18
リソースに格納したPNGをGDI+でロードする(エラーチェックなし版)
View LoadPngFromResouce
// リソースファイル上はこんな感じで格納
// #define IDB_PNG 12345
// IDB_PNG PNG "res\\png.png"
Gdiplus::Bitmap* LoadPngFromResource( HINSTANCE hInst, UINT resID )
{
HRSRC hResInfo = FindResource( hInst, MAKEINTRESOURCE(resID), _T("PNG") );
HGLOBAL hResImage = LoadResource( hModule, hResInfo );
DWORD size = SizeofResource( hModule, hResInfo );
const BYTE* srcImage = static_cast<const BYTE*>( LockResource( hResImage ) );
IStreamPtr ptrStream( SHCreateMemStream( srcImage, size ) );
@Tocchann
Tocchann / RunMessageLoop_Minimum.cpp
Created September 17, 2021 07:26
ミニマム実装例
View RunMessageLoop_Minimum.cpp
int RunMessageLoop()
{
MSG msg;
while( GetMessage( &msg, nullptr, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
@Tocchann
Tocchann / RunMessageLoop_PeekMessage.cpp
Created September 16, 2021 12:50
PeekMessage による例
View RunMessageLoop_PeekMessage.cpp
int RunMessageLoop()
{
MSG msg;
do{
if( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ) )
{
if( msg.message != WM_QUIT && !PreTranslateMessage( &msg ) )
{
TranslateMessage( &msg );
DispatchMesage( &msg );
@Tocchann
Tocchann / RunMessageLoop_GetMessage.cpp
Last active September 16, 2021 12:34
GetMessage な実装例
View RunMessageLoop_GetMessage.cpp
int RunMessageLoop()
{
MSG msg = { 0 };
BOOL ret;
while( (ret=GetMessage( &msg, nullptr, 0, 0 )) != 0 )
{
if( ret == -1 )
{
// 必要に応じてエラー処理を施す。場合によっては終了する
}
@Tocchann
Tocchann / RunMessageLoop_MsgWaitForMultipleObjects.cpp
Last active August 3, 2022 13:21
MsgWaitForMultipleObjects の例
View RunMessageLoop_MsgWaitForMultipleObjects.cpp
#include <map>
#include <functional>
// waitActions に登録する例は載せていない(通常は、排他制御して追加処理するのが良い)
std::map<HANDLE, std::function<bool(bool,bool&)>> waitActions;
DWORD APIENTRY SetupWaitHandles( HANDLE* waitHandles, DWORD capacityCount )
{
DWORD waitCount = 0;
if( capacityCount > 0 )
{
@Tocchann
Tocchann / IUnknown.idl
Created August 27, 2020 03:02
IUnknown の IDL上の定義(cpp_quote除外版)
View IUnknown.idl
[
local,
object,
uuid(00000000-0000-0000-C000-000000000046),
pointer_default(unique)
]
interface IUnknown
{
typedef [unique] IUnknown *LPUNKNOWN;