- /************************************************************************/
- /*函数名:MessageBox
- /*功 能: 封装MessageBoxW,支持变参。还有一个重载(MessageBoxA)
- /*返回值:无
- /************************************************************************/
- void Utility::MessageBox( HWND hWnd, const wchar_t* lpCaption, UINT uType, const wchar_t* format, ...)
- {
- wchar_t* buffer;
- int len;
- va_list args;
- setlocale(LC_ALL,\"chs\");//中文路径支持
- va_start(args, format);
- len = _vscwprintf( format, args ) + 1; // _vscprintf doesn\'t count terminating \'\\0\'
- buffer = (wchar_t*)malloc( len * sizeof(wchar_t) );
- vswprintf_s(buffer, len, format, args);
- va_end(args);
- ::MessageBoxW(hWnd, buffer,lpCaption,uType);
- free(buffer);
- }
- //use it:
- Utility::MessageBox(NULL, L\"Test\", MB_ICONERROR, L\"Test %s succeed!\", L\"Utility::MessageBox\");
- //该片段来自于http://www.codesnippet.cn/detail/13112012306.html
来源: http://www.codesnippet.cn/detail/13112012306.html