我想使用 char 数组创建一个动态 MessageBox,但我对 uType (UINT) 有一些问题。
如果你看我的代码,我首先有一个带有 | 的字符字符串 分隔符并将其解析为数组“a”。然后我将我的 char 转换为 UINT 但我无法让它工作,它只是不显示任何消息框。感谢您的帮助:-)
char str[] ="Testing message|Title Message|MB_OK|MB_ICONINFORMATION";
char * pch;
char * a[4];
int i = 0;
pch = strtok (str,"|");
while (pch != NULL)
{
a[i] = pch;
pch = strtok (NULL, "|");
//cout << a[i];
i++;
}
char test[1000] = "";
strcat_s (test,a[2]);
strcat_s (test,"|");
strcat_s (test,a[3]);
UINT y;
stringstream s;
s << test;
s >> y;
MessageBox(0,a[0],a[1],y);
Sleep(10000);
解决方案 :
UINT x;
if(!strcmp(a[3],"MB_ICONERROR")){
x = 0x10;
}else if(!strcmp(a[3],"MB_ICONEXCLAMATION")){
x = 0x30;
}else if(!strcmp(a[3],"MB_ICONINFORMATION")){
x = 0x40;
}else if(!strcmp(a[3],"MB_ICONQUESTION")){
x = 0x20;
}
if(!strcmp(a[2],"MB_OK")){
x = x + 0;
}else if(!strcmp(a[2],"MB_OKCANCEL")){
x = x + 1;
}else if(!strcmp(a[2],"MB_YESNO")){
x = x + 4;
}else if(!strcmp(a[2],"MB_YESNOCANCEL")){
x = x + 3;
}else if(!strcmp(a[2],"MB_RETRYCANCEL")){
x = x + 5;
}else if(!strcmp(a[2],"MB_ABORTRETRYIGNORE")){
x = x + 2;
}
MessageBox(0, a[0], a[1], x);