Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. void ShowTaskDialog(std::string& msg, std::string& title, PCWSTR icon) {
  2.     TaskDialogIndirectFunc TheTaskDialogIndirectFunc;
  3.     HINSTANCE hInstLibrary = LoadLibrary(L"comctl32.dll");
  4.     TheTaskDialogIndirectFunc = (TaskDialogIndirectFunc)GetProcAddress(hInstLibrary, "TaskDialogIndirect");
  5.  
  6.     if (TheTaskDialogIndirectFunc != NULL) {
  7.         // The Text after the first \n is placed at the content area of the
  8.         // TaskDialog
  9.         size_t pos = msg.find_first_of('\n');
  10.         std::string content = "";
  11.        
  12.         if (pos == msg.length() - 1) {
  13.             msg.resize(pos);
  14.         }
  15.         else if (pos != std::string::npos) {
  16.             content = msg.substr(pos + 1);
  17.             msg = msg.substr(0, pos);
  18.         }
  19.  
  20. #ifdef UNICODE
  21.         std::wstring windowTitle = s2ws(title);
  22.         std::wstring mainInstruction = s2ws(msg);
  23.         std::wstring wcontent = s2ws(content);
  24. #else
  25.         std::string windowTitle = title;
  26.         std::string mainInstruction = msg;
  27. #endif
  28.  
  29.         // Prepare the Dialog
  30.         TASKDIALOGCONFIG config;
  31.         memset(&config, '\0', sizeof(config));
  32.  
  33.         config.cbSize = sizeof(config);
  34.         config.hwndParent = GetHwnd();
  35.         config.dwFlags = TDF_POSITION_RELATIVE_TO_WINDOW;
  36.         config.pszWindowTitle = windowTitle.c_str();
  37.         config.pszMainIcon = icon;
  38.         config.pszMainInstruction = mainInstruction.c_str();
  39.         config.pszContent = wcontent.c_str();
  40.         TheTaskDialogIndirectFunc(&config, NULL, NULL, NULL);
  41.     }
  42.     FreeLibrary(hInstLibrary);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement