home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d020_1_4 / 6.ddi / DEFPROCS / DEFDLG.C next >
Encoding:
Text File  |  1990-06-01  |  6.3 KB  |  213 lines

  1.  
  2. /*--------------------------------------------------------------------------*/
  3. /*                                        */
  4. /*  DefDlgProc() -                                */
  5. /*                                        */
  6. /*--------------------------------------------------------------------------*/
  7.  
  8. LONG FAR PASCAL DefDlgProc(hwnd, message, wParam, lParam)
  9.  
  10. register HWND hwnd;
  11. register WORD message;
  12. WORD          wParam;
  13. LONG          lParam;
  14.  
  15. {
  16.   HWND          hwndT1;
  17.   HWND          hwndT2;
  18.   int          result;
  19.  
  20.   if (!CheckHwnd(hwnd))
  21.       return(NULL);
  22.  
  23.   ((PDLG)hwnd)->resultWP = 0L;
  24.  
  25.   if (((PDLG)hwnd)->lpfnDlg == NULL || 
  26.       !(result = (*((PDLG)hwnd)->lpfnDlg)(hwnd, message, wParam, lParam)))
  27.     {
  28.       switch (message)
  29.     {
  30.       case WM_ERASEBKGND:
  31.           FillWindow(hwnd, hwnd, (HDC)wParam, (HBRUSH)CTLCOLOR_DLG);
  32.           return((LONG)TRUE);
  33.  
  34.       case WM_SHOWWINDOW:
  35.           /* If hiding the window, save the focus. If showing the window
  36.            * by means of a SW_* command and the fEnd bit is set, do not
  37.            * pass to DWP so it won't get shown.
  38.            */
  39.           if (!wParam && ((PDLG)hwnd)->hwndFocusSave == NULL)
  40.           ((PDLG)hwnd)->hwndFocusSave = hwndFocus;
  41.           else if (LOWORD(lParam) != 0 && ((PDLG)hwnd)->fEnd)
  42.           break;
  43.           goto CallDWP;
  44.  
  45.       case WM_ACTIVATE:
  46.           fDialog = FALSE;
  47.           if (wParam)
  48.         {
  49.           fDialog = TRUE;
  50.           if (((PDLG)hwnd)->hwndFocusSave)
  51.             {
  52.               SetFocus(((PDLG)hwnd)->hwndFocusSave);
  53.  
  54.               /* Set to NULL so we don't reset if we get more than
  55.              one activate message. */
  56.               ((PDLG)hwnd)->hwndFocusSave = NULL;
  57.             }
  58.         }
  59.           else if (hwndFocus && IsChild(hwnd, hwndFocus) &&
  60.                ((PDLG)hwnd)->hwndFocusSave == NULL)
  61.         {
  62.           /* Must remember focus if deactivated */
  63.           ((PDLG)hwnd)->hwndFocusSave = hwndFocus;
  64.         }
  65.           break;
  66.  
  67.       case WM_SETFOCUS:
  68.               if (!((PDLG)hwnd)->fEnd)
  69.                   /* Don't set the focus if we are ending this dialog box 
  70.            */
  71.                 DlgSetFocus(GetFirstTab(hwnd));
  72.           break;
  73.  
  74.       case WM_CLOSE:
  75.           /* Make sure cancel button is not disabled before sending the
  76.            * IDCANCEL.  Note that we need to do this as a message instead
  77.            * of directly calling the dlg proc so that any dialog box
  78.            * filters get this. 
  79.            */
  80.           hwndT1 = GetDlgItem(hwnd, IDCANCEL);
  81.           if (hwndT1 && TestWF(hwndT1, WFDISABLED))
  82.           MessageBeep(0);
  83.           else
  84.           PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
  85.           break;
  86.  
  87.       case WM_NCDESTROY:
  88.               fDialog = FALSE;      /* clear this flag */
  89.           if (!(hwnd->style & DS_LOCALEDIT))
  90.         {
  91.           if (((PDLG)hwnd)->hData)
  92.             {
  93.               GlobalUnWire(((PDLG)hwnd)->hData);
  94.               ReleaseEditDS(((PDLG)hwnd)->hData);
  95.             }
  96.         }
  97.           /* Delete the user defined font if any */
  98.           if (((PDLG)hwnd)->hUserFont)
  99.           DeleteObject(((PDLG)hwnd)->hUserFont);
  100.  
  101.           /* Gotta let DefWindowProc do its thing here or we won't
  102.            * get all of the little chunks of memory freed for this
  103.            * window (szName and rgwScroll).
  104.            */
  105.           DefWindowProc(hwnd, message, wParam, lParam);
  106.           break;
  107.  
  108.       case DM_SETDEFID:
  109.               if (!(((PDLG)hwnd)->fEnd) && (((PDLG)hwnd)->result != wParam))
  110.                 {
  111.                   /* Make sure that the new default button has the highlight.
  112.            * We need to blow this off if we are ending the dialog box
  113.            * because hwnd->result is no longer a default window id but
  114.            * rather the return value of the dialog box.  
  115.            */
  116.                   /* Catch the case of setting the defid to null or setting
  117.            * the defid to something else when it was initially null. 
  118.            */
  119.                   CheckDefPushButton(hwnd, 
  120.                        (((PDLG)hwnd)->result ? 
  121.                                      GetDlgItem(hwnd, ((PDLG)hwnd)->result) :
  122.                                      NULL),
  123.                        (wParam ? GetDlgItem(hwnd, wParam) : NULL));
  124.                  ((PDLG)hwnd)->result = wParam;
  125.                 }
  126.           return(TRUE);
  127.  
  128.       case DM_GETDEFID:
  129.           return(MAKELONG(((PDLG)hwnd)->result, DC_HASDEFID));
  130.  
  131.       /* This message was added so that user defined controls that want 
  132.        * tab keys can pass the tab off to the next/previous control in the
  133.        * dialog box.  Without this, all they could do was set the focus
  134.        * which didn't do the default button stuff.
  135.        */
  136.       case WM_NEXTDLGCTL:
  137.           hwndT2 = hwndFocus;
  138.           if (LOWORD(lParam))
  139.         {
  140.           if (hwndT2 == NULL)
  141.               hwndT2 = hwnd;
  142.  
  143.           /* wParam contains the hwnd of the ctl to set focus to. */
  144.           hwndT1 = (HWND)wParam;
  145.         }
  146.           else
  147.         {
  148.           if (hwndT2 == NULL)
  149.             {
  150.               /* Set focus to the first tab item. */
  151.               hwndT1 = GetFirstTab(hwnd);
  152.               hwndT2 = hwnd;
  153.             }
  154.           else
  155.             {
  156.               /* If window with focus not a dlg ctl, ignore message. */
  157.               if (!IsChild(hwnd, hwndT2))
  158.               return(TRUE);
  159.  
  160.               /* wParam = TRUE for previous, FALSE for next */
  161.               hwndT1 = GetNextDlgTabItem(hwnd, hwndT2, wParam);
  162.             }
  163.         }
  164.  
  165.           DlgSetFocus(hwndT1);
  166.           CheckDefPushButton(hwnd, hwndT2, hwndT1);
  167.           return(TRUE);
  168.  
  169.       case WM_LBUTTONDOWN:
  170.       case WM_NCLBUTTONDOWN:
  171.           hwndT1 = hwndFocus;
  172.           if (hwndT1->pcls->lpfnWndProc == ComboBoxCtlWndProc)
  173.           /* If user clicks anywhere in dialog box and a combo box (or
  174.            * the editcontrol of a combo box) has the focus, then hide
  175.            * it's listbox. 
  176.            */              
  177.           SendMessage(hwndT1,CB_SHOWDROPDOWN, FALSE, 0L);
  178.           else
  179.           if (hwndT1->pcls->lpfnWndProc == EditWndProc &&
  180.           hwndT1->hwndParent->pcls->lpfnWndProc==ComboBoxCtlWndProc)
  181.         {
  182.           SendMessage(hwndT1->hwndParent,CB_SHOWDROPDOWN, FALSE, 0L);
  183.         }
  184.           /* Always send the message off to DefWndProc */
  185.           goto CallDWP;
  186.  
  187.       case WM_GETFONT:
  188.           return(((PDLG)hwnd)->hUserFont);
  189.  
  190.       case WM_VKEYTOITEM:
  191.       case WM_COMPAREITEM:
  192.       case WM_CHARTOITEM:
  193.           /* We need to return the 0 the app may have returned for these
  194.            * items instead of calling defwindow proc. 
  195.            */
  196.           return(result);
  197.  
  198.       default:
  199. CallDWP:
  200.           return(DefWindowProc(hwnd, message, wParam, lParam));
  201.     }
  202.     }
  203.  
  204.   /* Must return brush which apps dlgfn returns. */
  205.   if (message == WM_CTLCOLOR ||
  206.       message == WM_COMPAREITEM ||
  207.       message == WM_VKEYTOITEM ||
  208.       message == WM_CHARTOITEM)
  209.       return(result);
  210.  
  211.   return(((PDLG)hwnd)->resultWP);
  212. }
  213.