-
Notifications
You must be signed in to change notification settings - Fork 0
/
vMessageBox.cxx
69 lines (58 loc) · 1.15 KB
/
vMessageBox.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
// win環境じゃないんで適当に
typedef int* HWND;
typedef char* LPSTR;
typedef unsigned int UINT;
#define MB_OK 0
#define MB_CANCEL -1
#define MessageBox(a,b,c,d) puts(b);
// 可変個引数メッセージボックス
// 戻り値は、メッセージボックスのをそのまま返す
int vMessageBox(
HWND hWnd,
LPSTR lpCaption,
UINT uType,
char *format,
...)
{
// define
va_list args;
int len = 0;
int result = 0;
char *buffer = NULL;
va_start(args,format);
// create buffer
len = snprintf(NULL,0,format,args);
buffer = new char[len + 1];
if(buffer == NULL){
return 0;
}
// copy buffer
vsnprintf(buffer,len,format,args);
buffer[len] = '\0';
// view messagebox
result = MessageBox(NULL,buffer,NULL,MB_OK);
// delete buffer
delete buffer;
buffer = NULL;
// exit
va_end(args);
return result;
}
int main()
{
// 基本的な呼び出し方
// 引数の順番が微妙に違うので注意が必要
int nResult = vMessageBox(
NULL,
"TestTitle",
MB_OK,
"created by %s.",
"kimoto"
);
printf("ResultValue => %d\n",nResult);
return 0;
}