Custom MessageBox Buttons


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. [DllImport("kernel32.dll")]
  2. static extern uint GetCurrentThreadId();
  3.  
  4. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  5. private static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
  6.  
  7. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  8. private static extern bool UnhookWindowsHookEx(int idHook);
  9.  
  10. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  11. private static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
  12.  
  13. [DllImport("user32.dll")]
  14. private static extern bool SetDlgItemText(IntPtr hWnd, int nIDDlgItem, string lpString);
  15.  
  16. delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
  17.  
  18. static HookProc dlgHookProc;
  19.  
  20. private const long WH_CBT = 5;
  21. private const long HCBT_ACTIVATE = 5;
  22.  
  23. private const int ID_BUT_OK = 1;
  24. private const int ID_BUT_CANCEL = 2;
  25. private const int ID_BUT_ABORT = 3;
  26. private const int ID_BUT_RETRY = 4;
  27. private const int ID_BUT_IGNORE = 5;
  28. private const int ID_BUT_YES = 6;
  29. private const int ID_BUT_NO = 7;
  30.  
  31. private const string BUT_OK = "Save";
  32. private const string BUT_CANCEL = "Cancel";
  33. private const string BUT_ABORT = "Stop";
  34. private const string BUT_RETRY = "Continue";
  35. private const string BUT_IGNORE = "Ignore";
  36. private const string BUT_YES = "Yeeh";
  37. private const string BUT_NO = "Never";
  38.  
  39. private static int _hook = 0;
  40.  
  41. private static int DialogHookProc(int nCode, IntPtr wParam, IntPtr lParam)
  42. {
  43. if (nCode < 0)
  44. {
  45. return CallNextHookEx(_hook, nCode, wParam, lParam);
  46. }
  47.  
  48. if (nCode == HCBT_ACTIVATE)
  49. {
  50. SetDlgItemText(wParam, ID_BUT_OK, BUT_OK);
  51. SetDlgItemText(wParam, ID_BUT_CANCEL, BUT_CANCEL);
  52. SetDlgItemText(wParam, ID_BUT_ABORT, BUT_ABORT);
  53. SetDlgItemText(wParam, ID_BUT_RETRY, BUT_RETRY);
  54. SetDlgItemText(wParam, ID_BUT_IGNORE, BUT_IGNORE);
  55. SetDlgItemText(wParam, ID_BUT_YES, BUT_YES);
  56. SetDlgItemText(wParam, ID_BUT_NO, BUT_NO);
  57. }
  58.  
  59. return CallNextHookEx(_hook, nCode, wParam, lParam);
  60. }
  61.  
  62. private void Button_Click(object sender, EventArgs e)
  63. {
  64. dlgHookProc = new HookProc(DialogHookProc);
  65.  
  66. _hook = SetWindowsHookEx((int)WH_CBT, dlgHookProc, (IntPtr)0, (int)GetCurrentThreadId());
  67.  
  68. DialogResult dlgEmptyCheck = MessageBox.Show("Text", "Caption", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
  69.  
  70. if (dlgEmptyCheck == DialogResult.Abort)
  71. {
  72.  
  73. }
  74.  
  75. UnhookWindowsHookEx(_hook);
  76. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.