home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / DDEML / SERVER / DIALOG.C_ / DIALOG.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  8.2 KB  |  289 lines

  1. #include "ddemlsv.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "huge.h"
  6.  
  7. LONG GetDlgItemLong(HWND hwnd, WORD id, BOOL *pfTranslated, BOOL fSigned);
  8. VOID SetDlgItemLong(HWND hwnd, WORD id, LONG l, BOOL fSigned);
  9.  
  10. /****************************************************************************
  11.  *                                                                          *
  12.  *  FUNCTION   : DoDialog()                                                 *
  13.  *                                                                          *
  14.  *  PURPOSE    : Generic dialog invocation routine.  Handles procInstance   *
  15.  *               stuff, focus management and param passing.                 *
  16.  *  RETURNS    : result of dialog procedure.                                *
  17.  *                                                                          *
  18.  ****************************************************************************/
  19. int FAR DoDialog(
  20. LPSTR lpTemplateName,
  21. FARPROC lpDlgProc,
  22. DWORD param,
  23. BOOL fRememberFocus)
  24. {
  25.     WORD wRet;
  26.     HWND hwndFocus;
  27.     WORD cRunawayT;
  28.  
  29.     cRunawayT = cRunaway;
  30.     cRunaway = 0;           // turn off runaway during dialogs.
  31.  
  32.     if (fRememberFocus)
  33.         hwndFocus = GetFocus();
  34.     lpDlgProc = MakeProcInstance(lpDlgProc, hInst);
  35.     wRet = DialogBoxParam(hInst, lpTemplateName, hwndServer, lpDlgProc, param);
  36.     FreeProcInstance(lpDlgProc);
  37.     if (fRememberFocus)
  38.         SetFocus(hwndFocus);
  39.  
  40.     cRunaway = cRunawayT;   // restore runaway state.
  41.     return wRet;
  42. }
  43.  
  44.  
  45. /****************************************************************************
  46.  
  47.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  48.  
  49.     PURPOSE:  Processes messages for "About" dialog box
  50.  
  51.     MESSAGES:
  52.  
  53.         WM_INITDIALOG - initialize dialog box
  54.         WM_COMMAND    - Input received
  55.  
  56.     COMMENTS:
  57.  
  58.         No initialization is needed for this particular dialog box, but TRUE
  59.         must be returned to Windows.
  60.  
  61.         Wait for user to click on "Ok" button, then close the dialog box.
  62.  
  63. ****************************************************************************/
  64.  
  65. BOOL FAR PASCAL __export About(hDlg, message, wParam, lParam)
  66. HWND hDlg;                                /* window handle of the dialog box */
  67. unsigned message;                         /* type of message                 */
  68. WORD wParam;                              /* message-specific information    */
  69. LONG lParam;
  70. {
  71.     switch (message) {
  72.         case WM_INITDIALOG:                /* message: initialize dialog box */
  73.             return (TRUE);
  74.  
  75.         case WM_COMMAND:                      /* message: received a command */
  76.             if (wParam == IDOK                /* "OK" box selected?          */
  77.                 || wParam == IDCANCEL) {      /* System menu close command? */
  78.                 EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
  79.                 return (TRUE);
  80.             }
  81.             break;
  82.     }
  83.     return (FALSE);                           /* Didn't process a message    */
  84. }
  85.  
  86.  
  87.  
  88.  
  89. BOOL FAR PASCAL __export RenderDelayDlgProc(
  90. HWND          hwnd,
  91. register WORD msg,
  92. register WORD wParam,
  93. LONG          lParam)
  94. {
  95.     switch (msg){
  96.     case WM_INITDIALOG:
  97.         SetWindowText(hwnd, "Data Render Delay");
  98.         SetDlgItemInt(hwnd, IDEF_VALUE, RenderDelay, FALSE);
  99.         SetDlgItemText(hwnd, IDTX_VALUE, "Delay in milliseconds:");
  100.         return(1);
  101.         break;
  102.  
  103.     case WM_COMMAND:
  104.         switch (wParam) {
  105.         case IDOK:
  106.             RenderDelay = GetDlgItemInt(hwnd, IDEF_VALUE, NULL, FALSE);
  107.             // fall through
  108.         case IDCANCEL:
  109.             EndDialog(hwnd, 0);
  110.             break;
  111.  
  112.         default:
  113.             return(FALSE);
  114.         }
  115.         break;
  116.     }
  117.     return(FALSE);
  118. }
  119.  
  120.  
  121.  
  122.  
  123. BOOL FAR PASCAL __export SetTopicDlgProc(
  124. HWND          hwnd,
  125. register WORD msg,
  126. register WORD wParam,
  127. LONG          lParam)
  128. {
  129.     char szT[MAX_APPNAME + MAX_TOPIC + 3];
  130.  
  131.     switch (msg){
  132.     case WM_INITDIALOG:
  133.         SetWindowText(hwnd, "Set Topic Dialog");
  134.         SendDlgItemMessage(hwnd, IDEF_VALUE, EM_LIMITTEXT, MAX_TOPIC, 0);
  135.         SetDlgItemText(hwnd, IDEF_VALUE, szTopic);
  136.         SetDlgItemText(hwnd, IDTX_VALUE, "Topic:");
  137.         return(1);
  138.         break;
  139.  
  140.     case WM_COMMAND:
  141.         switch (wParam) {
  142.         case IDOK:
  143.             DdeFreeStringHandle(idInst, topicList[1].hszTopic);
  144.             GetDlgItemText(hwnd, IDEF_VALUE, szTopic, MAX_TOPIC);
  145.             topicList[1].hszTopic = DdeCreateStringHandle(idInst, szTopic, NULL);
  146.             strcpy(szT, szServer);
  147.             strcat(szT, " | ");
  148.             strcat(szT, szTopic);
  149.             SetWindowText(hwndServer, szT);
  150.             InvalidateRect(hwndServer, &rcTopics, TRUE);
  151.             // fall through
  152.         case IDCANCEL:
  153.             EndDialog(hwnd, 0);
  154.             break;
  155.  
  156.         default:
  157.             return(FALSE);
  158.         }
  159.         break;
  160.     }
  161.     return(FALSE);
  162. }
  163.  
  164.  
  165. BOOL FAR PASCAL __export SetServerDlgProc(
  166. HWND          hwnd,
  167. register WORD msg,
  168. register WORD wParam,
  169. LONG          lParam)
  170. {
  171.     char szT[MAX_APPNAME + MAX_TOPIC + 3];
  172.  
  173.     switch (msg){
  174.     case WM_INITDIALOG:
  175.         SetWindowText(hwnd, "Set Server Name Dialog");
  176.         SendDlgItemMessage(hwnd, IDEF_VALUE, EM_LIMITTEXT, MAX_APPNAME, 0);
  177.         SetDlgItemText(hwnd, IDEF_VALUE, szServer);
  178.         SetDlgItemText(hwnd, IDTX_VALUE, "Server:");
  179.         return(1);
  180.         break;
  181.  
  182.     case WM_COMMAND:
  183.         switch (wParam) {
  184.         case IDOK:
  185.             GetDlgItemText(hwnd, IDEF_VALUE, szServer, MAX_APPNAME);
  186.             DdeNameService(idInst, hszAppName, NULL, DNS_UNREGISTER);
  187.             DdeFreeStringHandle(idInst, hszAppName);
  188.             hszAppName = DdeCreateStringHandle(idInst, szServer, NULL);
  189.             DdeNameService(idInst, hszAppName, NULL, DNS_REGISTER);
  190.             strcpy(szT, szServer);
  191.             strcat(szT, " | ");
  192.             strcat(szT, szTopic);
  193.             SetWindowText(hwndServer, szT);
  194.             // fall through
  195.         case IDCANCEL:
  196.             EndDialog(hwnd, 0);
  197.             break;
  198.  
  199.         default:
  200.             return(FALSE);
  201.         }
  202.         break;
  203.     }
  204.     return(FALSE);
  205. }
  206.  
  207.  
  208.  
  209.  
  210. BOOL FAR PASCAL __export ContextDlgProc(
  211. HWND          hwnd,
  212. register WORD msg,
  213. register WORD wParam,
  214. LONG          lParam)
  215. {
  216.     BOOL fSuccess;
  217.  
  218.     switch (msg){
  219.     case WM_INITDIALOG:
  220.         SetDlgItemInt(hwnd, IDEF_FLAGS, CCFilter.wFlags, FALSE);
  221.         SetDlgItemInt(hwnd, IDEF_COUNTRY, CCFilter.wCountryID, FALSE);
  222.         SetDlgItemInt(hwnd, IDEF_CODEPAGE, CCFilter.iCodePage, TRUE);
  223.         SetDlgItemLong(hwnd, IDEF_LANG, CCFilter.dwLangID, FALSE);
  224.         SetDlgItemLong(hwnd, IDEF_SECURITY, CCFilter.dwSecurity, FALSE);
  225.         return(1);
  226.         break;
  227.  
  228.     case WM_COMMAND:
  229.         switch (wParam) {
  230.         case IDOK:
  231.             CCFilter.wFlags = GetDlgItemInt(hwnd, IDEF_FLAGS, &fSuccess, FALSE);
  232.             if (!fSuccess) return(0);
  233.             CCFilter.wCountryID = GetDlgItemInt(hwnd, IDEF_COUNTRY, &fSuccess, FALSE);
  234.             if (!fSuccess) return(0);
  235.             CCFilter.iCodePage = GetDlgItemInt(hwnd, IDEF_CODEPAGE, &fSuccess, TRUE);
  236.             if (!fSuccess) return(0);
  237.             CCFilter.dwLangID = GetDlgItemLong(hwnd, IDEF_LANG, &fSuccess, FALSE);
  238.             if (!fSuccess) return(0);
  239.             CCFilter.dwSecurity = GetDlgItemLong(hwnd, IDEF_SECURITY, &fSuccess, FALSE);
  240.             if (!fSuccess) return(0);
  241.             // fall through
  242.         case IDCANCEL:
  243.             EndDialog(hwnd, 0);
  244.             break;
  245.  
  246.         default:
  247.             return(FALSE);
  248.         }
  249.         break;
  250.     }
  251.     return(FALSE);
  252. }
  253.  
  254.  
  255.  
  256.  
  257. LONG GetDlgItemLong(
  258. HWND hwnd,
  259. WORD id,
  260. BOOL *pfTranslated,
  261. BOOL fSigned)
  262. {
  263.     char szT[20];
  264.  
  265.     if (!GetDlgItemText(hwnd, id, szT, 20)) {
  266.         if (pfTranslated != NULL) {
  267.             *pfTranslated = FALSE;
  268.         }
  269.         return(0L);
  270.     }
  271.     if (pfTranslated != NULL) {
  272.         *pfTranslated = TRUE;
  273.     }
  274.     return(atol(szT));
  275. }
  276.  
  277.  
  278. VOID SetDlgItemLong(
  279. HWND hwnd,
  280. WORD id,
  281. LONG l,
  282. BOOL fSigned)
  283. {
  284.     char szT[20];
  285.  
  286.     ltoa(l, szT, 10);
  287.     SetDlgItemText(hwnd, id, szT);
  288. }
  289.