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

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  MODULE      : dialog.c                                                 *
  4.  *                                                                         *
  5.  *  PURPOSE     : Contains all dialog procedures and related functions.    *
  6.  *                                                                         *
  7.  ***************************************************************************/
  8. #include "ddemlcl.h"
  9. #include "infoctrl.h"
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include "huge.h"
  14.  
  15. #define MAX_NAME 100    // max size for edit controls with app/topic/item names.
  16. char szWild[] = "*";    // used to indicate wild names ("" is also cool)
  17. char szT[MAX_NAME];     // temp buf for munging names.
  18.  
  19.  
  20. LONG GetDlgItemLong(HWND hwnd, WORD id, BOOL *pfTranslated, BOOL fSigned);
  21. VOID SetDlgItemLong(HWND hwnd, WORD id, LONG l, BOOL fSigned);
  22.  
  23. /****************************************************************************
  24.  *                                                                          *
  25.  *  FUNCTION   : DoDialog()                                                 *
  26.  *                                                                          *
  27.  *  PURPOSE    : Generic dialog invocation routine.  Handles procInstance   *
  28.  *               stuff, focus management and param passing.                 *
  29.  *  RETURNS    : result of dialog procedure.                                *
  30.  *                                                                          *
  31.  ****************************************************************************/
  32. int FAR DoDialog(
  33. LPCSTR lpTemplateName,
  34. FARPROC lpDlgProc,
  35. DWORD param,
  36. BOOL fRememberFocus)
  37. {
  38.     WORD wRet;
  39.     HWND hwndFocus;
  40.  
  41.     if (fRememberFocus)
  42.         hwndFocus = GetFocus();
  43.     lpDlgProc = MakeProcInstance(lpDlgProc, hInst);
  44.     wRet = DialogBoxParam(hInst, lpTemplateName, hwndFrame, lpDlgProc, param);
  45.     FreeProcInstance(lpDlgProc);
  46.     if (fRememberFocus)
  47.         SetFocus(hwndFocus);
  48.     return wRet;
  49. }
  50.  
  51.  
  52.  
  53. /****************************************************************************
  54.  *                                                                          *
  55.  *  FUNCTION   :                                                            *
  56.  *                                                                          *
  57.  *  PURPOSE    :                                                            *
  58.  *                                                                          *
  59.  *  RETURNS    :                                                            *
  60.  *                                                                          *
  61.  ****************************************************************************/
  62. BOOL FAR PASCAL __export AboutDlgProc ( hwnd, msg, wParam, lParam )
  63. HWND          hwnd;
  64. register WORD msg;
  65. register WORD wParam;
  66. LONG          lParam;
  67. {
  68.     switch (msg){
  69.         case WM_INITDIALOG:
  70.             /* nothing to initialize */
  71.             break;
  72.  
  73.         case WM_COMMAND:
  74.             switch (wParam){
  75.                 case IDOK:
  76.                 case IDCANCEL:
  77.                     EndDialog(hwnd, 0);
  78.                     break;
  79.  
  80.                 default:
  81.                     return FALSE;
  82.             }
  83.             break;
  84.  
  85.         default:
  86.             return(FALSE);
  87.     }
  88.  
  89.     return TRUE;
  90. }
  91.  
  92.  
  93.  
  94.  
  95. /****************************************************************************
  96.  *                                                                          *
  97.  *  FUNCTION   :                                                            *
  98.  *                                                                          *
  99.  *  PURPOSE    :                                                            *
  100.  *                                                                          *
  101.  *  RETURNS    :                                                            *
  102.  *                                                                          *
  103.  ****************************************************************************/
  104. BOOL FAR PASCAL __export ConnectDlgProc(
  105. HWND          hwnd,
  106. register WORD msg,
  107. register WORD wParam,
  108. LONG          lParam)
  109. {
  110.     static BOOL fReconnect;
  111.     char szT[MAX_NAME];
  112.     HSZ hszApp, hszTopic;
  113.     MYCONVINFO *pmci;
  114.     WORD error;
  115.  
  116.     switch (msg){
  117.     case WM_INITDIALOG:
  118.         SendDlgItemMessage(hwnd, IDEF_APPLICATION, EM_LIMITTEXT, MAX_NAME, 0);
  119.         SendDlgItemMessage(hwnd, IDEF_TOPIC, EM_LIMITTEXT, MAX_NAME, 0);
  120.         fReconnect = (BOOL)lParam;
  121.         if (fReconnect) {
  122.             PSTR psz;
  123.  
  124.             pmci = (MYCONVINFO *)GetWindowWord(hwndActive, 0);
  125.             SetWindowText(hwnd, "DDE Reconnect List");
  126.             psz = GetHSZName(pmci->hszApp);
  127.             SetDlgItemText(hwnd, IDEF_APPLICATION, psz);
  128.             MyFree(psz);
  129.             psz = GetHSZName(pmci->hszTopic);
  130.             SetDlgItemText(hwnd, IDEF_TOPIC, psz);
  131.             MyFree(psz);
  132.             ShowWindow(GetDlgItem(hwnd, IDCH_CONNECTLIST), SW_HIDE);
  133.         }
  134.         break;
  135.  
  136.     case WM_COMMAND:
  137.         switch (wParam) {
  138.         case IDOK:
  139.             GetDlgItemText(hwnd, IDEF_APPLICATION, szT, MAX_NAME);
  140.             if (!strcmp(szT, szWild))
  141.                 szT[0] = '\0';
  142.             hszApp = DdeCreateStringHandle(idInst, szT, 0);
  143.  
  144.             GetDlgItemText(hwnd, IDEF_TOPIC, szT, MAX_NAME);
  145.             if (!strcmp(szT, szWild))
  146.                 szT[0] = '\0';
  147.             hszTopic = DdeCreateStringHandle(idInst, szT, 0);
  148.  
  149.             if (fReconnect) {
  150.                 HCONV hConv;
  151.                 CONVINFO ci;
  152.                 WORD cHwnd;
  153.                 HWND *aHwnd, *pHwnd, hwndSave;
  154.  
  155.                 ci.cb = sizeof(CONVINFO);
  156.                 pmci = (MYCONVINFO *)GetWindowWord(hwndActive, 0);
  157.                 hwndSave = hwndActive;
  158.  
  159.                 // count the existing conversations and allocate aHwnd
  160.  
  161.                 cHwnd = 0;
  162.                 hConv = NULL;
  163.                 while (hConv = DdeQueryNextServer((HCONVLIST)pmci->hConv, hConv))
  164.                     cHwnd++;
  165.                 aHwnd = (HWND *)MyAlloc(cHwnd * sizeof(HWND));
  166.  
  167.                 // save all the old conversation windows into aHwnd.
  168.  
  169.                 pHwnd = aHwnd;
  170.                 hConv = NULL;
  171.                 while (hConv = DdeQueryNextServer((HCONVLIST)pmci->hConv, hConv)) {
  172.             DdeQueryConvInfo(hConv, (DWORD)QID_SYNC, &ci);
  173.                     *pHwnd++ = (HWND)ci.hUser;
  174.                 }
  175.  
  176.                 // reconnect
  177.  
  178.                 if (!(hConv = DdeConnectList(idInst, hszApp, hszTopic, pmci->hConv, &CCFilter))) {
  179.                     MPError(hwnd, MB_OK, IDS_DDEMLERR, (LPSTR)Error2String(DdeGetLastError(idInst)));
  180.                     DdeFreeStringHandle(idInst, hszApp);
  181.                     DdeFreeStringHandle(idInst, hszTopic);
  182.                     return 0;
  183.                 }
  184.  
  185.                 // fixup windows corresponding to the new conversations.
  186.  
  187.                 pmci->hConv = hConv;
  188.                 hConv = NULL;
  189.                 while (hConv = DdeQueryNextServer((HCONVLIST)pmci->hConv, hConv)) {
  190.             DdeQueryConvInfo(hConv, (DWORD)QID_SYNC, &ci);
  191.                     // preserve corresponding window by setting its list
  192.                     // entry to 0
  193.                     for (pHwnd = aHwnd; pHwnd < &aHwnd[cHwnd]; pHwnd++) {
  194.                         if (*pHwnd == (HWND)ci.hUser) {
  195.                             *pHwnd = NULL;
  196.                             break;
  197.                         }
  198.                     }
  199.                 }
  200.  
  201.                 // destroy all windows left in the old list
  202.  
  203.                 for (pHwnd = aHwnd; pHwnd < &aHwnd[cHwnd]; pHwnd++)
  204.                     if (*pHwnd)
  205.                         SendMessage(hwndMDIClient, WM_MDIDESTROY, *pHwnd, 0L);
  206.                 MyFree((PSTR)aHwnd);
  207.  
  208.                 // create any new windows needed
  209.  
  210.                 hConv = NULL;
  211.                 while (hConv = DdeQueryNextServer((HCONVLIST)pmci->hConv, hConv)) {
  212.             DdeQueryConvInfo(hConv, (DWORD)QID_SYNC, &ci);
  213.                     if (ci.hUser) {
  214.                         InvalidateRect((HWND)ci.hUser, NULL, TRUE);
  215.                     } else {
  216.                         AddConv(ci.hszSvcPartner, ci.hszTopic, hConv, FALSE);
  217.                     }
  218.                 }
  219.  
  220.                 // make list window update itself
  221.  
  222.                 InvalidateRect(hwndSave, NULL, TRUE);
  223.                 SetFocus(hwndSave);
  224.             } else {
  225.                 if (!CreateConv(hszApp, hszTopic,
  226.                         IsDlgButtonChecked(hwnd, IDCH_CONNECTLIST), &error)) {
  227.                     MPError(hwnd, MB_OK, IDS_DDEMLERR, (LPSTR)Error2String(error));
  228.                     return 0;
  229.                 }
  230.             }
  231.             DdeFreeStringHandle(idInst, hszApp);
  232.             DdeFreeStringHandle(idInst, hszTopic);
  233.             // fall through
  234.         case IDCANCEL:
  235.             EndDialog(hwnd, 0);
  236.             break;
  237.  
  238.         default:
  239.             return(FALSE);
  240.         }
  241.         break;
  242.  
  243.     default:
  244.         return(FALSE);
  245.     }
  246. }
  247.  
  248.  
  249.  
  250.  
  251. /*
  252.  * Fills a XACT structure and calls ProcessTransaction.
  253.  *
  254.  * On initiation lParam == hConv.
  255.  */
  256. /****************************************************************************
  257.  *                                                                          *
  258.  *  FUNCTION   :                                                            *
  259.  *                                                                          *
  260.  *  PURPOSE    :                                                            *
  261.  *                                                                          *
  262.  *  RETURNS    :                                                            *
  263.  *                                                                          *
  264.  ****************************************************************************/
  265. BOOL FAR PASCAL __export TransactDlgProc(
  266. HWND          hwnd,
  267. register WORD msg,
  268. register WORD wParam,
  269. LONG          lParam)
  270. {
  271.     static WORD id2type[] = {
  272.         XTYP_REQUEST,       // IDCH_REQUEST
  273.         XTYP_ADVSTART,      // IDCH_ADVISE
  274.         XTYP_ADVSTOP,       // IDCH_UNADVISE
  275.         XTYP_POKE,          // IDCH_POKE
  276.         XTYP_EXECUTE,       // IDCH_EXECUTE
  277.     };
  278.     static XACT *pxact;     // ONLY ONE AT A TIME!
  279.     int i;
  280.  
  281.     switch (msg){
  282.     case WM_INITDIALOG:
  283.         pxact = (XACT *)MyAlloc(sizeof(XACT));
  284.         pxact->hConv = (HCONV)lParam;
  285.         pxact->fsOptions = DefOptions;
  286.         pxact->ulTimeout = DefTimeout;
  287.  
  288.         // The item index == the index to the format atoms in aFormats[].
  289.         for (i = 0; i < CFORMATS; i++)
  290.             SendDlgItemMessage(hwnd, IDCB_FORMAT, CB_INSERTSTRING, i,
  291.                     (DWORD)(LPSTR)aFormats[i].sz);
  292.         SendDlgItemMessage(hwnd, IDCB_FORMAT, CB_INSERTSTRING, i,
  293.                 (DWORD)(LPSTR)"NULL");
  294.         SendDlgItemMessage(hwnd, IDCB_FORMAT, CB_SETCURSEL, 0, 0);
  295.         CheckRadioButton(hwnd, IDCH_REQUEST, IDCH_EXECUTE, IDCH_REQUEST);
  296.         SendDlgItemMessage(hwnd, IDEF_ITEM, EM_LIMITTEXT, MAX_NAME, 0);
  297.  
  298.         // If there is a top transaction window, use its contents to
  299.         // anticipate what the user will want to do.
  300.  
  301.         if (IsWindow(hwndActive)) {
  302.             HWND hwndXaction;
  303.             XACT *pxact;
  304.             PSTR pszItem;
  305.  
  306.             hwndXaction = GetWindow(hwndActive, GW_CHILD);
  307.             if (IsWindow(hwndXaction)) {
  308.                 pxact = (XACT *)GetWindowWord(hwndXaction, GWW_WUSER);
  309.                 pszItem = GetHSZName(pxact->hszItem);
  310.                 if ((pxact->wType & XTYP_ADVSTART) == XTYP_ADVSTART ||
  311.                         pxact->wType == XTYP_ADVDATA) {
  312.                     CheckRadioButton(hwnd, IDCH_REQUEST, IDCH_EXECUTE, IDCH_UNADVISE);
  313.                 }
  314.                 SetDlgItemText(hwnd, IDEF_ITEM, pszItem);
  315.                 for (i = 0; i < CFORMATS; i++) {
  316.                     if (aFormats[i].atom == pxact->wFmt) {
  317.                         SendDlgItemMessage(hwnd, IDCB_FORMAT, CB_SETCURSEL, i, 0);
  318.                         break;
  319.                     }
  320.                 }
  321.                 MyFree(pszItem);
  322.             }
  323.         }
  324.         break;
  325.  
  326.     case WM_COMMAND:
  327.         switch (wParam) {
  328.         case IDCH_EXECUTE:
  329.             SetDlgItemText(hwnd, IDEF_ITEM, "");
  330.         case IDCH_REQUEST:
  331.         case IDCH_ADVISE:
  332.         case IDCH_UNADVISE:
  333.         case IDCH_POKE:
  334.             EnableWindow(GetDlgItem(hwnd, IDEF_ITEM), wParam != IDCH_EXECUTE);
  335.             EnableWindow(GetDlgItem(hwnd, IDTX_ITEM), wParam != IDCH_EXECUTE);
  336.             break;
  337.  
  338.         case IDOK:
  339.         case IDBN_OPTIONS:
  340.             {
  341.                 int id;
  342.  
  343.                 // set pxact->wType
  344.  
  345.                 for (id = IDCH_REQUEST; id <= IDCH_EXECUTE; id++) {
  346.                     if (IsDlgButtonChecked(hwnd, id)) {
  347.                         pxact->wType = id2type[id - IDCH_REQUEST];
  348.                         break;
  349.                     }
  350.                 }
  351.  
  352.                 if (wParam == IDBN_OPTIONS) {
  353.                     DoDialog(MAKEINTRESOURCE(IDD_ADVISEOPTS),
  354.                             AdvOptsDlgProc, MAKELONG(pxact->fsOptions, pxact),
  355.                             TRUE);
  356.                     return 0;
  357.                 }
  358.  
  359.                 id = (int)SendDlgItemMessage(hwnd, IDCB_FORMAT, CB_GETCURSEL, 0, 0);
  360.                 if (id == LB_ERR) {
  361.                     return 0;
  362.                 }
  363.                 if (id == CFORMATS)
  364.                     pxact->wFmt = 0;
  365.                 else
  366.                     pxact->wFmt = aFormats[id].atom;
  367.  
  368.                 if (pxact->wType == XTYP_ADVSTART) {
  369.                     if (pxact->fsOptions & XOPT_NODATA)
  370.                         pxact->wType |= XTYPF_NODATA;
  371.                     if (pxact->fsOptions & XOPT_ACKREQ)
  372.                         pxact->wType |= XTYPF_ACKREQ;
  373.                 }
  374.  
  375.                 GetDlgItemText(hwnd, IDEF_ITEM, szT, MAX_NAME);
  376.                 pxact->hszItem = DdeCreateStringHandle(idInst, szT, NULL);
  377.  
  378.                 pxact->hDdeData = 0;
  379.                 /*
  380.                  * If this transaction needs data, invoke data input dialog.
  381.                  */
  382.                 if (pxact->wType == XTYP_POKE || pxact->wType == XTYP_EXECUTE) {
  383.                     if (!DoDialog(MAKEINTRESOURCE(IDD_TEXTENTRY),
  384.                             TextEntryDlgProc, (DWORD)(LPSTR)pxact,
  385.                             TRUE))
  386.                         return 0;
  387.                 }
  388.  
  389.                 // now start the transaction
  390.  
  391.                 ProcessTransaction(pxact);
  392.                 MyFree((PSTR)pxact);
  393.             }
  394.             EndDialog(hwnd, 1);
  395.             break;
  396.  
  397.         case IDCANCEL:
  398.             MyFree((PSTR)pxact);
  399.             EndDialog(hwnd, 0);
  400.             break;
  401.  
  402.         default:
  403.             return(FALSE);
  404.         }
  405.         break;
  406.  
  407.     case WM_DESTROY:
  408.         break;
  409.  
  410.     default:
  411.         return(FALSE);
  412.     }
  413.     return 0;
  414. }
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422. /****************************************************************************
  423.  *                                                                          *
  424.  *  FUNCTION   : AdvOptsDlgProc                                             *
  425.  *                                                                          *
  426.  *  RETURNS    :                                                            *
  427.  *                                                                          *
  428.  ****************************************************************************/
  429. BOOL FAR PASCAL __export AdvOptsDlgProc(
  430. HWND          hwnd,
  431. register WORD msg,
  432. register WORD wParam,
  433. LONG          lParam)
  434. {
  435.     static struct {
  436.         WORD id;
  437.         WORD opt;
  438.     } id2Opt[] = {
  439.         {   IDCH_NODATA        ,   XOPT_NODATA             }   ,
  440.         {   IDCH_ACKREQ        ,   XOPT_ACKREQ             }   ,
  441.         {   IDCH_DISABLEFIRST  ,   XOPT_DISABLEFIRST       }   ,
  442.         {   IDCH_ABANDON       ,   XOPT_ABANDONAFTERSTART  }   ,
  443.         {   IDCH_BLOCKRESULT   ,   XOPT_BLOCKRESULT        }   ,
  444.         {   IDCH_ASYNC         ,   XOPT_ASYNC              }   ,
  445.     };
  446. #define CCHBOX  6
  447.     int i;
  448.     static XACT *pxact; // only one instance at a time!!
  449.  
  450.     switch (msg){
  451.     case WM_INITDIALOG:
  452.         pxact = (XACT *)HIWORD(lParam);
  453.  
  454.         for (i = 0; i < CCHBOX; i++) {
  455.             CheckDlgButton(hwnd, id2Opt[i].id, pxact->fsOptions & id2Opt[i].opt);
  456.         }
  457.         SetDlgItemLong(hwnd, IDEF_TIMEOUT, pxact->ulTimeout, FALSE);
  458.         if (pxact->wType != XTYP_ADVSTART) {
  459.             EnableWindow(GetDlgItem(hwnd, IDCH_NODATA), FALSE);
  460.             EnableWindow(GetDlgItem(hwnd, IDCH_ACKREQ), FALSE);
  461.         }
  462.         SendMessage(hwnd, WM_COMMAND, IDCH_ASYNC, 0);   // enable async checkboxes
  463.         break;
  464.  
  465.     case WM_COMMAND:
  466.         switch (wParam) {
  467.         case IDCH_ASYNC:
  468.             {
  469.                 BOOL fEnable;
  470.  
  471.                 fEnable = IsDlgButtonChecked(hwnd, IDCH_ASYNC);
  472.                 EnableWindow(GetDlgItem(hwnd, IDCH_DISABLEFIRST), fEnable);
  473.                 EnableWindow(GetDlgItem(hwnd, IDCH_ABANDON), fEnable);
  474.                 EnableWindow(GetDlgItem(hwnd, IDCH_BLOCKRESULT), fEnable);
  475.                 EnableWindow(GetDlgItem(hwnd, IDEF_TIMEOUT), !fEnable);
  476.             }
  477.             break;
  478.  
  479.         case IDOK:
  480.             pxact->fsOptions = 0;
  481.             for (i = 0; i < CCHBOX; i++) {
  482.                 if (IsDlgButtonChecked(hwnd, id2Opt[i].id))
  483.                     pxact->fsOptions |= id2Opt[i].opt;
  484.             }
  485.             if (!(pxact->fsOptions & XOPT_ASYNC))
  486.                 pxact->ulTimeout = (DWORD)GetDlgItemLong(hwnd, IDEF_TIMEOUT,
  487.                     &i, FALSE);
  488.             // fall through
  489.         case IDCANCEL:
  490.             EndDialog(hwnd, GetWindowWord(hwnd, 0));
  491.             break;
  492.         }
  493.         break;
  494.  
  495.     default:
  496.         return(FALSE);
  497.     }
  498.     return 0;
  499. #undef CCHBOX
  500. }
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507. /****************************************************************************
  508.  *                                                                          *
  509.  *  FUNCTION   : TextEntryDlgProc                                           *
  510.  *                                                                          *
  511.  *  PURPOSE    : Allows user to enter text data which is to be sent to a    *
  512.  *               server.  The user can opt to have a huge text piece of     *
  513.  *               data created automaticlly.                                 *
  514.  *               It uses the XACT structure for passing info in and out.    *
  515.  *               Must have wFmt and hszItem set on entry.                   *
  516.  *               Sets hDDEData on return if TRUE was returned.              *
  517.  *                                                                          *
  518.  *  RETURNS    : TRUE on success, FALSE on failure or cancel                *
  519.  *                                                                          *
  520.  ****************************************************************************/
  521. BOOL FAR PASCAL __export TextEntryDlgProc(
  522. HWND          hwnd,
  523. register WORD msg,
  524. register WORD wParam,
  525. LONG          lParam)
  526. {
  527.     static XACT FAR *pxact;
  528.     DWORD cb;
  529.     LONG length;
  530.     LPBYTE pData;
  531.     BOOL fOwned;
  532.     int id, i;
  533.  
  534.     switch (msg){
  535.     case WM_INITDIALOG:
  536.         pxact = (XACT FAR *)lParam;
  537.         fOwned = FALSE;
  538.         for (i = 0; i < (int)cOwned; i++) {
  539.             if (aOwned[i].wFmt == pxact->wFmt &&
  540.                     aOwned[i].hszItem == pxact->hszItem) {
  541.                 fOwned = TRUE;
  542.                 break;
  543.             }
  544.         }
  545.         EnableWindow(GetDlgItem(hwnd, IDBN_USEOWNED), fOwned);
  546.         CheckDlgButton(hwnd, IDCH_MAKEOWNED, 0);
  547.         EnableWindow(GetDlgItem(hwnd, IDCH_MAKEOWNED), cOwned < MAX_OWNED);
  548.         break;
  549.  
  550.     case WM_COMMAND:
  551.         switch (wParam) {
  552.         case IDOK:
  553.         case IDBN_GENHUGE:
  554.             fOwned = IsDlgButtonChecked(hwnd, IDCH_MAKEOWNED);
  555.             cb = SendDlgItemMessage(hwnd, IDEF_DATA, WM_GETTEXTLENGTH, 0, 0) + 1;
  556.             pxact->hDdeData = DdeCreateDataHandle(idInst, NULL, 0, cb, pxact->hszItem,
  557.                     pxact->wFmt, fOwned ? HDATA_APPOWNED : 0);
  558.             //
  559.             // Note that at this time we have not yet given the data handle
  560.             // to DDEML for transmission to any application, therefore, we
  561.             // are at liberty to write to it using DdeAccessData() or any
  562.             // other DDEML api.  It is only data handles received from DDEML
  563.             // or given to DDEML for transmission that are readonly.
  564.             //
  565.             pData = DdeAccessData(pxact->hDdeData, NULL);
  566.             GetDlgItemText(hwnd, IDEF_DATA, pData, (WORD)cb);
  567.             DdeUnaccessData(pxact->hDdeData);
  568.             if (wParam == IDBN_GENHUGE) {
  569.                 char szT[40];
  570.  
  571.                 /*
  572.                  * we assume in this case that the text entered is the decimal
  573.                  * value of the size of the huge object desired.  We parse
  574.                  * this string and create a randomly generated huge block
  575.                  * of text data and place it into pxact->hDdeData.
  576.                  */
  577.                 _fmemcpy(szT, pData, min((WORD)cb, 40));
  578.                 szT[39] = '\0';
  579.                 if (sscanf(szT, "%ld", &length) == 1) {
  580.                     DdeFreeDataHandle(pxact->hDdeData);
  581.                     pxact->hDdeData = CreateHugeDataHandle(length, 4325,
  582.                             345, 5, pxact->hszItem, pxact->wFmt,
  583.                             fOwned ? HDATA_APPOWNED : 0);
  584.                 } else {
  585.                     /*
  586.                      * The string cannot be parsed.  Inform the user of
  587.                      * what is expected.
  588.                      */
  589.                     MPError(hwnd, MB_OK, IDS_BADLENGTH);
  590.                     return 0;
  591.                 }
  592.             }
  593.             if (fOwned) {
  594.                 aOwned[cOwned].hData = pxact->hDdeData;
  595.                 aOwned[cOwned].hszItem = pxact->hszItem;
  596.                 aOwned[cOwned].wFmt = pxact->wFmt;
  597.                 cOwned++;
  598.             }
  599.             EndDialog(hwnd, TRUE);
  600.             break;
  601.  
  602.         case IDBN_USEOWNED:
  603.             /*
  604.              * the user has chosen to use an existing owned data for sending
  605.              * to the server.
  606.              */
  607.             id = DoDialog(MAKEINTRESOURCE(IDD_HDATAVIEW), ViewHandleDlgProc,
  608.                     (DWORD)pxact, TRUE);
  609.  
  610.             switch (id) {
  611.             case IDCANCEL:
  612.                 return(0);
  613.  
  614.             case IDOK:
  615.                 EndDialog(hwnd, TRUE);
  616.  
  617.             case IDBN_VIEW:
  618.                 pData = DdeAccessData(pxact->hDdeData, NULL);
  619.                 SetDlgItemText(hwnd, IDEF_DATA, pData);
  620.                 DdeUnaccessData(pxact->hDdeData);
  621.                 break;
  622.             }
  623.             break;
  624.  
  625.         case IDCANCEL:
  626.             EndDialog(hwnd, FALSE);
  627.             break;
  628.         }
  629.         break;
  630.  
  631.     default:
  632.         return(FALSE);
  633.     }
  634. }
  635.  
  636.  
  637.  
  638. BOOL FAR PASCAL __export ViewHandleDlgProc(
  639. HWND          hwnd,
  640. register WORD msg,
  641. register WORD wParam,
  642. LONG          lParam)
  643. {
  644.     static XACT FAR *pxact;
  645.     int i, itm;
  646.  
  647.     switch (msg){
  648.     case WM_INITDIALOG:
  649.         pxact = (XACT FAR *)lParam;
  650.         // load listbox with handles that fit pxact constraints
  651.  
  652.         for (i = 0; i < (int)cOwned; i++) {
  653.             if (aOwned[i].hszItem == pxact->hszItem &&
  654.                     aOwned[i].wFmt == pxact->wFmt) {
  655.                 wsprintf(szT, "[%d] %lx : length=%ld", i, aOwned[i].hData,
  656.                         DdeGetData(aOwned[i].hData, NULL, 0, 0));
  657.                 SendDlgItemMessage(hwnd, IDLB_HANDLES, LB_ADDSTRING, 0, (LONG)(LPSTR)szT);
  658.             }
  659.         }
  660.         SendDlgItemMessage(hwnd, IDLB_HANDLES, LB_SETCURSEL, 0, 0);
  661.         break;
  662.  
  663.     case WM_COMMAND:
  664.         switch (wParam) {
  665.         case IDOK:          // use selectted handle
  666.         case IDBN_DELETE:   // delete selected handle
  667.         case IDBN_VIEW:     // view selected handle
  668.             itm = (int)SendDlgItemMessage(hwnd, IDLB_HANDLES, LB_GETCURSEL, 0, 0);
  669.             if (itm != LB_ERR) {
  670.                 SendDlgItemMessage(hwnd, IDLB_HANDLES, LB_GETTEXT, itm, (LONG)(LPSTR)szT);
  671.                 sscanf(szT, "[%d]", &i);
  672.                 pxact->hDdeData = aOwned[i].hData;
  673.                 switch (wParam) {
  674.                 case IDOK:          // use selectted handle
  675.                     EndDialog(hwnd, wParam);
  676.                     break;
  677.  
  678.                 case IDBN_DELETE:   // delete selected handle
  679.                     DdeFreeDataHandle(aOwned[i].hData);
  680.                     aOwned[i] = aOwned[--cOwned];
  681.                     SendDlgItemMessage(hwnd, IDLB_HANDLES, LB_DELETESTRING, itm, 0);
  682.                     if (SendDlgItemMessage(hwnd, IDLB_HANDLES, LB_GETCOUNT, 0, 0) == 0)
  683.                         EndDialog(hwnd, IDCANCEL);
  684.                     break;
  685.  
  686.                 case IDBN_VIEW:     // view selected handle
  687.                     EndDialog(hwnd, wParam);
  688.                 }
  689.             }
  690.             break;
  691.  
  692.         case IDCANCEL:
  693.             EndDialog(hwnd, FALSE);
  694.             break;
  695.         }
  696.         break;
  697.  
  698.     default:
  699.         return(FALSE);
  700.     }
  701. }
  702.  
  703.  
  704.  
  705. BOOL FAR PASCAL __export DelayDlgProc(
  706. HWND          hwnd,
  707. register WORD msg,
  708. register WORD wParam,
  709. LONG          lParam)
  710. {
  711.     switch (msg){
  712.     case WM_INITDIALOG:
  713.         SetWindowText(hwnd, "Advise data response time");
  714.         SetDlgItemInt(hwnd, IDEF_VALUE, wDelay, FALSE);
  715.         SetDlgItemText(hwnd, IDTX_VALUE, "Delay in milliseconds:");
  716.         break;
  717.  
  718.     case WM_COMMAND:
  719.         switch (wParam) {
  720.         case IDOK:
  721.             wDelay = (WORD)GetDlgItemInt(hwnd, IDEF_VALUE, NULL, FALSE);
  722.         case IDCANCEL:
  723.             EndDialog(hwnd, 0);
  724.             break;
  725.  
  726.         default:
  727.             return(FALSE);
  728.         }
  729.         break;
  730.  
  731.     default:
  732.         return(FALSE);
  733.     }
  734. }
  735.  
  736.  
  737.  
  738.  
  739.  
  740. /****************************************************************************
  741.  *                                                                          *
  742.  *  FUNCTION   : TimeoutDlgProc()                                           *
  743.  *                                                                          *
  744.  *  PURPOSE    : Allows user to alter the synchronous timeout value.        *
  745.  *                                                                          *
  746.  *  RETURNS    : TRUE on success, FALSE on cancel or failure.               *
  747.  *                                                                          *
  748.  ****************************************************************************/
  749. BOOL FAR PASCAL __export TimeoutDlgProc(
  750. HWND          hwnd,
  751. register WORD msg,
  752. register WORD wParam,
  753. LONG          lParam)
  754. {
  755.     switch (msg){
  756.     case WM_INITDIALOG:
  757.         SetWindowText(hwnd, "Synchronous transaction timeout");
  758.         SetDlgItemLong(hwnd, IDEF_VALUE, DefTimeout, FALSE);
  759.         SetDlgItemText(hwnd, IDTX_VALUE, "Timeout in milliseconds:");
  760.         break;
  761.  
  762.     case WM_COMMAND:
  763.         switch (wParam) {
  764.         case IDOK:
  765.             DefTimeout = GetDlgItemLong(hwnd, IDEF_VALUE, NULL, FALSE);
  766.         case IDCANCEL:
  767.             EndDialog(hwnd, 0);
  768.             break;
  769.  
  770.         default:
  771.             return(FALSE);
  772.         }
  773.         break;
  774.  
  775.     default:
  776.         return(FALSE);
  777.     }
  778. }
  779.  
  780.  
  781.  
  782.  
  783. BOOL FAR PASCAL __export ContextDlgProc(
  784. HWND          hwnd,
  785. register WORD msg,
  786. register WORD wParam,
  787. LONG          lParam)
  788. {
  789.     BOOL fSuccess;
  790.  
  791.     switch (msg){
  792.     case WM_INITDIALOG:
  793.         SetDlgItemInt(hwnd, IDEF_FLAGS, CCFilter.wFlags, FALSE);
  794.         SetDlgItemInt(hwnd, IDEF_COUNTRY, CCFilter.wCountryID, FALSE);
  795.         SetDlgItemInt(hwnd, IDEF_CODEPAGE, CCFilter.iCodePage, TRUE);
  796.         SetDlgItemLong(hwnd, IDEF_LANG, CCFilter.dwLangID, FALSE);
  797.         SetDlgItemLong(hwnd, IDEF_SECURITY, CCFilter.dwSecurity, FALSE);
  798.         return(1);
  799.         break;
  800.  
  801.     case WM_COMMAND:
  802.         switch (wParam) {
  803.         case IDOK:
  804.             CCFilter.wFlags = GetDlgItemInt(hwnd, IDEF_FLAGS, &fSuccess, FALSE);
  805.             if (!fSuccess) return(0);
  806.             CCFilter.wCountryID = GetDlgItemInt(hwnd, IDEF_COUNTRY, &fSuccess, FALSE);
  807.             if (!fSuccess) return(0);
  808.             CCFilter.iCodePage = GetDlgItemInt(hwnd, IDEF_CODEPAGE, &fSuccess, TRUE);
  809.             if (!fSuccess) return(0);
  810.             LOWORD(CCFilter.dwLangID) = GetDlgItemInt(hwnd, IDEF_LANG, &fSuccess, FALSE);
  811.             if (!fSuccess) return(0);
  812.             LOWORD(CCFilter.dwSecurity) = GetDlgItemInt(hwnd, IDEF_SECURITY, &fSuccess, FALSE);
  813.             if (!fSuccess) return(0);
  814.             // fall through
  815.         case IDCANCEL:
  816.             EndDialog(hwnd, 0);
  817.             break;
  818.  
  819.         default:
  820.             return(FALSE);
  821.         }
  822.         break;
  823.     }
  824.     return(FALSE);
  825. }
  826.  
  827.  
  828. void Delay(
  829. DWORD delay)
  830. {
  831.     MSG msg;
  832.  
  833.     delay = GetCurrentTime() + delay;
  834.     while (GetCurrentTime() < delay) {
  835.         if (PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE)) {
  836.             TranslateMessage(&msg);
  837.             DispatchMessage(&msg);
  838.         }
  839.     }
  840. }
  841.  
  842.  
  843. LONG GetDlgItemLong(
  844. HWND hwnd,
  845. WORD id,
  846. BOOL *pfTranslated,
  847. BOOL fSigned)
  848. {
  849.     char szT[20];
  850.  
  851.     if (!GetDlgItemText(hwnd, id, szT, 20)) {
  852.         if (pfTranslated != NULL) {
  853.             *pfTranslated = FALSE;
  854.         }
  855.         return(0L);
  856.     }
  857.     if (pfTranslated != NULL) {
  858.         *pfTranslated = TRUE;
  859.     }
  860.     return(atol(szT));
  861. }
  862.  
  863.  
  864. VOID SetDlgItemLong(
  865. HWND hwnd,
  866. WORD id,
  867. LONG l,
  868. BOOL fSigned)
  869. {
  870.     char szT[20];
  871.  
  872.     ltoa(l, szT, 10);
  873.     SetDlgItemText(hwnd, id, szT);
  874. }
  875.