Posted By

hobeau43 on 12/25/12


Tagged

messagebox PInvoke user32


Versions (?)

Messagebox Timer


 / Published in: C#
 

Wrapper class for the undocumented MessageBoxTimeout method in user32.dll

  1. class MessageBoxTimer
  2. {
  3. [DllImport("user32.dll", SetLastError = true)]
  4. static extern int MessageBoxTimeout(IntPtr hwnd, String text, String title, uint type, Int16 wLanguageId, Int32 milliseconds);
  5.  
  6. public enum MessageBoxReturnStatus
  7. {
  8. OK = 1,
  9. Cancel = 2,
  10. Abort = 3,
  11. Retry = 4,
  12. Ignore = 5,
  13. Yes = 6,
  14. No = 7,
  15. TryAgain = 10,
  16. Continue = 11
  17. }
  18.  
  19. public enum MessageBoxType
  20. {
  21. OK = 0,
  22. OK_Cancel = 1,
  23. Abort_Retry_Ignore = 2,
  24. Yes_No_Cancel = 3,
  25. Yes_No = 4,
  26. Retry_Cancel = 5,
  27. Cancel_TryAgain_Continue = 6
  28. }
  29.  
  30. public static MessageBoxReturnStatus Show(string title, string text, MessageBoxType type, int milliseconds)
  31. {
  32. int returnValue = MessageBoxTimeout(IntPtr.Zero, text, title, Convert.ToUInt32(type), 1, milliseconds);
  33.  
  34. return (MessageBoxReturnStatus)returnValue;
  35. }
  36. }

Report this snippet  

You need to login to post a comment.