home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / ipc / ddeml / server / dialog.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  9KB  |  278 lines

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