home *** CD-ROM | disk | FTP | other *** search
/ Mega Movie Guide 3.5 / MEGA_MOVIE_.iso / _assist / ddetest.c < prev    next >
C/C++ Source or Header  |  1996-05-08  |  22KB  |  667 lines

  1. // DDETEST.C
  2. //
  3. // Written by Albert J. Lee     alee@spyglass.com
  4. //
  5. // (C) Copyright Spyglass Inc., 1995.  All rights reserved.
  6. //
  7. // You have a royalty-free right to use, modify, reproduce and
  8. // distribute the files used to build DDETEST.EXE in
  9. // any way you find useful, provided that you agree that
  10. // Spyglass has no warranty obligations or liability.  The source
  11. // code is provided "as is".  Your use of the source code indicates
  12. // your acceptance of these terms.
  13.  
  14. #include <windows.h>
  15. #include <ddeml.h>
  16. #include <stdio.h>
  17. #include <malloc.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "ddetest.h"
  21.  
  22. #ifdef _WIN32
  23.     #undef _export
  24.     #define _export
  25. #endif
  26.  
  27. static HANDLE ghInst;
  28. static HWND hwndDialog;
  29. static HWND hModeless;
  30. static DWORD dwInst = 0;
  31. static HCONV hConv = (HCONV) NULL;
  32. static LONG lProc;
  33. static HSZ hszService;
  34. static HSZ hszMosaicService;
  35. static char *pTopic;
  36. static char *pCommand;
  37.  
  38. static FARPROC lpfnMLEProc;
  39. static FARPROC lpfnResponseProc;
  40. //static FARPROC lpfnDDEProc;
  41. static PFNCALLBACK lpfnDDEProc;
  42. static FARPROC lpfnRegisterProc;
  43. static char szService[256];
  44. static HSZPAIR ahszp[CTOPICS + 1];
  45. static char pDataBuffer[256];
  46.  
  47.  
  48. LRESULT CALLBACK _export WndProc(HWND, UINT, UINT, LONG);
  49. LRESULT CALLBACK _export MLEProc(HWND hwnd, UINT message, UINT wParam, LONG lParam);
  50. BOOL CALLBACK _export ResponseProc(HWND hwnd, UINT message, UINT wParam, LONG lParam);
  51. BOOL CALLBACK _export RegisterProc(HWND hwnd, UINT message, UINT wParam, LONG lParam);
  52.  
  53. HDDEDATA CALLBACK _export DdeCallBack(uType, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2)
  54. UINT uType; /* transaction type */
  55. UINT uFmt;  /* clipboard data format    */
  56. HCONV hconv;    /* handle of the conversation   */
  57. HSZ hsz1;   /* handle of a string   */
  58. HSZ hsz2;   /* handle of a string   */
  59. HDDEDATA hdata; /* handle of a global memory object */
  60. DWORD dwData1;  /* transaction-specific data    */
  61. DWORD dwData2;  /* transaction-specific data    */
  62. {
  63.     DWORD length;
  64.     char *pBuffer;
  65.     long bExiting;
  66.     char szTemp[1000];
  67.     long i;
  68.     HDDEDATA  hReturn;
  69.     long lReturn;
  70.  
  71.     DdeQueryString(dwInst, hsz1, szTemp, sizeof(szTemp), CP_WINANSI);
  72.  
  73.     switch(uType)
  74.     {
  75.         case XTYP_REQUEST:
  76.             if( ! _strnicmp( szTemp, "DIALER_", 7 )  )
  77.             {
  78.                 long lDoesNotMatter = 1;
  79.                 SendMessage(GetDlgItem(hwndDialog, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) (char *) szTemp);
  80.                 ShowWindow(GetDlgItem(hwndDialog, IDC_PROGRESSVALUE), SW_HIDE);
  81.                 i = (int) SendMessage(GetDlgItem(hwndDialog, IDC_LIST), LB_GETCOUNT, 0, 0);
  82.                 SendMessage(GetDlgItem(hwndDialog, IDC_LIST), LB_SETCURSEL, (WPARAM) i - 1, 0);
  83.  
  84.                 hReturn = DdeCreateDataHandle(dwInst, (LPBYTE) &lDoesNotMatter, sizeof(lDoesNotMatter), 0,
  85.                                                 hszService, CF_TEXT, 0);
  86.                 return( hReturn );
  87.  
  88.             }
  89.  
  90.             lReturn = DDE_FACK;
  91.             hReturn = DdeCreateDataHandle(dwInst, (LPBYTE) &lReturn, sizeof(lReturn), 0,
  92.                     hszService, CF_TEXT, 0);
  93.             return( hReturn );
  94.             //return DDE_FACK;
  95.  
  96.         case XTYP_POKE:
  97.             break;
  98.  
  99.         case XTYP_CONNECT:
  100.             hReturn = (HDDEDATA)(hszService == hsz2 );
  101.             return hReturn;
  102.  
  103.         case XTYP_WILDCONNECT:
  104.             ahszp[0].hszTopic = hsz1;
  105.             ahszp[0].hszSvc = hszService;
  106.  
  107.             // null terminate the array
  108.             ahszp[1].hszTopic = NULL;
  109.             ahszp[1].hszSvc = NULL;
  110.             return( DdeCreateDataHandle(dwInst, (LPBYTE) &ahszp, sizeof( ahszp), 0,
  111.                                         (HSZ)NULL, 0, 0));
  112.         default:
  113.             break;
  114.     }
  115.  
  116.     return 0;
  117. }
  118.  
  119. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  120.                     LPSTR lpszCmdParam, int nCmdShow)
  121. {
  122.     static char szServiceName[] = "ddetest" ;
  123.     HWND        hwnd ;
  124.     MSG         msg ;
  125.     WNDCLASS    wndclass ;
  126.  
  127.     pCommand = lpszCmdParam;
  128.     
  129.     if (!hPrevInstance)
  130.     {
  131.         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  132.         wndclass.lpfnWndProc   = WndProc ;
  133.         wndclass.cbClsExtra    = 0 ;
  134.         wndclass.cbWndExtra    = 0 ;
  135.         wndclass.hInstance     = hInstance ;
  136.         wndclass.hIcon         = NULL;
  137.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  138.  
  139.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  140.         wndclass.lpszMenuName  = NULL ;
  141.         wndclass.lpszClassName = szServiceName ;
  142.  
  143.         RegisterClass (&wndclass) ;
  144.     }
  145.     
  146.     ghInst = hInstance;
  147.  
  148. #ifdef _WIN32
  149.     lpfnMLEProc = MLEProc;
  150.     lpfnResponseProc = ResponseProc;
  151.     //lpfnDDEProc = DdeCallBack;
  152.     lpfnDDEProc = MakeProcInstance( (PFNCALLBACK)DdeCallBack, ghInst);
  153.     lpfnRegisterProc = RegisterProc;
  154. #else
  155.     lpfnMLEProc = MakeProcInstance((FARPROC) MLEProc, ghInst);
  156.     lpfnResponseProc = MakeProcInstance((FARPROC) ResponseProc, ghInst);
  157.     lpfnDDEProc = MakeProcInstance((FARPROC) DdeCallBack, ghInst);
  158.     lpfnRegisterProc = MakeProcInstance((FARPROC) RegisterProc, ghInst);
  159. #endif
  160.     
  161.     hwnd = CreateWindow (szServiceName,       // window class name
  162.                     "DDE Test",   // window caption
  163.                     WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
  164.                     0, 0, 200, 400,
  165.                     NULL,                  // parent window handle
  166.                     NULL,                  // window menu handle
  167.                     hInstance,             // program instance handle
  168.                     NULL) ;                // creation parameters
  169.  
  170.     ShowWindow(hwnd, nCmdShow);
  171.     //WinExec( "d:\\dev\\win\\dialer\\dialer\\airdial.exe", SW_MINIMIZE );
  172.  
  173.  
  174.     while (GetMessage (&msg, NULL, 0, 0))
  175.     {
  176.         if (!IsWindow(hModeless) || !IsDialogMessage(hModeless, &msg))
  177.         {
  178.             TranslateMessage (&msg) ;
  179.             DispatchMessage (&msg) ;
  180.         }
  181.     }
  182.     
  183. #ifndef _WIN32
  184.     FreeProcInstance(lpfnMLEProc);
  185.     FreeProcInstance(lpfnResponseProc);
  186.     FreeProcInstance(lpfnDDEProc);
  187.     FreeProcInstance(lpfnRegisterProc);
  188. #endif
  189.     
  190.     return msg.wParam ;
  191. }
  192.  
  193. BOOL CALLBACK _export DialogProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  194. {
  195.     char szTopic[256];
  196.     char szMessage[256];
  197.     char szTemp[100];
  198.     char szArg[1000];
  199.     static HSZ hszTopic = (HSZ) NULL;
  200.     static HSZ hszItem = 0;
  201.     LRESULT count, length;
  202.     HWND h;
  203.     long i;
  204.     HDDEDATA trans_ret;
  205.     long long_result;
  206.  
  207.     switch(message)
  208.     {
  209.         case WM_INITDIALOG:
  210.             
  211.             DialogBox(ghInst, MAKEINTRESOURCE(ID_REGISTER), hwnd, lpfnRegisterProc);
  212.             
  213.             EnableWindow(GetDlgItem(hwnd, IDC_APPLICATION), FALSE);
  214.         
  215.             hModeless = hwnd;
  216.  
  217.             lProc = GetWindowLong(GetDlgItem(hwnd, IDC_ARGS), GWL_WNDPROC);
  218.             
  219.             SetWindowLong(GetDlgItem(hwnd, IDC_ARGS), GWL_WNDPROC, (LONG) lpfnMLEProc);
  220.             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_SETHORIZONTALEXTENT, 0x7FFF, 0);
  221.             SetWindowText(GetDlgItem(hwnd, IDC_APPLICATION), szService);
  222.  
  223.             h = GetDlgItem(hwnd, IDC_COMMAND);
  224.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_WinExec");
  225.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_DIAL");
  226.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_DIALQUIET");
  227.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_CANCELDIAL");
  228.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_INICHANGE");
  229.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_SHUTDOWN");
  230.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_SHUTDOWNQUIET");
  231.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_MODEMHANGUP");
  232.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_MODEMHANGUPQUIET");
  233.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_POST_DIALMODE");
  234.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_POST_DIALSTATE");
  235.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_TOGGLE_QUIETMODE");
  236.             SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_TOGGLE_DASHBOARD");
  237.             //SendMessage( h, CB_ADDSTRING, 0, (LPARAM) (char *) "DIALER_TOGGLE_PACKETMODE");
  238.  
  239.  
  240.  
  241.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_OpenURL");
  242.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_OpenURLResult");
  243.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_Activate");
  244.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_ListWindows");
  245.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_GetWindowInfo");
  246.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_Exit");
  247.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_RegisterProtocol");
  248.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_UnRegisterProtocol");
  249.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_RegisterViewer");
  250.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_UnRegisterViewer");
  251.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_ParseAnchor");
  252.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_RegisterWindowClose");
  253.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_UnRegisterWindowClose");
  254.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_BeginProgress");
  255.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_SetProgressRange");
  256.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_MakingProgress");
  257.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_EndProgress");
  258.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_RegisterURLEcho");
  259.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_UnRegisterURLEcho");
  260.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_ShowFile");
  261.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_QueryVersion");
  262.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_CancelTransaction");
  263.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_RegisterDone");
  264.  
  265.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_NavFwd");
  266.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_NavBack");
  267.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_NavHome");
  268.         //  SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (char *) "WWW_NavReload");
  269.  
  270.             // make sure there is an entry in the window
  271.         //  SendMessage(h, CB_SETCURSEL, 0, (LPARAM) 0l );
  272.  
  273.  
  274.             // Add the command line to listbox
  275.  
  276.         //  sprintf(szTemp, "Command line: %s", pCommand);
  277.         //  SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) szTemp);
  278.             break;
  279.  
  280.         case WM_COMMAND:
  281.             switch(LOWORD(wParam))
  282.             {
  283.                 case IDC_HELP:
  284.                     GetWindowsDirectory(szArg, sizeof(szArg));
  285.                     if (szArg[strlen(szArg) - 1] != '\\')
  286.                         strcat(szArg, "\\");
  287.                     strcat(szArg, "WINHELP DDETEST.HLP");
  288.                     WinExec(szArg, SW_SHOW);
  289.                     break;
  290.                     
  291.                 case IDC_SEND:
  292.                     GetWindowText(GetDlgItem(hwnd, IDC_COMMAND), szTopic, sizeof(szTopic));
  293.  
  294.                     if (strlen(szTopic) == 0)
  295.                         break;
  296.  
  297.                     // Compose the argument string
  298.  
  299.                     count = SendMessage(GetDlgItem(hwnd, IDC_ARGS), EM_GETLINECOUNT, 0, 0);
  300.                     memset(szArg, 0, sizeof(szArg));
  301.  
  302.                     for (i = 0; i < count; i++)
  303.                     {
  304.                         memset(szTemp, 0, sizeof(szTemp));
  305.                         *((WORD *) szTemp) = sizeof(szTemp) - sizeof(WORD);
  306.                         length = SendMessage(GetDlgItem(hwnd, IDC_ARGS), EM_GETLINE, (WPARAM) i, (LPARAM) szTemp);
  307.                         if (length)
  308.                             strcat(szArg, szTemp);
  309.                         if (i != count - 1)
  310.                             strcat(szArg, ",");
  311.                     }
  312.  
  313.                     // tell the dialer to start dialing
  314.                 //  if( stricmp( szTopic, "Dial") == 0 )
  315.                 //  {
  316.                 //      HWND hWndDialer = NULL;
  317.                 //      hWndDialer = FindWindow( "AfxFrameOrView", NULL);
  318.                 //      if( hWndDialer )
  319.                 //      {
  320.                 //          SendMessage( hWndDialer, WM_COMMAND, (WPARAM)32789, 0l);
  321.                 //      }
  322.                 //  }
  323.  
  324.                     if (hszTopic)
  325.                         DdeFreeStringHandle(dwInst, hszTopic);
  326.                     hszTopic = DdeCreateStringHandle(dwInst, szTopic, CP_WINANSI);
  327.  
  328.                     if (hszItem)
  329.                         DdeFreeStringHandle(dwInst, hszItem);
  330.                     hszItem = DdeCreateStringHandle(dwInst, szArg, CP_WINANSI);
  331.                     if (!hszItem)
  332.                     {
  333.                         // Item name cannot be 0, so make up some name
  334.  
  335.                         hszItem = DdeCreateStringHandle(dwInst, szService, CP_WINANSI);
  336.                     }
  337.  
  338.                     hConv = DdeConnect(dwInst, hszMosaicService, hszTopic, NULL);
  339.  
  340.                     sprintf(szMessage, "Connect handle: %ld (0 means fail)", hConv);
  341.                     SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) szMessage);
  342.  
  343.                     if (strcmp(szTopic, "WWW_Exit") == 0 ||
  344.                         strcmp(szTopic, "WWW_RegisterDone") == 0)
  345.                     {
  346.                         // Poke
  347.  
  348.                         trans_ret = DdeClientTransaction(NULL, 0, hConv, hszItem, CF_TEXT, XTYP_POKE,
  349.                             60000, NULL);
  350.                     }
  351.                     else
  352.                     {
  353.                         // Request
  354.  
  355.                         trans_ret = DdeClientTransaction(NULL, 0, hConv, hszItem, CF_TEXT, XTYP_REQUEST,
  356.                             60000, NULL);
  357.                     }
  358.  
  359.  
  360.  
  361.                     if( strcmp( szTopic, "DIALER_MODEMHANGUP" ) == 0        || 
  362.                         strcmp( szTopic, "DIALER_MODEMHANGUPQUIET" ) == 0   ||
  363.                         strcmp( szTopic, "DIALER_SHUTDOWN" ) == 0           ||
  364.                         strcmp( szTopic, "DIALER_INICHANGE" ) == 0          ||
  365.                         strcmp( szTopic, "DIALER_CANCELDIAL" ) == 0         ||
  366.                         strcmp( szTopic, "DIALER_DIAL" ) == 0               ||
  367.                         strcmp( szTopic, "DIALER_DIALQUIET" ) == 0 )
  368.                     {
  369.                         if (trans_ret != DDE_FNOTPROCESSED)
  370.                         {
  371.                             long *pBuffer;
  372.                             long itemcount;
  373.  
  374.                             // get the first long to see how many items exist
  375.                             
  376.                             pBuffer = (long *) malloc(sizeof(long));
  377.                             DdeGetData(trans_ret, (LPBYTE) pBuffer, sizeof(long), 0);
  378.                             itemcount = *pBuffer;
  379.                             
  380.                             free(pBuffer);
  381.                             pBuffer = (long *) malloc((size_t) sizeof(long) * (size_t) itemcount);
  382.                             DdeGetData(trans_ret, (LPBYTE) pBuffer, itemcount * sizeof(long), sizeof(long));
  383.                             
  384.                             DdeFreeDataHandle(trans_ret);
  385.  
  386.                             strcpy(szArg, "Transaction result: ");
  387.  
  388.                             // caution: we are limited to 1000 characters total, but no checking will be
  389.                             // done (because szArg is char[1000])
  390.  
  391.                             for (i = 0; i < itemcount; i++)
  392.                             {
  393.                                 sprintf(szMessage, " %ld", pBuffer[i]);
  394.                                 strcat(szArg, szMessage);
  395.                             }
  396.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) szArg);
  397.  
  398.                             free(pBuffer);
  399.                         }
  400.                         else
  401.                         {
  402.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) (char *) "Transaction failed.");
  403.                         }
  404.  
  405.                     }
  406.                 //  else if( strcmp( szTopic, "DIALER_WINEXEC" ) == 0 )
  407.                 //  {
  408.                 //  
  409.                 //
  410.                 //  }
  411.                     else if (strcmp(szTopic, "WWW_ListWindows") == 0)
  412.                     {
  413.                         // specialized return value
  414.  
  415.                         if (trans_ret != DDE_FNOTPROCESSED)
  416.                         {
  417.                             long *pBuffer;
  418.                             long itemcount;
  419.  
  420.                             // get the first long to see how many items exist
  421.                             
  422.                             pBuffer = (long *) malloc(sizeof(long));
  423.                             DdeGetData(trans_ret, (LPBYTE) pBuffer, sizeof(long), 0);
  424.                             itemcount = *pBuffer;
  425.                             
  426.                             free(pBuffer);
  427.                             pBuffer = (long *) malloc((size_t) sizeof(long) * (size_t) itemcount);
  428.                             DdeGetData(trans_ret, (LPBYTE) pBuffer, itemcount * sizeof(long), sizeof(long));
  429.                             
  430.                             DdeFreeDataHandle(trans_ret);
  431.  
  432.                             strcpy(szArg, "Transaction result: ");
  433.  
  434.                             // caution: we are limited to 1000 characters total, but no checking will be
  435.                             // done (because szArg is char[1000])
  436.  
  437.                             for (i = 0; i < itemcount; i++)
  438.                             {
  439.                                 sprintf(szMessage, " %ld", pBuffer[i]);
  440.                                 strcat(szArg, szMessage);
  441.                             }
  442.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) szArg);
  443.  
  444.                             free(pBuffer);
  445.                         }
  446.                         else
  447.                         {
  448.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) (char *) "Transaction failed.");
  449.                         }
  450.                     }
  451.                     else if (strcmp(szTopic, "WWW_GetWindowInfo") == 0 ||
  452.                              strcmp(szTopic, "WWW_ParseAnchor") == 0 ||
  453.                              strcmp(szTopic, "WWW_QueryVersion") == 0)
  454.                     {
  455.                         // string return value
  456.  
  457.                         if (trans_ret != DDE_FNOTPROCESSED)
  458.                         {
  459.                             char *pBuffer, *pTemp;
  460.                             long bufsize;
  461.  
  462.                             bufsize = DdeGetData(trans_ret, NULL, 0, 0);            // get length
  463.                             pBuffer = malloc((int) bufsize + sizeof(char));             // 1 extra for terminator
  464.                             DdeGetData(trans_ret, (LPBYTE) pBuffer, bufsize, 0);    // get data
  465.                             pBuffer[bufsize] = '\0';                                // null terminate
  466.                             DdeFreeDataHandle(trans_ret);                           // free  handle
  467.  
  468.                             pTemp = malloc((int) bufsize + 100);
  469.                             sprintf(pTemp, "Transaction result: %s", pBuffer);
  470.  
  471.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) pTemp);
  472.  
  473.                             free(pTemp);
  474.                             free(pBuffer);
  475.                         }
  476.                         else
  477.                         {
  478.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) (char *) "Transaction failed.");
  479.                         }
  480.                     }
  481.                     else if (strcmp(szTopic, "WWW_UnRegisterViewer") == 0 ||
  482.                              strcmp(szTopic, "WWW_Exit") == 0 ||
  483.                              strcmp(szTopic, "WWW_UnRegisterProtocol") == 0 ||
  484.                              strcmp(szTopic, "WWW_RegisterDone") == 0 ||
  485.                              strcmp(szTopic, "WWW_OpenURLResult") == 0)
  486.                     {
  487.                         // no return value
  488.                         SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, 
  489.                             (LPARAM) (char *) "Mosaic does not return any value for this verb.");
  490.                     }
  491.                     else if //(strcmp(szTopic, "WWW_RegisterProtocol") == 0 || 
  492.                            ( strcmp(szTopic, "WWW_RegisterViewer") == 0 ||
  493.                              strcmp(szTopic, "WWW_Activate") == 0 ||
  494.                              strcmp(szTopic, "WWW_OpenURL") == 0 ||
  495.                              //strcmp(szTopic, "WWW_RegisterWindowClose") == 0 ||
  496.                              //strcmp(szTopic, "WWW_UnRegisterWindowClose") == 0 ||
  497.                              strcmp(szTopic, "WWW_BeginProgress") == 0 ||
  498.                              strcmp(szTopic, "WWW_SetProgressRange") == 0 ||
  499.                              strcmp(szTopic, "WWW_MakingProgress") == 0 ||
  500.                              strcmp(szTopic, "WWW_EndProgress") == 0 ||
  501.                              //strcmp(szTopic, "WWW_RegisterURLEcho") == 0 ||
  502.                              //strcmp(szTopic, "WWW_UnRegisterURLEcho") == 0 ||
  503.                              //strcmp(szTopic, "WWW_ShowFile") == 0 ||
  504.                              strcmp( szTopic, "WWW_NavFwd" ) == 0 ||
  505.                              strcmp( szTopic, "WWW_NavBack" ) == 0 ||
  506.                              strcmp( szTopic, "WWW_NavHome" ) == 0 ||
  507.                              strcmp( szTopic, "WWW_NavReload" ) == 0 ||
  508.                              strcmp(szTopic, "WWW_CancelTransaction") == 0)
  509.                     {
  510.                         // long integer return value
  511.  
  512.                         if (trans_ret != DDE_FNOTPROCESSED)
  513.                         {
  514.                             DdeGetData(trans_ret, (LPBYTE) &long_result, sizeof(long_result), 0);
  515.                             DdeFreeDataHandle(trans_ret);
  516.                             sprintf(szMessage, "Transaction result: %ld", long_result);
  517.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) szMessage);
  518.                         }
  519.                         else
  520.                             SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_ADDSTRING, 0, (LPARAM) (char *) "Transaction failed.");
  521.                     }
  522.  
  523.                     i = (int) SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_GETCOUNT, 0, 0);
  524.                     SendMessage(GetDlgItem(hwnd, IDC_LIST), LB_SETCURSEL, (WPARAM) i - 1, 0);
  525.  
  526.                     if (hConv)
  527.                         DdeDisconnect(hConv);
  528.  
  529.                     break;
  530.  
  531.                 case IDC_EXIT:
  532.                     PostMessage(hwnd, WM_CLOSE, 0, 0);
  533.                     break;
  534.  
  535.                 case IDC_CLEARLIST:
  536.                     SendDlgItemMessage(hwnd, IDC_LIST, LB_RESETCONTENT, 0, 0);
  537.                     break;
  538.  
  539.                 case IDC_CLEARARGUMENTS:
  540.                     SetDlgItemText(hwnd, IDC_ARGS, "");
  541.                     SetFocus(GetDlgItem(hwnd, IDC_ARGS));
  542.                     break;
  543.             }
  544.             return TRUE;
  545.  
  546.         case WM_CLOSE:
  547.             SetWindowLong(GetDlgItem(hwnd, IDC_ARGS), GWL_WNDPROC, lProc);
  548.  
  549.             DdeNameService(dwInst, hszService, 0, DNS_UNREGISTER);
  550.  
  551.             if (hszService)
  552.                 DdeFreeStringHandle(dwInst, hszService);
  553.             if (hszTopic)
  554.                 DdeFreeStringHandle(dwInst, hszTopic);
  555.             if (hszItem)
  556.                 DdeFreeStringHandle(dwInst, hszItem);
  557.             if (hszMosaicService)
  558.                 DdeFreeStringHandle(dwInst, hszMosaicService);
  559.  
  560.             DdeUninitialize(dwInst);
  561.  
  562.             hModeless = NULL;
  563.             DestroyWindow(GetParent(hwnd));
  564.             return TRUE;
  565.     }
  566.  
  567.     return FALSE;
  568. }
  569.  
  570. LRESULT CALLBACK _export WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  571. {
  572.     switch(message)
  573.     {
  574.         case WM_CREATE:
  575.             hwndDialog = CreateDialog(ghInst, MAKEINTRESOURCE(ID_DIALOG), hwnd, DialogProc);
  576.             break;
  577.  
  578.         case WM_DESTROY:
  579.             PostQuitMessage(0);
  580.             return 0;
  581.     }
  582.  
  583.     return (DefWindowProc(hwnd, message, wParam, lParam));
  584. }
  585.  
  586. LRESULT CALLBACK _export MLEProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  587. {
  588.     switch (message)
  589.     {
  590.         case WM_KEYDOWN:
  591.             if (VK_RETURN == wParam)
  592.             {
  593.                 PostMessage(hwnd, WM_CHAR, 0x0A, 0L);
  594.                 return 0L;
  595.             }
  596.             break;
  597.         default:
  598.             break;
  599.     }
  600.     return (LRESULT) (CallWindowProc((FARPROC) lProc, hwnd, message, wParam, lParam));
  601. }
  602.  
  603. BOOL CALLBACK _export ResponseProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  604. {
  605.     static char *pBuffer;
  606.  
  607.     switch(message)
  608.     {
  609.         case WM_INITDIALOG:
  610.             pBuffer = (char *) lParam;
  611.             SetWindowText(GetDlgItem(hwnd, IDC_TOPIC), pTopic);
  612.             MessageBeep(0);
  613.             break;
  614.  
  615.         case WM_COMMAND:
  616.             if (LOWORD(wParam) == IDOK)
  617.             {
  618.                 GetWindowText(GetDlgItem(hwnd, IDC_RESPONSE), pBuffer, 1000);
  619.                 EndDialog(hwnd, TRUE);
  620.             }
  621.             else if (LOWORD(wParam) == IDCANCEL)
  622.                 EndDialog(hwnd, FALSE);
  623.             break;
  624.     }
  625.  
  626.     return FALSE;
  627. }
  628.  
  629. BOOL CALLBACK _export RegisterProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
  630. {
  631.     switch(message)
  632.     {
  633.         case WM_INITDIALOG:
  634.             SetWindowText(GetDlgItem(hwnd, IDC_DDENAME), "ddetest");
  635.             break;
  636.  
  637.         case WM_COMMAND:
  638.             if (LOWORD(wParam) == IDOK)
  639.             {
  640.                 if (dwInst == 0)
  641.                     DdeInitialize(&dwInst, (PFNCALLBACK) lpfnDDEProc, APPCLASS_STANDARD, 0);
  642.                     
  643.                 hszMosaicService = DdeCreateStringHandle(dwInst, "SPRYDIALER", CP_WINANSI);
  644.                 
  645.                 GetWindowText(GetDlgItem(hwnd, IDC_DDENAME), szService, sizeof(szService));
  646.                 hszService = DdeCreateStringHandle(dwInst, szService, CP_WINANSI);
  647.                     
  648.                 if (DdeNameService(dwInst, hszService, 0, DNS_REGISTER))
  649.                 {
  650.                     EndDialog(hwnd, TRUE);
  651.                     return 0;
  652.                 }
  653.                     
  654.                 MessageBox(hwnd, "Registration failed.  Try using another name.", "Error", MB_OK);
  655.                 
  656.                 //DdeFreeStringHandle(dwInst, hszMosaicService);
  657.                 //DdeFreeStringHandle(dwInst, hszService);
  658.             }
  659.             break;
  660.     }
  661.  
  662.     return FALSE;
  663. }
  664.  
  665.  
  666.  
  667.