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 / ddemlsv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  22.9 KB  |  662 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. /****************************************************************************
  13.  
  14.     PROGRAM: Server.c
  15.  
  16.     PURPOSE: Server template for Windows applications
  17.  
  18.     FUNCTIONS:
  19.  
  20.         WinMain() - calls initialization function, processes message loop
  21.         InitApplication() - initializes window data and registers window
  22.         InitInstance() - saves instance handle and creates main window
  23.         MainWndProc() - processes messages
  24.         About() - processes messages for "About" dialog box
  25.  
  26.     COMMENTS:
  27.  
  28.         Windows can have several copies of your application running at the
  29.         same time.  The variable hInst keeps track of which instance this
  30.         application is so that processing will be to the correct window.
  31.  
  32. ****************************************************************************/
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <tchar.h>
  38. #include "server.h"                 /* specific to this program              */
  39. #include "huge.h"
  40.  
  41. DWORD idInst = 0;
  42. CONVCONTEXT CCFilter = { sizeof(CONVCONTEXT), 0, 0, 0, 0L, 0L,
  43.     {
  44.         sizeof(SECURITY_QUALITY_OF_SERVICE),
  45.         SecurityImpersonation,
  46.         SECURITY_STATIC_TRACKING,
  47.         TRUE
  48.     }
  49. };
  50. HANDLE hInst;                       /* current instance                      */
  51. HWND hwndServer;
  52. RECT rcRand;
  53. RECT rcCount;
  54. RECT rcComment;
  55. RECT rcExec;
  56. RECT rcConnCount;
  57. RECT rcRndrDelay;
  58. RECT rcRunaway;
  59. RECT rcAllBlock;
  60. RECT rcNextAction;
  61. RECT rcHugeSize;
  62. RECT rcAppowned;
  63. BOOL fAllBlocked = FALSE;
  64. BOOL fAllEnabled = TRUE;
  65. BOOL fEnableOneCB = FALSE;
  66. BOOL fBlockNextCB = FALSE;
  67. BOOL fTermNextCB = FALSE;
  68. BOOL fAppowned = FALSE;
  69. WORD cRunaway = 0;
  70. WORD RenderDelay = 0;
  71. DWORD count = 0;
  72. WORD seed = 0;
  73. HSZ hszAppName = 0;
  74. TCHAR szClass[] = TEXT("ServerWClass");
  75. TCHAR szTopic[MAX_TOPIC] = TEXT("Test");
  76. TCHAR szServer[MAX_TOPIC] = TEXT("Server");
  77. TCHAR szComment[MAX_COMMENT] = TEXT("");
  78. TCHAR szExec[MAX_EXEC] = TEXT("");
  79. TCHAR *pszComment = szComment;
  80. WORD cyText;
  81. WORD cServers = 0;
  82. HDDEDATA hDataHelp[CFORMATS] = {0};
  83. HDDEDATA hDataCount[CFORMATS] = {0};
  84. HDDEDATA hDataRand[CFORMATS] = {0};
  85. HDDEDATA hDataHuge[CFORMATS] = {0};
  86. DWORD cbHuge = 0;
  87.  
  88. TCHAR szDdeHelp[] = TEXT("DDEML test server help:\r\n\n")\
  89.     TEXT("The 'Server'(service) and 'Test'(topic) names may change.\r\n\n")\
  90.     TEXT("Items supported under the 'Test' topic are:\r\n")\
  91.     TEXT("\tCount:\tThis value increments on each data change.\r\n")\
  92.     TEXT("\tRand:\tThis value is randomly generated each data change.\r\n")\
  93.     TEXT("\tHuge:\tThis is randomlly generated text data >64k that the\r\n")\
  94.     TEXT("\t\tDDEML test client can verify.\r\n")\
  95.     TEXT("The above items change after any request if in Runaway mode and \r\n")\
  96.     TEXT("can bo POKEed in order to change their values.  POKEed Huge data \r\n")\
  97.     TEXT("must be in a special format to verify the correctness of the data \r\n")\
  98.     TEXT("or it will not be accepted.\r\n")\
  99.     TEXT("If the server is set to use app owned data handles, all data sent \r\n")\
  100.     TEXT("uses HDATA_APPOWNED data handles.")\
  101.     ;
  102.  
  103. FORMATINFO aFormats[CFORMATS] = {
  104. #ifdef UNICODE
  105.     { 0, TEXT("CF_UNICODETEXT") },       // exception!  predefined format
  106. #else
  107.     { 0, TEXT("CF_TEXT") },       // exception!  predefined format
  108. #endif
  109.     { 0, TEXT("Dummy1")  },
  110.     { 0, TEXT("Dummy2")  },
  111. };
  112.  
  113.  
  114. /*
  115.  *          Topic and Item tables supported by this application.
  116.  */
  117.  
  118. /*   HSZ    PROCEDURE       PSZ        */
  119.  
  120. ITEMLIST SystemTopicItemList[CSYSTEMITEMS] = {
  121.  
  122.     { 0, TopicListXfer,  SZDDESYS_ITEM_TOPICS   },
  123.     { 0, ItemListXfer,   SZDDESYS_ITEM_SYSITEMS },
  124.     { 0, sysFormatsXfer, SZDDESYS_ITEM_FORMATS  },
  125.     { 0, HelpXfer,       SZDDESYS_ITEM_HELP},
  126.   };
  127.  
  128.  
  129. ITEMLIST TestTopicItemList[CTESTITEMS] = {
  130.  
  131.     { 0, TestRandomXfer, TEXT("Rand") },   // 0 index
  132.     { 0, TestCountXfer,  TEXT("Count")},   // 1 index
  133.     { 0, TestHugeXfer,   TEXT("Huge") },   // 2 index
  134.     { 0, ItemListXfer,   SZDDESYS_ITEM_SYSITEMS },  // 3 index
  135.   };
  136.  
  137.  
  138. /* The system topic is always assumed to be first. */
  139. /*   HSZ   PROCEDURE            #ofITEMS        PSZ     */
  140. TOPICLIST topicList[CTOPICS] = {
  141.  
  142.     { 0, SystemTopicItemList,   CSYSTEMITEMS,   SZDDESYS_TOPIC},    // 0 index
  143.     { 0, TestTopicItemList,     CTESTITEMS,     szTopic},           // 1 index
  144.   };
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. /****************************************************************************
  152.  
  153.     FUNCTION: WinMain(HANDLE, HANDLE, LPTSTR, int)
  154.  
  155.     PURPOSE: calls initialization function, processes message loop
  156.  
  157.     COMMENTS:
  158.  
  159.         Windows recognizes this function by name as the initial entry point
  160.         for the program.  This function calls the application initialization
  161.         routine, if no other instance of the program is running, and always
  162.         calls the instance initialization routine.  It then executes a message
  163.         retrieval and dispatch loop that is the top-level control structure
  164.         for the remainder of execution.  The loop is terminated when a WM_QUIT
  165.         message is received, at which time this function exits the application
  166.         instance by returning the value passed by PostQuitMessage().
  167.  
  168.         If this function must abort before entering the message loop, it
  169.         returns the conventional value NULL.
  170.  
  171. ****************************************************************************/
  172.  
  173. INT WINAPI WinMain(
  174. HINSTANCE hInstance,
  175. HINSTANCE hPrevInstance,
  176. LPSTR lpCmdLine,
  177. INT nCmdShow)
  178. {
  179.     MSG msg;                                 /* message                      */
  180.  
  181.     if (!hPrevInstance)                  /* Other instances of app running? */
  182.         if (!InitApplication(hInstance)) /* Initialize shared things */
  183.             return (FALSE);              /* Exits if unable to initialize     */
  184.  
  185.     /* Perform initializations that apply to a specific instance */
  186.  
  187.     if (!InitInstance(hInstance, nCmdShow))
  188.         return (FALSE);
  189.  
  190.     /* Acquire and dispatch messages until a WM_QUIT message is received. */
  191.  
  192.     while (GetMessage(&msg,     /* message structure                      */
  193.             0,                  /* handle of window receiving the message */
  194.             0,                  /* lowest message to examine              */
  195.             0))                 /* highest message to examine             */
  196.         {
  197.         TranslateMessage(&msg);    /* Translates virtual key codes           */
  198.         DispatchMessage(&msg);     /* Dispatches message to window           */
  199.     }
  200.  
  201.     UnregisterClass(szClass, hInstance);
  202.     return (msg.wParam);           /* Returns the value from PostQuitMessage */
  203. }
  204.  
  205.  
  206. /****************************************************************************
  207.  
  208.     FUNCTION: InitApplication(HANDLE)
  209.  
  210.     PURPOSE: Initializes window data and registers window class
  211.  
  212.     COMMENTS:
  213.  
  214.         This function is called at initialization time only if no other
  215.         instances of the application are running.  This function performs
  216.         initialization tasks that can be done once for any number of running
  217.         instances.
  218.  
  219.         In this case, we initialize a window class by filling out a data
  220.         structure of type WNDCLASS and calling the Windows RegisterClass()
  221.         function.  Since all instances of this application use the same window
  222.         class, we only need to do this when the first instance is initialized.
  223.  
  224.  
  225. ****************************************************************************/
  226.  
  227. BOOL InitApplication(hInstance)
  228. HANDLE hInstance;                              /* current instance           */
  229. {
  230.     WNDCLASS  wc;
  231.  
  232.     /* Fill in window class structure with parameters that describe the       */
  233.     /* main window.                                                           */
  234.  
  235.     wc.style = 0;                       /* Class style(s).                    */
  236.     wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  */
  237.                                         /* windows of this class.             */
  238.     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
  239.     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
  240.     wc.hInstance = hInstance;           /* Application that owns the class.   */
  241.     wc.hIcon = LoadIcon(hInstance, TEXT("server"));
  242.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  243.     wc.hbrBackground = (HANDLE)(COLOR_APPWORKSPACE+1);
  244.     wc.lpszMenuName =  TEXT("ServerMenu");   /* Name of menu resource in .RC file. */
  245.     wc.lpszClassName = TEXT("ServerWClass"); /* Name used in call to CreateWindow. */
  246.  
  247.     /* Register the window class and return success/failure code. */
  248.  
  249.     return (RegisterClass(&wc));
  250.  
  251. }
  252.  
  253.  
  254. /****************************************************************************
  255.  
  256.     FUNCTION:  InitInstance(HANDLE, int)
  257.  
  258.     PURPOSE:  Saves instance handle and creates main window
  259.  
  260.     COMMENTS:
  261.  
  262.         This function is called at initialization time for every instance of
  263.         this application.  This function performs initialization tasks that
  264.         cannot be shared by multiple instances.
  265.  
  266.         In this case, we save the instance handle in a static variable and
  267.         create and display the main program window.
  268.  
  269. ****************************************************************************/
  270.  
  271. BOOL InitInstance(hInstance, nCmdShow)
  272.     HANDLE          hInstance;          /* Current instance identifier.       */
  273.     INT             nCmdShow;           /* Param for first ShowWindow() call. */
  274. {
  275.     INT i;
  276.     RECT Rect;
  277.     TEXTMETRIC metrics;
  278.     HDC hdc;
  279.     TCHAR szTitle[40] =
  280. #ifdef UNICODE
  281.         TEXT("Server|Test (Unicode)");
  282. #else
  283.         TEXT("Server|Test");
  284. #endif
  285.  
  286.     /* Save the instance handle in static variable, which will be used in  */
  287.     /* many subsequence calls from this application to Windows.            */
  288.  
  289.     hInst = hInstance;
  290.  
  291.  
  292.     /* Create a main window for this application instance.  */
  293.  
  294.     hwndServer = CreateWindow(
  295.         TEXT("ServerWClass"),                /* See RegisterClass() call.          */
  296.         szTitle,
  297.         WS_OVERLAPPEDWINDOW,            /* Window style.                      */
  298.         CW_USEDEFAULT,                  /* Default horizontal position.       */
  299.         CW_USEDEFAULT,                  /* Default vertical position.         */
  300.         400,
  301.         200,
  302.         NULL,                           /* Overlapped windows have no parent. */
  303.         NULL,                           /* Use the window class menu.         */
  304.         hInstance,                      /* This instance owns this window.    */
  305.         NULL                            /* Pointer not needed.                */
  306.     );
  307.  
  308.     GetClientRect(hwndServer, (LPRECT) &Rect);
  309.  
  310.     /* If window could not be created, return "failure" */
  311.  
  312.     if (!hwndServer)
  313.         return (FALSE);
  314.  
  315.     hdc = GetDC(hwndServer);
  316.     GetTextMetrics(hdc, &metrics);
  317.     cyText = (WORD)(metrics.tmHeight + metrics.tmExternalLeading);
  318.     ReleaseDC(hwndServer, hdc);
  319.  
  320. #ifdef UNICODE
  321.     aFormats[0].atom = CF_UNICODETEXT; // exception - predefined.
  322. #else
  323.     aFormats[0].atom = CF_TEXT; // exception - predefined.
  324. #endif
  325.     for (i = 1; i < CFORMATS; i++) {
  326.         aFormats[i].atom = RegisterClipboardFormat(aFormats[i].sz);
  327.     }
  328.  
  329.     /* Make the window visible; update its client area; and return "success" */
  330.  
  331.     ShowWindow(hwndServer, nCmdShow);  /* Show the window                        */
  332.     UpdateWindow(hwndServer);          /* Sends WM_PAINT message                 */
  333.     seed = 1;
  334.     srand(1);
  335.     CCFilter.iCodePage = CP_WINANSI;   // initial default codepage
  336.     if (!DdeInitialize(&idInst, (PFNCALLBACK)MakeProcInstance((FARPROC)DdeCallback,
  337.                 hInstance), APPCMD_FILTERINITS, 0)) {
  338.         Hszize();
  339.         DdeNameService(idInst, hszAppName, 0, DNS_REGISTER);
  340.         return(TRUE);
  341.     }
  342.     return (FALSE);
  343.  
  344. }
  345.  
  346. /****************************************************************************
  347.  
  348.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  349.  
  350.     PURPOSE:  Processes messages
  351.  
  352.     MESSAGES:
  353.  
  354.         WM_COMMAND    - application menu (About dialog box)
  355.         WM_DESTROY    - destroy window
  356.  
  357.     COMMENTS:
  358.  
  359.         To process the IDM_ABOUT message, call MakeProcInstance() to get the
  360.         current instance address of the About() function.  Then call Dialog
  361.         box which will create the box according to the information in your
  362.         server.rc file and turn control over to the About() function.   When
  363.         it returns, free the intance address.
  364.  
  365. ****************************************************************************/
  366.  
  367. LONG  APIENTRY MainWndProc(hWnd, message, wParam, lParam)
  368. HWND hWnd;                                /* window handle                   */
  369. UINT message;                         /* type of message                 */
  370. WPARAM wParam;                              /* additional information          */
  371. LPARAM lParam;                              /* additional information          */
  372. {
  373.     switch (message) {
  374.     case WM_INITMENU:
  375.         if (GetMenu(hWnd) != (HMENU)wParam)
  376.             break;
  377.  
  378.         CheckMenuItem((HMENU)wParam, IDM_BLOCKALLCBS,
  379.                 fAllBlocked ? MF_CHECKED : MF_UNCHECKED);
  380.         CheckMenuItem((HMENU)wParam, IDM_UNBLOCKALLCBS,
  381.                 fAllEnabled ? MF_CHECKED : MF_UNCHECKED);
  382.         CheckMenuItem((HMENU)wParam, IDM_BLOCKNEXTCB,
  383.                 fBlockNextCB ? MF_CHECKED : MF_UNCHECKED);
  384.         CheckMenuItem((HMENU)wParam, IDM_TERMNEXTCB,
  385.                 fTermNextCB ? MF_CHECKED : MF_UNCHECKED);
  386.         CheckMenuItem((HMENU)wParam, IDM_RUNAWAY,
  387.                 cRunaway ? MF_CHECKED : MF_UNCHECKED);
  388.         CheckMenuItem((HMENU)wParam, IDM_APPOWNED,
  389.                 fAppowned ? MF_CHECKED : MF_UNCHECKED);
  390.         break;
  391.  
  392.     case WM_COMMAND:           /* message: command from application menu */
  393.         switch (LOWORD(wParam)) {
  394.         case IDM_ENABLEONECB:
  395.             DdeEnableCallback(idInst, 0, EC_ENABLEONE);
  396.             fAllBlocked = FALSE;
  397.             fAllEnabled = FALSE;
  398.             InvalidateRect(hwndServer, &rcAllBlock, TRUE);
  399.             break;
  400.  
  401.         case IDM_TERMNEXTCB:
  402.             fTermNextCB = !fTermNextCB;
  403.             InvalidateRect(hwndServer, &rcNextAction, TRUE);
  404.             break;
  405.  
  406.         case IDM_BLOCKNEXTCB:
  407.             fBlockNextCB = !fBlockNextCB;
  408.             InvalidateRect(hwndServer, &rcNextAction, TRUE);
  409.             break;
  410.  
  411.         case IDM_BLOCKALLCBS:
  412.             DdeEnableCallback(idInst, 0, EC_DISABLE);
  413.             fAllBlocked = TRUE;
  414.             fAllEnabled = FALSE;
  415.             InvalidateRect(hwndServer, &rcAllBlock, TRUE);
  416.             break;
  417.  
  418.         case IDM_UNBLOCKALLCBS:
  419.             DdeEnableCallback(idInst, 0, EC_ENABLEALL);
  420.             fAllEnabled = TRUE;
  421.             fAllBlocked = FALSE;
  422.             InvalidateRect(hwndServer, &rcAllBlock, TRUE);
  423.             break;
  424.  
  425.         case IDM_APPOWNED:
  426.             fAppowned = !fAppowned;
  427.             if (!fAppowned) {
  428.                 WORD iFmt;
  429.                 for (iFmt = 0; iFmt < CFORMATS; iFmt++) {
  430.                     if (hDataHuge[iFmt]) {
  431.                         DdeFreeDataHandle(hDataHuge[iFmt]);
  432.                         hDataHuge[iFmt] = 0;
  433.                         InvalidateRect(hwndServer, &rcHugeSize, TRUE);
  434.                     }
  435.                     if (hDataCount[iFmt]) {
  436.                         DdeFreeDataHandle(hDataCount[iFmt]);
  437.                         hDataCount[iFmt] = 0;
  438.                     }
  439.                     if (hDataRand[iFmt]) {
  440.                         DdeFreeDataHandle(hDataRand[iFmt]);
  441.                         hDataRand[iFmt] = 0;
  442.                     }
  443.                     if (hDataHelp[iFmt]) {
  444.                         DdeFreeDataHandle(hDataHelp[iFmt]);
  445.                         hDataHelp[iFmt] = 0;
  446.                     }
  447.                 }
  448.             }
  449.             InvalidateRect(hwndServer, &rcAppowned, TRUE);
  450.             break;
  451.  
  452.         case IDM_RUNAWAY:
  453.             cRunaway = !cRunaway;
  454.             InvalidateRect(hwndServer, &rcRunaway, TRUE);
  455.             if (!cRunaway) {
  456.                 break;
  457.             }
  458.             // fall through
  459.  
  460.         case IDM_CHANGEDATA:
  461.             PostMessage(hwndServer, UM_CHGDATA, 1, 0);  // rand
  462.             PostMessage(hwndServer, UM_CHGDATA, 1, 1);  // count
  463.             break;
  464.  
  465.         case IDM_RENDERDELAY:
  466.             DoDialog(MAKEINTRESOURCE(DID_VALUEENTRY), (DLGPROC)RenderDelayDlgProc, 0, TRUE);
  467.             InvalidateRect(hwndServer, &rcRndrDelay, TRUE);
  468.             break;
  469.  
  470.         case IDM_SETSERVER:
  471.             DoDialog(MAKEINTRESOURCE(DID_VALUEENTRY), (DLGPROC)SetServerDlgProc, 0, TRUE);
  472.             break;
  473.  
  474.         case IDM_SETTOPIC:
  475.             DoDialog(MAKEINTRESOURCE(DID_VALUEENTRY), (DLGPROC)SetTopicDlgProc, 0, TRUE);
  476.             break;
  477.  
  478.         case IDM_CONTEXT:
  479.             DoDialog(MAKEINTRESOURCE(DID_CONTEXT), (DLGPROC)ContextDlgProc, 0, TRUE);
  480.             break;
  481.  
  482.         case IDM_ABOUT:
  483.             DoDialog(MAKEINTRESOURCE(DID_ABOUT), (DLGPROC)About, 0, TRUE);
  484.             break;
  485.  
  486.         case IDM_HELP:
  487.            break;
  488.  
  489.         default:
  490.             return (DefWindowProc(hWnd, message, wParam, lParam));
  491.         }
  492.         break;
  493.  
  494.     case WM_PAINT:
  495.         PaintServer(hWnd);
  496.         break;
  497.  
  498.     case UM_CHGDATA:
  499.         {
  500.             WORD iFmt;
  501.  
  502.             // wParam = TopicIndex,
  503.             // LOWORD(lParam) = ItemIndex
  504.             // We asynchronously do DdePostAdvise() calls to prevent infinite
  505.             // loops when in runaway mode.
  506.             if (wParam == 1) {  // test topic
  507.                 if (lParam == 0) {  // rand item
  508.                     seed = rand();
  509.                     for (iFmt = 0; iFmt < CFORMATS ; iFmt++) {
  510.                         if (hDataRand[iFmt]) {
  511.                             DdeFreeDataHandle(hDataRand[iFmt]);
  512.                             hDataRand[iFmt] = 0;
  513.                         }
  514.                     }
  515.                     InvalidateRect(hwndServer, &rcRand, TRUE);
  516.                     DdePostAdvise(idInst, topicList[wParam].hszTopic,
  517.                             (HSZ)topicList[wParam].pItemList[lParam].hszItem);
  518.                 }
  519.                 if (lParam == 1) {  // count item
  520.                     count++;
  521.                     for (iFmt = 0; iFmt < CFORMATS ; iFmt++) {
  522.                         if (hDataCount[iFmt]) {
  523.                             DdeFreeDataHandle(hDataCount[iFmt]);
  524.                             hDataCount[iFmt] = 0;
  525.                         }
  526.                     }
  527.                     InvalidateRect(hwndServer, &rcCount, TRUE);
  528.                     DdePostAdvise(idInst, topicList[wParam].hszTopic,
  529.                             (HSZ)topicList[wParam].pItemList[lParam].hszItem);
  530.                 }
  531.                 // Huge item does not runaway - too slow.
  532.             }
  533.             if (cRunaway) {
  534.                 Delay(50, TRUE);
  535.                         // This gives enough time for the system to remain
  536.                         // useable in runaway mode.
  537.                 PostMessage(hwndServer, UM_CHGDATA, wParam, lParam);
  538.             }
  539.         }
  540.         break;
  541.  
  542.     case WM_DESTROY:                  /* message: window being destroyed */
  543.         if (fAppowned)
  544.             SendMessage(hwndServer, WM_COMMAND, (WPARAM)MAKELONG(IDM_APPOWNED, 0), (LONG)(0));
  545.         DdeNameService(idInst, 0, 0, DNS_UNREGISTER); // unregister all services
  546.         UnHszize();
  547.         DdeUninitialize(idInst);
  548.         PostQuitMessage(0);
  549.         break;
  550.  
  551.     default:
  552.         return (DefWindowProc(hWnd, message, wParam, lParam));
  553.     }
  554.     return(0);
  555. }
  556.  
  557.  
  558.  
  559.  
  560.  
  561. VOID Delay(
  562. DWORD delay,
  563. BOOL fModal)
  564. {
  565.     MSG msg;
  566.     delay = GetCurrentTime() + delay;
  567.     while (GetCurrentTime() < delay) {
  568.         if (fModal && PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
  569.             TranslateMessage(&msg);
  570.             DispatchMessage(&msg);
  571.         }
  572.     }
  573. }
  574.  
  575.  
  576.  
  577. /*
  578.  * This function not only paints the server client area with current info,
  579.  * it also has the side effect of setting the global RECTs that bound each
  580.  * info area.  This way flashing is reduced.
  581.  */
  582. VOID PaintServer(
  583. HWND hwnd)
  584. {
  585.     PAINTSTRUCT ps;
  586.     RECT rc;
  587.     TCHAR szT[MAX_COMMENT];
  588.  
  589.     BeginPaint(hwnd, &ps);
  590.     SetBkMode(ps.hdc, TRANSPARENT);
  591.     GetClientRect(hwnd, &rc);
  592.     rc.bottom = rc.top + cyText;    // all rects are cyText in height.
  593.  
  594.     rcComment = rc;
  595.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, pszComment);
  596.  
  597.     wsprintf(szT, TEXT("# of connections:%d"), cServers);
  598.     rcConnCount = rc;
  599.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  600.  
  601.     szT[0] = TEXT('\0');
  602.     rcAllBlock = rc;
  603.     if (fAllEnabled)
  604.         DrawTextLine(ps.hdc, &ps.rcPaint, &rc, TEXT("All Conversations are Enabled."));
  605.     else if (fAllBlocked)
  606.         DrawTextLine(ps.hdc, &ps.rcPaint, &rc, TEXT("All Conversations are Blocked."));
  607.     else
  608.         DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  609.  
  610.     rcNextAction = rc;
  611.     if (fBlockNextCB)
  612.         DrawTextLine(ps.hdc, &ps.rcPaint, &rc, TEXT("Next callback will block."));
  613.     else if (fTermNextCB)
  614.         DrawTextLine(ps.hdc, &ps.rcPaint, &rc, TEXT("Next callback will terminate."));
  615.     else
  616.         DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  617.  
  618.     wsprintf(szT, TEXT("Count item = %ld"), count);
  619.     rcCount = rc;
  620.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  621.  
  622.     wsprintf(szT, TEXT("Rand item = %d"), seed);
  623.     rcRand = rc;
  624.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  625.  
  626.     wsprintf(szT, TEXT("Huge item size = %ld"), cbHuge);
  627.     rcHugeSize = rc;
  628.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  629.  
  630.     wsprintf(szT, TEXT("Render delay is %d milliseconds."), RenderDelay);
  631.     rcRndrDelay = rc;
  632.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szT);
  633.  
  634.     rcExec = rc;
  635.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, szExec);
  636.  
  637.     rcRunaway = rc;
  638.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, cRunaway ? TEXT("Runaway active.") : TEXT(""));
  639.  
  640.     rcAppowned = rc;
  641.     DrawTextLine(ps.hdc, &ps.rcPaint, &rc, fAppowned ? TEXT("Using AppOwned Data Handles.") : TEXT(""));
  642.  
  643.     EndPaint(hwnd, &ps);
  644. }
  645.  
  646.  
  647. VOID DrawTextLine(
  648. HDC hdc,
  649. RECT *prcClip,
  650. RECT *prcText,
  651. PTSTR psz)
  652. {
  653.     RECT rc;
  654.  
  655.     if (IntersectRect(&rc, prcText, prcClip)) {
  656.         DrawText(hdc, psz, -1, prcText,
  657.                 DT_LEFT | DT_EXTERNALLEADING | DT_SINGLELINE | DT_EXPANDTABS |
  658.                 DT_NOCLIP | DT_NOPREFIX);
  659.     }
  660.     OffsetRect(prcText, 0, cyText);
  661. }
  662.