home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / S12602.ZIP / WELCOME1.C < prev    next >
C/C++ Source or Header  |  1990-05-17  |  24KB  |  782 lines

  1. #define INCL_BASE
  2. #define INCL_PM
  3.  
  4. #include <os2.h>
  5. #include "welcome1.h"
  6. #include <string.h>
  7. #include <stdio.h>
  8.  
  9. // #define DEBUG
  10.  
  11. #ifdef DEBUG
  12.  
  13. /* For details on using additional debugging output routines for PM
  14.    programs see KnowledgeBase article q43027 and softlib file pmutils.arc
  15.  
  16.    If you define DEBUG, you will need to add utils.lib to the LINK line in
  17.    the MAKEFILE.
  18. */
  19.  
  20. #include "\pmapps\utils\utils.h"
  21. #endif
  22.  
  23. #define SZREQUESTDATA "data from WM_DDE_REQUEST"
  24.  
  25. BOOL DisplayabData (HWND , PDDESTRUCT) ;
  26. void DisplayusFormat (HWND, USHORT) ;
  27. void DisplayDdeMsgType (HWND, USHORT) ;
  28. void DisplaywStatus (HWND, USHORT) ;
  29.  
  30. PDDESTRUCT MakeDDESegment (HWND, PSZ, USHORT, USHORT, PVOID, USHORT) ;
  31. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  32.  
  33. BOOL fQuiet=FALSE;  /* flag to turn off message boxes */
  34.  
  35. HWND hwndServer ;
  36. HWND hwndClient ;
  37. BOOL fInitSucceed;
  38. HWND hwndWelcomeClient;
  39. HWND hwndFrame;
  40.  
  41. char ThreadStack[4096];
  42.  
  43. int main (void)
  44.      {
  45.      static CHAR  szClientClass [] = "Welcome1" ;
  46.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  47.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  48.                  FCF_SHELLPOSITION | FCF_TASKLIST |
  49.                  FCF_MENU ;
  50.      HAB          hab ;
  51.      HMQ          hmq ;
  52.      QMSG         qmsg ;
  53.  
  54.      hab = WinInitialize (0) ;
  55.      hmq = WinCreateMsgQueue (hab, 0) ;
  56.  
  57.      WinRegisterClass (
  58.                     hab,                // Anchor block handle
  59.                     szClientClass,      // Name of class being registered
  60.                     ClientWndProc,      // Window procedure for class
  61.                     CS_SIZEREDRAW,      // Class style
  62.                     0) ;                // Extra bytes to reserve
  63.  
  64.      hwndFrame = WinCreateStdWindow (
  65.                     HWND_DESKTOP,       // Parent window handle
  66.                     WS_VISIBLE,         // Style of frame window
  67.                     &flFrameFlags,      // Pointer to control data
  68.                     szClientClass,      // Client window class name
  69.                     NULL,               // Title bar text
  70.                     0L,                 // Style of client window
  71.                     0,                 // Module handle for resources
  72.             ID_RESOURCE,    // ID of resources
  73.                     &hwndWelcomeClient) ;      // Pointer to client window handle
  74.  
  75.      WinSendMsg (hwndFrame, WM_SETICON,
  76.                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
  77.                  0L) ;
  78.  
  79.      while (WinGetMsg (hab, &qmsg, 0L, 0, 0))
  80.           WinDispatchMsg (hab, &qmsg) ;
  81.  
  82.      WinDestroyWindow (hwndFrame) ;
  83.      WinDestroyMsgQueue (hmq) ;
  84.      WinTerminate (hab) ;
  85.      return 0 ;
  86.      }
  87.  
  88.  
  89. MRESULT EXPENTRY GetValueDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  90.      {
  91.  
  92.      static HWND   hwndButton ;
  93.      SHORT       sLen ;
  94.      static char   szBuffer [SZBUF_SIZE] = {0L} ;
  95.      static CHAR FAR * szString ;
  96.  
  97.      switch (msg)
  98.       {
  99.       case WM_INITDLG:
  100.            WinAlarm (HWND_DESKTOP, WA_NOTE) ;
  101.  
  102.            szString = PVOIDFROMMP (mp2) ;
  103.  
  104.                WinSendDlgItemMsg(hwnd,
  105.                                  IDD_CRITEREA,
  106.                                  EM_SETTEXTLIMIT,
  107.                                  MPFROMSHORT( (SHORT) SZBUF_SIZE),
  108.                                  0L);
  109.  
  110.            WinSetDlgItemText (hwnd, IDD_TEXT, szString) ;
  111.  
  112.            hwndButton = WinWindowFromID (hwnd, IDD_CRITEREA) ;
  113.            WinSetDlgItemText (hwnd, IDD_CRITEREA, "") ;
  114.  
  115.            return 0 ;
  116.  
  117.           case WM_COMMAND:
  118.                switch (COMMANDMSG(&msg)->cmd)
  119.                     {
  120.             case IDD_OK:
  121.  
  122.              sLen = WinQueryWindowTextLength (hwndButton) + 1 ;
  123.              WinQueryWindowText (hwndButton, sLen, szString) ;
  124.              WinDismissDlg (hwnd, TRUE) ;
  125.              return 0 ;
  126.  
  127.             case IDD_CANCEL:
  128.  
  129.              WinDismissDlg (hwnd, FALSE) ;
  130.                          return 0 ;
  131.                     }
  132.                break ;
  133.           }
  134.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  135.      }
  136.  
  137.  
  138. PDDESTRUCT MakeDDESegment (hwndDest, pszItemName, fsStatus, usFormat, pabData, usDataLen )
  139. HWND     hwndDest ;
  140. PSZ      pszItemName ;
  141. USHORT   fsStatus ;
  142. USHORT   usFormat ;
  143. PVOID    pabData ;
  144. USHORT   usDataLen ;
  145.  
  146. {
  147. PDDESTRUCT pddes ;
  148. USHORT     usItemLen ;
  149. SEL        selBuf ;
  150.  
  151.     if (pszItemName != 0L)
  152.        usItemLen = strlen (pszItemName) + 1 ;
  153.     else
  154.        usItemLen = 0 ;
  155.  
  156.     if (! DosAllocSeg (sizeof (DDESTRUCT) + usItemLen + usDataLen,
  157.                        &selBuf, SEG_GIVEABLE))
  158.         {
  159.         pddes = SELTOPDDES (selBuf) ;
  160.         pddes -> cbData = usDataLen - 1; /* subtract 1 to make it work ??????? */
  161.         pddes -> fsStatus = fsStatus ;
  162.         pddes -> usFormat = usFormat ;
  163.         pddes -> offszItemName = sizeof (DDESTRUCT) ;
  164.  
  165.         if ((usDataLen) && (pabData))
  166.             pddes->offabData = sizeof (DDESTRUCT) + usItemLen ;
  167.         else
  168.             pddes -> offabData = sizeof (DDESTRUCT) ;
  169.  
  170.         if (pszItemName != NULL)
  171.             strcpy (DDES_PSZITEMNAME (pddes) , pszItemName) ;
  172.  
  173.         memcpy (DDES_PABDATA (pddes), pabData, usDataLen) ;
  174.         }
  175.  
  176.     return (pddes) ;
  177. }
  178.  
  179.  
  180. /*  ===================    Spawn Excel thread  ======================== */
  181.  
  182. /*  This thread spawns a copy of Excel using DosStartSession and then
  183.     waits until Excel adds itself to the task list before initiating a DDE
  184.     conversation with Excel.  Its kind of a hack in the way it determines
  185.     that Excel is ready for DDE since Excel doesn't provide a more formal
  186.     interface to let other apps know when it is ready
  187.  
  188.     =================================================================== */
  189.  
  190.  
  191. VOID SpawnExcel(VOID)
  192. {
  193. STARTDATA stdata;
  194. USHORT idSession;
  195. USHORT pid;
  196. PDDESTRUCT pddes;
  197. SEL sel;
  198. PSWBLOCK pswblk;
  199. USHORT cbItems, cbBuf,us;
  200. BOOL found;
  201.  
  202. HAB hab;
  203. HMQ hmq;
  204.  
  205. hab=WinInitialize(0);
  206. hmq=WinCreateMsgQueue(hab, 0);
  207.  
  208. DosBeep(440,500);
  209.  
  210. stdata.Length = sizeof(stdata);
  211. stdata.Related = FALSE;   /* unrelated session */
  212. stdata.FgBg = FALSE;
  213. stdata.TraceOpt = 0;
  214.  
  215. stdata.PgmTitle = "John's Excel"; /* don't put 'Microsoft Excel' here or
  216.                                      you'll not be able to tell when the
  217.                                      real one is started.  */
  218.  
  219. stdata.PgmName = "excel.exe";
  220. stdata.PgmInputs = NULL;
  221. stdata.TermQ = 0;
  222. stdata.Environment = 0;
  223. stdata.InheritOpt = 0;
  224. stdata.SessionType = 3;  /* PM api */
  225. stdata.IconFile = NULL;
  226. stdata.PgmHandle = 0;
  227. stdata.PgmControl = 32768;
  228. stdata.InitXPos = 0;
  229. stdata.InitYPos = 0;
  230. stdata.InitXSize = 0;
  231. stdata.InitYSize = 0;
  232.  
  233. DosStartSession(&stdata, &idSession, &pid);
  234.  
  235. #ifdef DEBUG
  236.     Debug("Excel spawned");
  237. #endif
  238.  
  239. found = FALSE;
  240.  
  241. /* HACK ALERT.  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  242.  
  243. /* The following hack is needed since Excel can't handle it if we just
  244. try to call WinDdeInitiate() repeatedly until we get a
  245. WM_DDE_INITIATEACK message.  Instead, we enumerate the switch list and
  246. wait for the name 'Microsoft Excel' to appear, then we *assume* that
  247. Excel is ready so we cross our fingers and try the WinDdeInitiate.
  248. This works under OS/2 1.2 with Excel 2.2a dated March 9,1990 and it is
  249. probably OK with other versions of OS/2 and Excel but since it is a hack,
  250. things might change in the future but since both Excel and 1.2 are
  251. released this should be OK for quite a while.
  252.  
  253. -John Bartlow 26-Apr-1990
  254. */
  255.  
  256.  
  257. while (!found)
  258.     {
  259.  
  260.     /* It would be best to move the DosAllocSeg/FreeSeg out of this
  261.         while() loop, but then how would you know how much memory to
  262.         allocate since it changes as apps come to life ?????
  263.     */
  264.  
  265.     cbItems = WinQuerySwitchList(hab, NULL, 0);   /* gets num. of items */
  266.     cbBuf = (cbItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  267.     DosAllocSeg(cbBuf, &sel, SEG_NONSHARED);      /* allocates buffer   */
  268.     pswblk = (PSWBLOCK) MAKEP(sel, 0);
  269.  
  270.     WinQuerySwitchList(hab, pswblk, cbBuf);       /* gets struct. array */
  271.  
  272.     us=0;
  273.  
  274.     for (us=0; us < cbItems; us++)
  275.         {
  276. #ifdef DEBUG
  277.         Debug("Task title = %s",pswblk->aswentry[us].swctl.szSwtitle);
  278. #endif
  279.  
  280.         if (!strcmp( pswblk->aswentry[us].swctl.szSwtitle,"Microsoft Excel"))
  281.             break;
  282.         }
  283.  
  284.     if ( ( us < cbItems) &&
  285.          ( !strcmp( pswblk->aswentry[us].swctl.szSwtitle,"Microsoft Excel")) )
  286.         {
  287.         found=TRUE;
  288.         break;
  289.         }
  290.     else
  291.         {
  292.         DosSleep(1000L);   /* give Excel some more time */
  293.         }
  294.  
  295.     DosFreeSeg(sel);
  296.     }
  297.  
  298. /* End HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  */
  299.  
  300. /* We hope its OK to try the DdeInitiate now */
  301.  
  302. WinDdeInitiate (hwndWelcomeClient, "Excel", "System");
  303.  
  304. pddes = MakeDDESegment (hwndServer, 0, 0,
  305.                         DDEFMT_TEXT, "[NEW()]", strlen ("[NEW()]") + 1) ;
  306.  
  307. WinDdePostMsg (hwndServer, hwndWelcomeClient, WM_DDE_EXECUTE, pddes, TRUE) ;
  308. DosFreeSeg (PDDESTOSEL(pddes)) ;
  309. }
  310.  
  311.  
  312. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  313.     {
  314.     static CHAR szString  [128] ;
  315.     static CHAR szString1 [128] ;
  316.     static CHAR szString2 [128] ;
  317.     static CHAR szData    [128] ;
  318.     static CHAR szText [] = "Welcome" ;
  319.  
  320.     PDDESTRUCT pddes ;
  321.     PDDEINIT   pddei ;
  322.  
  323.     HPS         hps;
  324.     RECTL       rcl ;
  325.  
  326.     switch (msg)
  327.         {
  328.         case WM_DDE_INITIATEACK:
  329.             hwndServer = HWNDFROMMP (mp1) ;
  330.  
  331.             fInitSucceed=TRUE;   /* we got an INITIATEACK from Excel */
  332.  
  333.             DosBeep(800,1000);
  334.             DosBeep(400,1000);
  335.             DosBeep(200,1000);
  336.  
  337.             DisplayDdeMsgType (hwnd, msg) ;
  338.             WinInvalidateRect (hwnd, 0L, FALSE) ;
  339.             return (0) ;
  340.  
  341.         case WM_DDE_TERMINATE:
  342.             DisplayDdeMsgType (hwnd, msg) ;
  343.             if (hwndServer)
  344.                WinDdePostMsg (hwndServer, hwnd, WM_DDE_TERMINATE, 0L, TRUE) ;
  345.             if (hwndClient)
  346.                WinDdePostMsg (hwndClient, hwnd, WM_DDE_TERMINATE, 0L, TRUE) ;
  347.             return (0) ;
  348.  
  349.         case WM_DDE_ACK:
  350.             pddes = (PDDESTRUCT) LONGFROMMP (mp2) ;
  351.             DisplayDdeMsgType (hwnd, msg) ;
  352.             DisplaywStatus (hwnd, pddes->fsStatus) ;
  353.             DosFreeSeg (PDDESTOSEL (pddes)) ;
  354.             return (0) ;
  355.  
  356.         case WM_DDE_DATA:
  357.             pddes = (PDDESTRUCT) LONGFROMMP (mp2) ;
  358.             DisplayDdeMsgType (hwnd, msg) ;
  359.             DisplaywStatus (hwnd, pddes->fsStatus) ;
  360.             DisplayusFormat (hwnd, pddes->usFormat) ;
  361.             DisplayabData (hwnd, pddes) ;
  362.             DosFreeSeg (PDDESTOSEL (pddes)) ;
  363.             pddes = MakeDDESegment (hwndServer, szString, DDE_FACK, 0, NULL, 0) ;
  364.             WinDdePostMsg (hwndServer, hwnd, WM_DDE_ACK, pddes, TRUE) ;
  365.             return (0) ;
  366.  
  367.         case WM_DDE_INITIATE:
  368.  
  369.              pddei = (PDDEINIT) LONGFROMMP (mp2) ;
  370.  
  371.              if ( !strcmp(pddei->pszAppName,"Welcome1"))
  372.              {
  373.                 if (!strcmp(pddei->pszTopic,"System"))
  374.                 {
  375.                    WinDdeRespond ((HWND) (LONGFROMMP (mp1)), hwnd,
  376.                                   pddei->pszAppName, pddei->pszTopic) ;
  377.  
  378.                    hwndClient = HWNDFROMMP (mp1) ;
  379.                    WinInvalidateRect (hwnd, NULL, FALSE) ;
  380.  
  381.                 }
  382.              }
  383.              DisplayDdeMsgType (hwnd, msg) ;
  384.  
  385.              if (!fQuiet)
  386.                 {
  387.                 WinMessageBox(HWND_DESKTOP,
  388.                              hwnd,
  389.                              pddei->pszAppName,
  390.                              pddei->pszTopic,
  391.                              0,
  392.                              MB_OK);
  393.                 }
  394.              DosFreeSeg (PDDEITOSEL(pddei)) ;
  395.  
  396.              break ;
  397.  
  398.         case WM_DDE_EXECUTE:
  399.             pddes = (PDDESTRUCT) LONGFROMMP (mp2) ;
  400.             DisplayDdeMsgType (hwnd, msg) ;
  401.             if ( (ULONG) pddes->offabData - (ULONG) pddes->offszItemName < pddes->cbData)
  402.                 DisplayabData (hwnd, pddes) ;
  403.  
  404.             strcpy (szString, (PSZ) ( (LONG) pddes + pddes->offabData)) ;
  405.             DosFreeSeg (PDDESTOSEL (pddes)) ;
  406.  
  407.             pddes = MakeDDESegment ((HWND) LONGFROMMP (mp1), 0L,
  408.                                      DDE_FACK,  DDEFMT_TEXT,
  409.                                      szString, strlen (szString) + 1) ;
  410.             if (pddes)
  411.                 {
  412.                 WinDdePostMsg ((HWND) mp1, hwnd, WM_DDE_ACK,
  413.                               pddes,
  414.                               TRUE);
  415. #ifdef DEBUG
  416.                 Debug("Posted WM_DDE_ACK message");
  417. #endif
  418.                 }
  419.             return(TRUE);
  420.  
  421.             break ;
  422.  
  423.         case WM_DDE_REQUEST:
  424.             DisplayDdeMsgType (hwnd, msg) ;
  425.  
  426.             pddes = (PDDESTRUCT) LONGFROMMP (mp2) ;
  427.  
  428.             strcpy (szString, (PSZ) ( (LONG) pddes + pddes->offszItemName)) ;
  429.  
  430.             if (pddes->usFormat == DDEFMT_TEXT)
  431.                 {
  432.                 pddes = MakeDDESegment(hwndClient,
  433.                                        szString,
  434.                                        DDE_FRESPONSE,
  435.                                        DDEFMT_TEXT,
  436.                                        SZREQUESTDATA,
  437.                                        strlen (SZREQUESTDATA) + 1);
  438.  
  439.                 WinDdePostMsg (hwndClient, hwnd, WM_DDE_DATA, pddes, TRUE) ;
  440.  
  441.                 DosFreeSeg (PDDESTOSEL (pddes)) ;
  442.                 }
  443.             else
  444.                 {
  445.                 /* We don't support this format, so respond with a negative ACK */
  446.  
  447.                 pddes = MakeDDESegment(hwndClient,
  448.                                        szString,
  449.                                        0,           /* negative ACK */
  450.                                        0,
  451.                                        "",
  452.                                        strlen ("") + 1);
  453.  
  454.                 WinDdePostMsg (hwndClient, hwnd, WM_DDE_ACK, pddes, TRUE) ;
  455.  
  456.                 }
  457.  
  458.             break ;
  459.  
  460.         case WM_DDE_ADVISE:
  461.         case WM_DDE_UNADVISE:
  462.         case WM_DDE_POKE:
  463.  
  464.         case WM_DDE_LAST:
  465.             DisplayDdeMsgType (hwnd, msg) ;
  466.             break ;
  467.  
  468.         case WM_COMMAND:
  469.             switch (COMMANDMSG(&msg)->cmd)
  470.                 {
  471.                 case IDM_QUIET:
  472.                     if (!fQuiet)
  473.                         {
  474.                         WinSendMsg(WinWindowFromID( hwndFrame, FID_MENU),
  475.                                    MM_SETITEMATTR,
  476.                                    MPFROM2SHORT((USHORT) IDM_QUIET, (BOOL) TRUE),
  477.                                    MPFROM2SHORT((USHORT) MIA_CHECKED, (USHORT) MIA_CHECKED));
  478.                         fQuiet=TRUE;
  479.                         }
  480.                     else
  481.                         {
  482.                         WinSendMsg(WinWindowFromID( hwndFrame, FID_MENU),
  483.                                    MM_SETITEMATTR,
  484.                                    MPFROM2SHORT((USHORT) IDM_QUIET, (BOOL) TRUE),
  485.                                    MPFROM2SHORT((USHORT) MIA_CHECKED, (USHORT) 0));
  486.                         fQuiet=FALSE;
  487.                         }
  488.                     break;
  489.  
  490.                 case IDM_EXCEL:
  491.                     {
  492.                     TID tidThread;
  493.  
  494.                     DosCreateThread(SpawnExcel, &tidThread, &ThreadStack[4095]);
  495.                     }
  496.                     break;
  497.  
  498.                 case IDM_CREATE:
  499.                     strcpy (szString1,"App Name?") ;
  500.                     if (!WinDlgBox (HWND_DESKTOP, hwnd, GetValueDlgProc,
  501.                                (HMODULE) 0, DID_GETVALUE, (PVOID) szString1))
  502.                          return(0);
  503.  
  504.                     strcpy (szString2,"Topic Name?") ;
  505.                     if (!WinDlgBox (HWND_DESKTOP, hwnd, GetValueDlgProc,
  506.                                (HMODULE) 0, DID_GETVALUE, (PVOID) szString2))
  507.                          return(0);
  508.  
  509.  
  510.                     WinDdeInitiate (hwnd, szString1, szString2) ;
  511.                     return 0 ;
  512.  
  513.                 case IDM_RUN:
  514.                     strcpy (szData,"Execute String?") ;
  515.                     if (!WinDlgBox (HWND_DESKTOP, hwnd, GetValueDlgProc,
  516.                                (HMODULE) 0, DID_GETVALUE, (PVOID) szData))
  517.                          return(0);
  518.  
  519.                     pddes = MakeDDESegment (hwndServer, 0L, 0,
  520.                                             DDEFMT_TEXT, szData, strlen (szData) + 1) ;
  521.                     WinDdePostMsg (hwndServer, hwnd, WM_DDE_EXECUTE, pddes, TRUE) ;
  522.                     return 0 ;
  523.  
  524.                 case IDM_NUMBER:
  525.                     strcpy (szString,"Data Location?") ;
  526.                     WinDlgBox (HWND_DESKTOP, hwnd, GetValueDlgProc,
  527.                                0, DID_GETVALUE, (PVOID) szString) ;
  528.                     pddes = MakeDDESegment (hwndServer,
  529.                                             szString,
  530.                                              0,  DDEFMT_TEXT, szString, strlen (szString) + 1) ;
  531.                     WinDdePostMsg (hwndServer, hwnd, WM_DDE_REQUEST, pddes, TRUE) ;
  532.                     return 0 ;
  533.  
  534.                 case IDM_REPLY:
  535.                 case IDM_COMPOSE:
  536.                     strcpy (szString,"Data Location?") ;
  537.                     WinDlgBox (HWND_DESKTOP, hwnd, GetValueDlgProc,
  538.                               (HMODULE) 0, DID_GETVALUE, (PVOID) szString) ;
  539.  
  540.                     strcpy (szData,"Data?") ;
  541.                     WinDlgBox (HWND_DESKTOP, hwnd, GetValueDlgProc,
  542.                               (HMODULE) 0, DID_GETVALUE, (PVOID) szData) ;
  543.  
  544.                     pddes = MakeDDESegment (hwndServer,
  545.                                             szString,
  546.                                             0,  DDEFMT_TEXT,
  547.                                             szData, strlen (szData)+1);
  548.  
  549.                     WinDdePostMsg (hwndServer, hwnd, WM_DDE_POKE, pddes, TRUE) ;
  550.                     return 0 ;
  551.  
  552.                 case IDM_ENDSERVER:
  553.                     if (hwndServer)
  554.                     {
  555.                        pddes = MakeDDESegment (hwndServer,
  556.                                                0L,
  557.                                                0, 0, NULL, 0) ;
  558.                        WinDdePostMsg (hwndServer, hwnd, WM_DDE_TERMINATE, 0L, TRUE) ;
  559.                        hwndServer = (HWND) 0;
  560.                        WinInvalidateRect (hwnd, 0L, 0L) ;
  561.                     }
  562.                     break ;
  563.  
  564.                 case IDM_ENDCLIENT:
  565.                     if (hwndClient)
  566.                     {
  567.                       pddes = MakeDDESegment (hwndClient,
  568.                                               0L,
  569.                                               0, 0, NULL, 0) ;
  570.                       WinDdePostMsg (hwndClient, hwnd, WM_DDE_TERMINATE, 0L, TRUE) ;
  571.                       hwndClient = 0L ;
  572.                       WinInvalidateRect (hwnd, NULL, 0) ;
  573.                     }
  574.                     return 0 ;
  575.  
  576.  
  577.                 case IDM_AUTHOR:
  578.                     return 0 ;
  579.  
  580.                 case IDM_PARENT:
  581.                     return 0 ;
  582.  
  583.                 case IDM_CHILDREN:
  584.                     return 0 ;
  585.  
  586.                 case IDM_DATE:
  587.                     return 0 ;
  588.                 }
  589.             break ;
  590.  
  591.         case WM_CREATE:
  592.              strcpy (szString, "Hello") ;
  593.              hwndServer = 0L ;
  594.              hwndClient = 0L ;
  595.              return 0 ;
  596.  
  597.         case WM_PAINT:
  598.              hps = WinBeginPaint (hwnd, 0L, 0L) ;
  599.              WinQueryWindowRect (hwnd, &rcl) ;
  600.              sprintf(szString,"Server Window Handle: %u",hwndServer) ;
  601.              WinDrawText (hps, -1, (PSZ) szString, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
  602.                           DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
  603.              sprintf(szString,"Client Window Handle: %u",hwndClient) ;
  604.              WinDrawText (hps, -1, szString, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
  605.              DT_CENTER  | DT_BOTTOM) ;
  606.              WinEndPaint (hps) ;
  607.              return 0 ;
  608.  
  609.         case WM_DESTROY:
  610.              return 0 ;
  611.         }
  612.     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  613.     }
  614.  
  615. void DisplaywStatus (HWND hwnd, USHORT fsStatus)
  616.      {
  617.      static CHAR szString [80] ;
  618.  
  619.      switch (fsStatus)
  620.      {
  621.  
  622.      case DDE_FACK:
  623.           strcpy (szString, "DDE_FACK") ;
  624.           break ;
  625.  
  626.  
  627.      case DDE_FACKREQ:
  628.           strcpy (szString, "DDE_FACKREQ") ;
  629.           break ;
  630.  
  631.      case DDE_FBUSY:
  632.           strcpy (szString, "DDE_FBUSY") ;
  633.           break ;
  634.  
  635.      case DDE_FNODATA:
  636.           strcpy (szString, "DDE_FNODATA") ;
  637.           break ;
  638.  
  639.      case DDE_FRESPONSE:
  640.           strcpy (szString, "DDE_FRESPONSE") ;
  641.           break ;
  642.  
  643.      case DDE_NOTPROCESSED:
  644.           strcpy (szString, "DDE_NOTPROCESSED") ;
  645.           break ;
  646.  
  647.      case DDE_FRESERVED:
  648.           strcpy (szString, "DDE_FRESERVED") ;
  649.           break ;
  650.  
  651.      case DDE_FAPPSTATUS:
  652.           strcpy (szString, "DDE_FAPPSTATUS") ;
  653.           break ;
  654.  
  655.      default:
  656.           strcpy (szString, "DDE_UNKNOWN") ;
  657.           break ;
  658.  
  659.      }
  660.  
  661.          if (!fQuiet)
  662.             {
  663.             WinMessageBox(HWND_DESKTOP,
  664.                        hwnd,
  665.                        szString,
  666.                        "fsStatus",
  667.                        0,
  668.                        MB_OK);
  669.             }
  670.      }
  671.  
  672. void DisplayDdeMsgType (HWND hwnd, USHORT msg)
  673.      {
  674.      static CHAR szString [80] ;
  675.  
  676.      switch (msg)
  677.       {
  678.       case WM_DDE_INITIATEACK:
  679.            strcpy (szString, "WM_DDE_INITIATEACK") ;
  680.            break ;
  681.  
  682.       case WM_DDE_TERMINATE:
  683.            strcpy (szString, "WM_DDE_TERMINATE") ;
  684.            break ;
  685.  
  686.       case WM_DDE_ACK:
  687.            strcpy (szString, "WM_DDE_ACK") ;
  688.            break ;
  689.  
  690.       case WM_DDE_DATA:
  691.            strcpy (szString, "WM_DDE_DATA") ;
  692.            break ;
  693.  
  694.       case WM_DDE_INITIATE:
  695.            strcpy (szString, "WM_DDE_INITIATE") ;
  696.            break ;
  697.  
  698.       case WM_DDE_REQUEST:
  699.            strcpy (szString, "WM_DDE_REQUEST") ;
  700.            break ;
  701.  
  702.       case WM_DDE_ADVISE:
  703.            strcpy (szString, "WM_DDE_ADVISE") ;
  704.            break ;
  705.  
  706.       case WM_DDE_UNADVISE:
  707.            strcpy (szString, "WM_DDE_UNADVISE") ;
  708.            break ;
  709.  
  710.       case WM_DDE_POKE:
  711.            strcpy (szString, "WM_DDE_POKE") ;
  712.            break ;
  713.  
  714.       case WM_DDE_EXECUTE:
  715.            strcpy (szString, "WM_DDE_EXECUTE") ;
  716.            break ;
  717.  
  718.       case WM_DDE_LAST:
  719.            strcpy (szString, "WM_DDE_LAST") ;
  720.            break ;
  721.  
  722.       default:
  723.            strcpy (szString, "WM_DDE_UNKNOWN") ;
  724.            break ;
  725.       }
  726.  
  727.          if (!fQuiet)
  728.             {
  729.             WinMessageBox(HWND_DESKTOP,
  730.                          hwnd,
  731.                          szString,
  732.                          "Message Received",
  733.                          0,
  734.                          MB_OK);
  735.             }
  736.     }
  737.  
  738. void DisplayusFormat (HWND hwnd, USHORT usFormat)
  739.      {
  740.      static CHAR szString [80] ;
  741.  
  742.      switch (usFormat)
  743.         {
  744.         case DDEFMT_TEXT:
  745.             strcpy (szString, "DDEFMT_TEXT") ;
  746.             break;
  747.  
  748.         default:
  749.             strcpy (szString, "DDEFMT_UNKNOWN") ;
  750.             break;
  751.  
  752.         }
  753.  
  754.         if (!fQuiet)
  755.             {
  756.             WinMessageBox(HWND_DESKTOP,
  757.                           hwnd,
  758.                           szString,
  759.                           "DDE FORMAT",
  760.                           0,
  761.                           MB_OK);
  762.             }
  763.      }
  764.  
  765. BOOL DisplayabData (HWND hwnd, PDDESTRUCT pddes)
  766.      {
  767.      PSZ pszString ;
  768.  
  769.      pszString = (PSZ) ( (LONG) pddes + pddes->offabData) ;
  770.      if (!fQuiet)
  771.         {
  772.         WinMessageBox(HWND_DESKTOP,
  773.                      hwnd,
  774.                      pszString,
  775.                      "DDE DATA",
  776.                      0,
  777.                      MB_OK);
  778.         }
  779.      return TRUE ;
  780.  
  781.      }
  782.