我们在微软官方文档上找不到MessageBoxTimeout()的记录,它是由user32.dll导出的。
使用时只需在.cpp文件中包含了以下部分,就可以调用MessageBoxTimeout。
// 添加MessageBoxTimeout支持
extern "C"
{
int WINAPI MessageBoxTimeoutA(IN HWND hWnd, IN LPCSTR lpText, IN LPCSTR lpCaption, IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
int WINAPI MessageBoxTimeoutW(IN HWND hWnd, IN LPCWSTR lpText, IN LPCWSTR lpCaption, IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
};
#ifdef UNICODE
#define MessageBoxTimeout MessageBoxTimeoutW
#else
#define MessageBoxTimeout MessageBoxTimeoutA
#endif
需要指出的是,Windows 2000的user32.dll没有导出这个函数。
// 设置1000ms自动关闭该提示对话框
MessageBoxTimeout(NULL, L"倒计时", L"提示", MB_OKCANCEL, 0, 1000);