Skip to content

Instantly share code, notes, and snippets.

View Tocchann's full-sized avatar

Toshiyuki Takahagi Tocchann

View GitHub Profile
@Tocchann
Tocchann / RunMessageLoop_PeekMessage.cpp
Created September 16, 2021 12:50
PeekMessage による例
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 な実装例
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 の例
#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除外版)
[
local,
object,
uuid(00000000-0000-0000-C000-000000000046),
pointer_default(unique)
]
interface IUnknown
{
typedef [unique] IUnknown *LPUNKNOWN;
@Tocchann
Tocchann / Compatibilty.manifest
Created April 6, 2020 15:26
Windows10 にきっちり対応したいアプリ用追加マニフェスト
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
@Tocchann
Tocchann / prototype.cpp
Last active August 21, 2019 09:26
わんくま横浜 サンプルコードプロトタイプバージョン抜粋
static void APIENTRY CountColors( CWnd* pParent, CListCtrl& lc, LPCTSTR imagePath, std::map<COLORREF, size_t>& numColors )
{
// InsertItem するときに使う情報(コールバックでテキスト表示するのでデータはLPARAMだけ)
LVITEM item{};
item.mask = LVIF_PARAM|LVIF_TEXT;
// テキストデータはその都度生成する(メモリイメージ省略のため)
item.cchTextMax = 0;
item.pszText = LPSTR_TEXTCALLBACK;
// メッセージポンプが動かない版 WM_SETCURSOR されるとマウスカーソルが戻るためメッセージポンプが動く場合はセットしない
@Tocchann
Tocchann / AsyncIndicator.cpp
Created August 16, 2019 02:51
タスクを使った非同期処理
void CSampleDlg::OnOK()
{
// いろいろ前処理
CProgressDlg dlg; // 非同期処理で対応できるように修正したプログレス表示クラス
auto task = concurrency::create_task( [&]()
{
return CountCharInFile( dlg, m_targetPath, m_numbers );
} ).then( [&]( bool result )
{
dlg.PostMessage( WM_CLOSE );
@Tocchann
Tocchann / SyncIndicator.cpp
Created August 16, 2019 02:50
古のインジケータ処理
void CSampleDlg::OnOK()
{
// いろいろ前処理
CProgressDlg dlg; // 同期で処理することを前提に作ったプログレス表示クラス
dlg.Create();
if( CountCharInFile( dlg, m_targetPath, m_numbers ) )
{
// 画面を更新
}
dlg.CloseWindow();
@Tocchann
Tocchann / fooaction.wxs
Last active May 28, 2019 02:32
Sample deferred CustomAction
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<Binary Id="Foo.dll" SourceFile="Foo.dll" />
<CustomAction Id="CA_FooAction" BinaryKey="Foo.dll" DllEntry="CA_FooAction" Return="check" Execute="deferred" />
<SetProperty Id="CA_FooAction" Before="CA_FooAction" Sequence="execute" Value="[FooProp]" />
<InstallExecuteSequence>
<Custom Action="CA_FooAction" After="InstallValidate" />
</InstallExecuteSequence>
</Fragment>
@Tocchann
Tocchann / UNICODE2UTF8
Created November 15, 2017 07:07
std::string/wstring を使って、UNICODE と UTF-8 を相互変換(抜粋コード)
std::string ToUtf8Str( const wchar_t* value )
{
_ASSERTE( value != nullptr );
if( value == nullptr || *value == L'\0' ){
return "";
}
int needLength = WideCharToMultiByte( CP_UTF8, 0, value, -1, nullptr, 0, nullptr, nullptr );
if( needLength < 1 ){
return "";
}