c – 如何将GDI状态转换为字符串?

实际上,主题.我还没有找到任何标准方法将GDI状态(GDI方法返回的错误状态)转换为字符串,类似于FormatMessage() 最佳答案 如果您想将
GDI+ Status中的标签转换为字符串,那么您可以做的最简单的事情就是:

const char* StatusMsgMap[] = 
{
    "Ok",               //StatusMsgMap[Ok] = "Ok";
    "GenericError",     //StatusMsgMap[GenericError] = "GenericError";
    "InvalidParameter", //StatusMsgMap[InvalidParameter] = "InvalidParameter";
    "OutOfMemory",      //StatusMsgMap[OutOfMemory] = "OutOfMemory";
    //so on
};

//Usage:
 std::string error = StatusMsgMap[status]; // where status is Status type!

或者如果您想要更多描述性消息,那么:

const char* StatusMsgMap[] =
{
    "the method call was successful",
    "there was an error on the method call, which is identified as something other than those defined by the other elements of this enumeration",
    "one of the arguments passed to the method was not valid",
    //so on
};

由于Status枚举中只有22个标签,因此在我看来,以上述方式创建StatusMsgMap并不是什么大问题. 5分钟绰绰有余!

点赞