home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / dflat.zip / MSGBOX.C < prev    next >
Text File  |  1991-02-18  |  2KB  |  104 lines

  1. /* ------------------ msgbox.c ------------------ */
  2.  
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include "dflat.h"
  7.  
  8. extern DBOX MsgBox;
  9.  
  10. int MessageBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  11. {
  12.     switch (msg)    {
  13.         case CREATE_WINDOW:
  14.             GetClass(wnd) = MESSAGEBOX;
  15.             ClearAttribute(wnd, CONTROLBOX);
  16.             break;
  17.         default:
  18.             break;
  19.     }
  20.     return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
  21. }
  22.  
  23. int YesNoBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  24. {
  25.     switch (msg)    {
  26.         case CREATE_WINDOW:
  27.             GetClass(wnd) = MESSAGEBOX;
  28.             ClearAttribute(wnd, CONTROLBOX);
  29.             break;
  30.         case KEYBOARD:    {
  31.             int c = tolower((int)p1);
  32.             if (c == 'y')
  33.                 SendMessage(wnd, COMMAND, ID_OK, 0);
  34.             else if (c == 'n')
  35.                 SendMessage(wnd, COMMAND, ID_CANCEL, 0);
  36.             break;
  37.         }
  38.         default:
  39.             break;
  40.     }
  41.     return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
  42. }
  43.  
  44. int ErrorBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  45. {
  46.     switch (msg)    {
  47.         case CREATE_WINDOW:
  48.             GetClass(wnd) = ERRORBOX;
  49.             ClearAttribute(wnd, MOVEABLE | CONTROLBOX);
  50.             break;
  51.         default:
  52.             break;
  53.     }
  54.     return BaseWndProc(ERRORBOX, wnd, msg, p1, p2);
  55. }
  56.  
  57. static int GenericMessage(char *ttl, char *msg, int buttonct,
  58.     int (*wndproc)(struct window *, enum messages, PARAM, PARAM),
  59.     char *b1, char *b2)
  60. {
  61.     int rtn;
  62.     MsgBox.dwnd.title = ttl;
  63.     MsgBox.ctl[0].dwnd.h = MsgHeight(msg);
  64.     MsgBox.ctl[0].dwnd.w = max(MsgWidth(msg),
  65.             buttonct*8 + buttonct + 2);
  66.     MsgBox.dwnd.h = MsgBox.ctl[0].dwnd.h+6;
  67.     MsgBox.dwnd.w = MsgBox.ctl[0].dwnd.w+4;
  68.     if (buttonct == 1)
  69.         MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 10) / 2;
  70.     else    {
  71.         MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 18) / 2;
  72.         MsgBox.ctl[2].dwnd.x = MsgBox.ctl[1].dwnd.x + 9;
  73.         MsgBox.ctl[2].class = BUTTON;
  74.     }
  75.     MsgBox.ctl[1].dwnd.y = MsgBox.dwnd.h - 4;
  76.     MsgBox.ctl[2].dwnd.y = MsgBox.dwnd.h - 4;
  77.     MsgBox.ctl[0].itext = msg;
  78.     MsgBox.ctl[1].itext = b1;
  79.     MsgBox.ctl[2].itext = b2;
  80.     rtn = DialogBox(&MsgBox, wndproc);
  81.     MsgBox.ctl[2].class = 0;
  82.     return rtn;
  83. }
  84.  
  85. int TestErrorMessage(char *msg)
  86. {
  87.     return GenericMessage("Error", msg, 2, ErrorBoxProc, Ok, Cancel);
  88. }
  89.  
  90. void ErrorMessage(char *msg)
  91. {
  92.     GenericMessage("Error", msg, 1, ErrorBoxProc, Ok, NULL);
  93. }
  94.  
  95. void MessageBox(char *ttl, char *msg)
  96. {
  97.     GenericMessage(ttl, msg, 1, MessageBoxProc, Ok, NULL);
  98. }
  99.  
  100. int YesNoBox(char *msg)
  101. {
  102.     return GenericMessage(NULL, msg, 2, YesNoBoxProc, Yes, No);
  103. }
  104.