Advertisement
Guest User

Using TaskDialog DLL

a guest
Jul 5th, 2015
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.83 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <stdio.h>
  3.  
  4. #define TD_WARNING_ICON         MAKEINTRESOURCEW(-1)
  5. #define TD_ERROR_ICON           MAKEINTRESOURCEW(-2)
  6. #define TD_INFORMATION_ICON     MAKEINTRESOURCEW(-3)
  7. #define TD_SHIELD_ICON          MAKEINTRESOURCEW(-4)
  8. enum _TASKDIALOG_COMMON_BUTTON_FLAGS
  9. {
  10.     TDCBF_OK_BUTTON            = 0x0001, // selected control return value IDOK
  11.     TDCBF_YES_BUTTON           = 0x0002, // selected control return value IDYES
  12.     TDCBF_NO_BUTTON            = 0x0004, // selected control return value IDNO
  13.     TDCBF_CANCEL_BUTTON        = 0x0008, // selected control return value IDCANCEL
  14.     TDCBF_RETRY_BUTTON         = 0x0010, // selected control return value IDRETRY
  15.     TDCBF_CLOSE_BUTTON         = 0x0020  // selected control return value IDCLOSE
  16. };
  17. typedef int TASKDIALOG_COMMON_BUTTON_FLAGS;           // Note: _TASKDIALOG_COMMON_BUTTON_FLAGS is an int
  18. typedef HRESULT (*TaskDialog_t)(HWND, HINSTANCE, PCWSTR, PCWSTR, PCWSTR, TASKDIALOG_COMMON_BUTTON_FLAGS, PCWSTR, int*);
  19.  
  20. int main(){
  21.     HANDLE lib = LoadLibrary("Libs\\TaskDialog.dll");
  22.     if(!lib){
  23.         puts("Library not found!");
  24.         return 1;
  25.     }
  26.     TaskDialog_t TaskDialog = (TaskDialog_t)GetProcAddress(lib, "TaskDialog");
  27.     if(!TaskDialog){
  28.         puts("Function in library not found!");
  29.         FreeLibrary(lib);
  30.         return 2;
  31.     }
  32.     int button_pressed = 0;
  33.     if(TaskDialog(
  34.         NULL, /* hWndParent */
  35.         NULL, /* hInstance */
  36.         L"TaskDialog - Title", /* pszWindowTitle */
  37.         L"TaskDialog - Instruction", /* pszMainInstruction */
  38.         L"TaskDialog - Content", /* pszContent */
  39.         TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON, /* dwCommonButtons */
  40.         TD_INFORMATION_ICON, /* pszIcon */
  41.         &button_pressed /* *pnButton */
  42.     ) != S_OK){
  43.         puts("Function call failed!");
  44.         FreeLibrary(lib);
  45.         return 3;
  46.     }
  47.     puts(button_pressed == IDOK ? "OK" : "Cancel");
  48.     FreeLibrary(lib);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement