LoginSignup
1
0

More than 3 years have passed since last update.

C++のWindowsアプリ開発などで使用できる簡易メッセージボックス

Last updated at Posted at 2020-07-03

i.e.

自分用。
Windows APIを利用している場合のみ対応できます。
クライアントウインドウに対して表示するメッセージボックスを<stdio.h>のprintfみたいな形で使いたい時に。
(なんかフォーマット指定子使って変数とか出力したいデバッグetc...)

コード

適当に加工して使ってください。
説明へたくそなので、解説はありません:tired_face::sweat_drops:

versatility_msgbox.cpp
char i_Buffer[512];
versaility_msgbox.hpp
#include <Windows.h>

// スコープ変数の宣言
extern char i_Buffer[512];

// マクロ定義
/// printf系列のフォーマット指定子が指定可能なメッセージボックス関数
#ifndef DEBUG_MSG_BOX
#define DEBUG_MSG_BOX(msg, ...) snprintf(i_Buffer, 512, msg, __VA_ARGS__); MessageBoxA(/* ここは親ウインドウ(hWndとか)、NULLでも多分動く */, i_Buffer, "Debug Only", MB_OK)
#endif // !DEBUG_MSG_BOX
main.cpp
#include "versatility_msgbox.hpp"

int __stdcall WinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR lpCmdLine,
    _In_ int nCmdShow
) {
    bool ret = true;
    int value = 0x01;
    DEBUG_MSG_BOX("メッセージボックスに表示する文言。\nINTEGER型(HEX):%x\nBOOL型:%s", value, ret ? "true" : "false");
    return 0;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0