DIALOG.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:9k
源码类别:

Windows编程

开发平台:

Visual C++

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