C++ MessageBox操作系统。独立的
我想创建一个断言函数,它在不打开控制台的情况下在新窗口中显示消息。函数需要独立于O.S,如果可能的话,不使用C++外部库。C++ MessageBox操作系统。独立的,c++,platform-independent,C++,Platform Independent,我想创建一个断言函数,它在不打开控制台的情况下在新窗口中显示消息。函数需要独立于O.S,如果可能的话,不使用C++外部库。 #include <string> #include <sstream> #ifdef WIN32 #include <windows.h> // include windows header, for Windows Based Sistems. #else // ... #endif void Assert (bool con
#include <string>
#include <sstream>
#ifdef WIN32
#include <windows.h> // include windows header, for Windows Based Sistems.
#else
// ...
#endif
void Assert (bool cond,const char* file,int line,const char* desc)
{
if (cond) return; // No Assertion.
#ifdef WIN32
// Use MessageBox function to display the information.
// For Example ...
std::stringstream st;
st << "There Was An Error At Runtime ! \n";
st << "File: " << file << "\n";
st << "Line: " << line << "\n";
st << "Description: " << desc << "\n";
st << "Do You Want To Continue Running the Application?\n";
if (MessageBox (NULL,"Unexpected Error", str.str ().c_str (), MB_YESNO) == IDNO)
exit (-1);
#else
// Do Something, but in Unix Base Systems.
#endif
}
#define assert(condition,description) \
__assert__ (condition,__FILE__,__LINE__,description)
#包括
#包括
#ifdef WIN32
#include//include windows头,用于基于windows的系统。
#否则
// ...
#恩迪夫
void断言(bool cond,const char*file,int行,const char*desc)
{
if(cond)return;//无断言。
#ifdef WIN32
//使用MessageBox功能显示信息。
//例如。。。
std::stringstream st;
St> P> C++标准不包括GUI操作。您需要利用外部平台来为您所需的平台提供GUI服务。
所以你要求的是不可能的。抱歉。定义其他操作系统-有那么多为什么你不在ifdef WIN32的“else”之后编写代码?剩下的就简单多了,我们不必猜测了。我应该使用什么库?GTK、wkWidgets?只需打印一个消息框的最简单库?@VictorUIZ Dialog没有问题,problem是它的阻塞behavior@VictorRuiz因为你只需要一个消息框,使用每个系统上的默认值。只需一个消息框就不难了。注意,在Mac OS X上,你需要在目标C中编写GUI代码,而不是C++。但是,你的用例看起来很奇怪。如果你的应用程序不是GUI,那么为什么会这样呢?想打开消息框吗?没有任何意义。