home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / iwftech.zip / samples / WFEdit / wfedit.C next >
Text File  |  1994-07-21  |  28KB  |  787 lines

  1. /*+--------------------------------------------------------------------------+*/
  2. /*|WF/2 Editor DDE sample                                                    |*/
  3. /*|--------------------------------------------------------------------------|*/
  4. /*|                                                                          |*/
  5. /*| PROGRAM NAME: WFEDIT                                                     |*/
  6. /*| -------------                                                            |*/
  7. /*|                                                                          |*/
  8. /*| COPYRIGHT:                                                               |*/
  9. /*| ----------                                                               |*/
  10. /*| Copyright (C) International Business Machines Corp., 1991,1992,1993,1994.|*/
  11. /*|                                                                          |*/
  12. /*| DISCLAIMER OF WARRANTIES:                                                |*/
  13. /*| -------------------------                                                |*/
  14. /*| The following [enclosed] code is sample code created by IBM              |*/
  15. /*| Corporation.  This sample code is not part of any standard IBM product   |*/
  16. /*| and is provided to you solely for the purpose of assisting you in the    |*/
  17. /*| development of your applications.  The code is provided "AS IS",         |*/
  18. /*| without warranty of any kind.  IBM shall not be liable for any damages   |*/
  19. /*| arising out of your use of the sample code, even if they have been       |*/
  20. /*| advised of the possibility of such damages.                              |*/
  21. /*|                                                                          |*/
  22. /*| REVISION LEVEL: 2.1                                                      |*/
  23. /*| -------------------                                                      |*/
  24. /*|                                                                          |*/
  25. /*|  This program illustrates the editor side of the DDE and D&D protocols   |*/
  26. /*|  used by WorkFrame/2 version 1.x and 2.1.                                |*/
  27. /*|                                                                          |*/
  28. /*+--------------------------------------------------------------------------+*/
  29. #define INCL_DOSFILEMGR
  30. #define INCL_WINDDE
  31. #define INCL_WINFRAMEMGR
  32. #define INCL_WINHELP
  33. #define INCL_WINLISTBOXES
  34. #define INCL_WINMENUS
  35. #define INCL_WINPOINTERS
  36. #define INCL_WINSTDDRAG
  37. #define INCL_WINSYS
  38. #define INCL_ERRORS
  39. #include <os2.h>
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44.  
  45. #include "wkfedit.h"   /* DDE signatures       */
  46. #include "wfedit.h"    /* resource definitions */
  47.  
  48.  
  49. /* ----------------------------------------------------------------- */
  50. /* Function prototypes                                               */
  51. /* ----------------------------------------------------------------- */
  52. FNWP       fnwpClientWndProc;
  53.  
  54. MRESULT    mrCreate       ( HWND hwnd );
  55. MRESULT    mrDragOver     ( HWND hwnd, PDRAGINFO pDraginfo );
  56. MRESULT    mrDrop         ( HWND hwnd, PDRAGINFO pDraginfo );
  57. MRESULT    mrDropHelp     ( HWND hwnd, PDRAGINFO pDraginfo );
  58. MRESULT    mrPaint        ( HWND hwnd, CHAR *szErrorMsg );
  59. MRESULT    mrSize         ( HWND hwnd, MPARAM mp2 );
  60.  
  61. VOID       ddeExecute     ( HWND hwnd, HWND hwndMsg, PDDESTRUCT pDDE );
  62. VOID       ddeInitiate    ( HWND hwnd, HWND hwndMsg, PDDEINIT pDDEi );
  63. PDDESTRUCT pddeMakeRequest( USHORT usFormat,
  64.                             PSZ    pszItemName,
  65.                             PVOID  pvData,
  66.                             USHORT usDataSize );
  67. BOOL       ddeSendGoto    ( HWND hwnd );
  68. VOID       ddeTerminate   ( HWND hwnd, HWND hwndMsg );
  69.  
  70.  
  71. /* ----------------------------------------------------------------- */
  72. /* Globals                                                           */
  73. /* ----------------------------------------------------------------- */
  74. CHAR szClientClass[] = "WorkFrame/2 Sample Editor";
  75.  
  76. HAB  hAB;                              /* anchor block handle        */
  77. HMQ  hMQ;                              /* message queue handle       */
  78. HWND hwndFrame;                        /* frame window handle        */
  79. HWND hwndClient;                       /* client window handle       */
  80. HWND hwndMenu;                         /* menu window handle         */
  81. HWND hwndHelp;                         /* help instance handle       */
  82.  
  83. BOOL fConnected;                       /* DDE connection status      */
  84. HWND hwndDDE;                          /* DDE client window handle   */
  85. CHAR szTopicName[CCHMAXPATH];          /* DDE topic name buffer      */
  86.  
  87. CHAR szSourceFile[CCHMAXPATH];         /* qualified source name      */
  88. CHAR szLibraryFile[CCHMAXPATH];        /* library name buffer        */
  89.  
  90. CHAR szErrorLine[300];                 /* error text buffer          */
  91.  
  92. PULONG pulErrorLines;                  /* array of error lines       */
  93. PULONG pulErrorOffsets;                /* array of error offsets     */
  94. PULONG pulCookies;                     /* array of error cookies     */
  95.  
  96. ULONG ulErrorCount=0L;                 /* error count                */
  97. ULONG ulErrorIndex=0L;                 /* error index                */
  98. ULONG ulErrorLimit=0L;                 /* error limit                */
  99.  
  100. ULONG ulCurrentError;                  /* current error line         */
  101. ULONG ulCurrentOffset;                 /* current error offset       */
  102. ULONG ulCurrentCookie;                 /* current magic cookie       */
  103. ULONG ulCurrentResID;                  /* current resource ID        */
  104.  
  105.  
  106. /* ----------------------------------------------------------------- */
  107. /* Trace definitions                                                 */
  108. /* ----------------------------------------------------------------- */
  109.  
  110. HWND hwndTrace;                        /* listbox window handle      */
  111. CHAR szTrace[CCHMAXPATH+128];          /* Trace data buffer          */
  112.  
  113. #define TRACE(hwnd,psz) \
  114. {SHORT s = (SHORT)WinSendMsg(hwnd,LM_INSERTITEM,MPFROMSHORT(LIT_END), \
  115.    MPFROMP(psz)); WinSendMsg(hwnd,LM_SETTOPINDEX,MPFROMSHORT(s),NULL);}
  116.  
  117. #define FRAMEFLAGS \
  118.         FCF_TITLEBAR | FCF_SYSMENU | FCF_MENU                  \
  119.         | FCF_SIZEBORDER | FCF_MINMAX | FCF_TASKLIST
  120.  
  121.  
  122. /* ----------------------------------------------------------------- */
  123. /* main()                                                            */
  124. /* ----------------------------------------------------------------- */
  125.  
  126. int main( int argc, char** argv )
  127.    {
  128.    ULONG flFrameFlags =  FRAMEFLAGS;
  129.    QMSG  qMsg;
  130.  
  131.  
  132.    /* Fetch filename if specified */
  133.    if( argc != 2 )
  134.       *szSourceFile = (char) NULL;
  135.    else
  136.       strcpy( szSourceFile, argv[1] );
  137.  
  138.    strcpy( szTopicName, szSourceFile);
  139.  
  140.    /* --------------------------------------------------------------- */
  141.    /* Initialize with Presentation Manager                            */
  142.    /* --------------------------------------------------------------- */
  143.    hAB = WinInitialize(0);
  144.    hMQ = WinCreateMsgQueue(hAB, 0);
  145.    WinRegisterClass( hAB, szClientClass, fnwpClientWndProc, 0L, 0 );
  146.  
  147.    hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
  148.                                    WS_VISIBLE,
  149.                                    &flFrameFlags,
  150.                                    szClientClass,
  151.                                    NULL,
  152.                                    0L,
  153.                                    (HMODULE)NULL,
  154.                                    ID_SERVER,
  155.                                    &hwndClient );
  156.  
  157.    hwndMenu = WinWindowFromID( hwndFrame, FID_MENU );
  158.    hwndHelp = NULLHANDLE;
  159.  
  160.    WinSetWindowPos( hwndFrame,
  161.                     HWND_TOP, 200, 200,
  162.                     LONGFROMMR( WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ) )
  163.                           / 2,
  164.                     LONGFROMMR( WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) )
  165.                           / 2,
  166.                     SWP_SIZE | SWP_MOVE);
  167.  
  168.    WinSendMsg( hwndFrame,
  169.                WM_SETICON,
  170.                MPFROMLONG(WinQuerySysPointer( HWND_DESKTOP,
  171.                                               SPTR_APPICON,
  172.                                               FALSE)),
  173.                NULL );
  174.  
  175.    while( WinGetMsg( hAB, &qMsg, NULLHANDLE, 0, 0 ))
  176.       WinDispatchMsg( hAB, &qMsg );
  177.  
  178.    WinDestroyWindow( hwndFrame );
  179.    WinDestroyMsgQueue( hMQ );
  180.    WinTerminate( hAB );
  181.    return( 0 );
  182.    }
  183.  
  184.  
  185. /* ----------------------------------------------------------------- */
  186. /* fnwpClientWndProc()                                               */
  187. /* ----------------------------------------------------------------- */
  188.  
  189. MRESULT fnwpClientWndProc ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  190.    {
  191.    switch( msg )
  192.       {
  193.       case WM_CREATE:
  194.            return( mrCreate( hwnd ));
  195.  
  196.       case WM_SIZE:
  197.            return( mrSize( hwnd, mp2 ));
  198.  
  199.       case WM_PAINT:
  200.            return( mrPaint( hwnd, szErrorLine ));
  201.  
  202.       case WM_ERASEBACKGROUND:
  203.            return( (MRESULT)TRUE  );
  204.  
  205.       case WM_INITMENU:
  206.            if ( SHORT1FROMMP( mp1 ) == IDM_ERROR )
  207.               {
  208.               WinEnableMenuItem( hwndMenu,
  209.                                  IDM_NEXT,
  210.                                  ( ulErrorIndex < ulErrorLimit ));
  211.               WinEnableMenuItem( hwndMenu,
  212.                                  IDM_PREVIOUS,
  213.                                  ( ulErrorIndex > 0L ));
  214.               }
  215.            break;
  216.  
  217.       case WM_COMMAND:
  218.            switch( LOUSHORT( mp1 ))
  219.               {
  220.               case IDM_NEXT:
  221.                    ++ulErrorIndex;
  222.                    ddeSendGoto( hwnd );
  223.                    return( NULL );
  224.  
  225.               case IDM_PREVIOUS:
  226.                    --ulErrorIndex;
  227.                    ddeSendGoto( hwnd );
  228.                    return( NULL );
  229.  
  230.               case IDM_DESCRIBE:
  231.                    if ( WinSendMsg( hwndHelp,
  232.                                     HM_DISPLAY_HELP,
  233.                                     MPFROMLONG( MAKELONG( ulCurrentResID, NULL )),
  234.                                     MPFROMSHORT( HM_RESOURCEID )))
  235.                       WinAlarm( HWND_DESKTOP, WA_ERROR );
  236.                    return( NULL );
  237.               }
  238.            break;
  239.  
  240.       case WM_CLOSE:
  241.            if ( fConnected )
  242.                WinDdePostMsg( hwndDDE, hwnd, WM_DDE_TERMINATE, NULL, TRUE );
  243.            WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
  244.            return( NULL );
  245.  
  246.       case DM_DRAGOVER:
  247.            return( mrDragOver( hwnd, (PDRAGINFO) PVOIDFROMMP( mp1 )));
  248.  
  249.       case DM_DRAGLEAVE:
  250.            return( NULL );
  251.  
  252.       case DM_DROPHELP:
  253.            return( mrDropHelp( hwnd, (PDRAGINFO) PVOIDFROMMP( mp1 )));
  254.  
  255.       case DM_DROP:
  256.            return( mrDrop( hwnd, (PDRAGINFO) PVOIDFROMMP( mp1 )));
  257.  
  258.       case WM_DDE_INITIATE:
  259.            ddeInitiate( hwnd, HWNDFROMMP( mp1 ), PVOIDFROMMP( mp2 ));
  260.            break;
  261.  
  262.       case WM_DDE_EXECUTE:
  263.            ddeExecute( hwnd, HWNDFROMMP( mp1 ), PVOIDFROMMP( mp2 ));
  264.            return( NULL );
  265.  
  266.       case WM_DDE_TERMINATE:
  267.            ddeTerminate( hwnd, HWNDFROMMP( mp1 ));
  268.            break;
  269.  
  270.       case WM_USER:
  271.            if ( *szSourceFile
  272.                 && WinDdeInitiate( hwnd, CV_DDEAPPNAME, szTopicName, NULL ))
  273.               WinSetWindowText( hwndFrame, szSourceFile );
  274.            else
  275.               {
  276.               WinSetWindowText( hwndFrame, szClientClass );
  277.               WinEnableMenuItem( hwndMenu, IDM_ERROR, FALSE );
  278.               }
  279.            return( NULL );
  280.       }
  281.    return( WinDefWindowProc( hwnd, msg, mp1, mp2 ));
  282.    }
  283.  
  284.  
  285. /* ----------------------------------------------------------------- */
  286. /* mrCreate()                                                        */
  287. /* ----------------------------------------------------------------- */
  288.  
  289. MRESULT mrCreate( HWND hwnd )
  290.    {
  291.    RECTL rclClient;
  292.    LONG  cxClient, cyClient;
  293.  
  294.  
  295.    WinQueryWindowRect( hwnd, &rclClient );
  296.    cyClient  = (rclClient.yTop - rclClient.yBottom) / 2;
  297.    cxClient  = (rclClient.xRight - rclClient.xLeft) - 1;
  298.    hwndTrace = WinCreateWindow( hwnd,
  299.                                 WC_LISTBOX,
  300.                                 NULL,
  301.                                 WS_VISIBLE | LS_HORZSCROLL,
  302.                                 0,
  303.                                 0,
  304.                                 cxClient,
  305.                                 cyClient,
  306.                                 hwnd,
  307.                                 HWND_TOP,
  308.                                 ID_TRACE,
  309.                                 NULL,
  310.                                 NULL );
  311.  
  312.    *szErrorLine = '\0';
  313.    fConnected   = FALSE;
  314.    WinPostMsg( hwnd, WM_USER, NULL, NULL );
  315.    return( NULL );
  316.    }
  317.  
  318.  
  319. /* ----------------------------------------------------------------- */
  320. /* mrDragOver()                                                      */
  321. /* ----------------------------------------------------------------- */
  322.  
  323. MRESULT mrDragOver( HWND hwnd, PDRAGINFO pDraginfo )
  324.    {
  325.    PDRAGITEM pDragitem;
  326.    USHORT    usCount;
  327.    USHORT    usIndex;
  328.    USHORT    usIndicator;
  329.  
  330.    DrgAccessDraginfo( pDraginfo );
  331.    usCount     = DrgQueryDragitemCount( pDraginfo );
  332.    usIndicator = DOR_DROP;
  333.  
  334.    for( usIndex = 0; usIndex < usCount; ++usIndex )
  335.       {
  336.       pDragitem = DrgQueryDragitemPtr( pDraginfo, usIndex );
  337.       if ( !DrgVerifyRMF( pDragitem, "DRM_DDE", "DDE3ERRORS" ))
  338.          {
  339.          usIndicator = DOR_NODROP;
  340.          break;
  341.          }
  342.       }
  343.  
  344.    DrgFreeDraginfo( pDraginfo );
  345.  
  346.    return( MRFROM2SHORT( usIndicator, DO_COPY ));
  347.    }
  348.  
  349.  
  350. /* ----------------------------------------------------------------- */
  351. /* mrDrop()                                                          */
  352. /* ----------------------------------------------------------------- */
  353.  
  354. MRESULT mrDrop( HWND hwnd, PDRAGINFO pDraginfo )
  355.    {
  356.    USHORT usCount;
  357.    USHORT usItem;
  358.    PDRAGITEM pDragitem;
  359.  
  360.  
  361.    DrgAccessDraginfo( pDraginfo );
  362.    usCount = DrgQueryDragitemCount( pDraginfo );
  363.  
  364.    for( usItem = 0; usItem < usCount; usItem++ )
  365.       {
  366.       pDragitem = DrgQueryDragitemPtr( pDraginfo, usItem );
  367.       DrgQueryStrName( pDragitem->hstrSourceName,
  368.                        sizeof( szTopicName ),
  369.                        szTopicName );
  370.       DrgQueryStrName( pDragitem->hstrContainerName,
  371.                        sizeof( szSourceFile ),
  372.                        szSourceFile );
  373.  
  374.       sprintf( szTrace, "DROP: %s", szTopicName );
  375.       TRACE( hwndTrace, szTrace );
  376.  
  377.       sprintf( szTrace, "FROM: %s", szSourceFile );
  378.       TRACE( hwndTrace, szTrace );
  379.  
  380.       if( strchr( szTopicName, '\\' ) || strchr( szTopicName, ':' ))
  381.          strcpy( szSourceFile, szTopicName );
  382.       else
  383.          strcat( szSourceFile, szTopicName );
  384.  
  385.       DrgSendTransferMsg( pDragitem->hwndItem,
  386.                           DM_ENDCONVERSATION,
  387.                           MPFROMLONG( pDragitem->ulItemID ),
  388.                           MPFROMSHORT( DMFL_TARGETSUCCESSFUL ));
  389.       }
  390.  
  391.    if ( fConnected )
  392.       {
  393.       WinDdePostMsg( hwndDDE, hwnd, WM_DDE_TERMINATE, NULL, TRUE );
  394.       if ( hwndHelp )
  395.          {
  396.          WinDestroyHelpInstance( hwndHelp );
  397.          hwndHelp = NULLHANDLE;
  398.          }
  399.  
  400.       hwndDDE = NULLHANDLE;
  401.       fConnected = FALSE;
  402.       }
  403.  
  404.    WinPostMsg( hwnd, WM_USER, MPFROMHWND(pDraginfo->hwndSource), NULL );
  405.  
  406.    DrgDeleteDraginfoStrHandles( pDraginfo );
  407.    DrgFreeDraginfo( pDraginfo );
  408.    return( NULL );
  409.    }
  410.  
  411.  
  412. /* ----------------------------------------------------------------- */
  413. /* mrDropHelp()                                                      */
  414. /* ----------------------------------------------------------------- */
  415.  
  416. MRESULT mrDropHelp( HWND hwnd, PDRAGINFO pDraginfo )
  417.    {
  418.    DrgAccessDraginfo( pDraginfo );
  419.    WinAlarm( HWND_DESKTOP, WA_NOTE );
  420.  
  421.    if ( hwnd != pDraginfo->hwndSource )
  422.       DrgDeleteDraginfoStrHandles( pDraginfo );
  423.    DrgFreeDraginfo( pDraginfo );
  424.    return( NULL );
  425.    }
  426.  
  427.  
  428. /* ----------------------------------------------------------------- */
  429. /* mrPaint()                                                         */
  430. /* ----------------------------------------------------------------- */
  431.  
  432. MRESULT mrPaint( HWND hwnd, CHAR *szErrorMsg )
  433.    {
  434.    HPS    hPS;
  435.    RECTL  rclPaint;
  436.    LONG   lDivisor;
  437.    CHAR   szPaintStr[91];
  438.    CHAR   szWorkStr[16];
  439.    USHORT i;
  440.    ULONG  j;
  441.    PULONG pulWorklines;
  442.    PULONG pulWorkoff;
  443.    PULONG pulWorkcookie;
  444.  
  445.  
  446.    hPS = WinBeginPaint( hwnd, NULLHANDLE, NULL );
  447.    GpiErase( hPS );
  448.    WinQueryWindowRect( hwnd, &rclPaint );
  449.    rclPaint.yBottom = rclPaint.yTop / 2 + 1;
  450.  
  451.    if( !*szSourceFile )
  452.       WinDrawText( hPS,
  453.                    -1,
  454.                    "No file selected",
  455.                    &rclPaint,
  456.          CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  457.  
  458.    else if ( ulErrorCount == 0 )
  459.       WinDrawText( hPS,
  460.                    -1,
  461.                    "No errors",
  462.                    &rclPaint,
  463.          CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  464.  
  465.    else
  466.       {
  467.       lDivisor = ( rclPaint.yTop - rclPaint.yBottom )
  468.                  / ( 6 + ( ulErrorCount / 5 ));
  469.       rclPaint.yBottom = rclPaint.yTop - lDivisor;
  470.       WinDrawText( hPS,
  471.                    -1,
  472.                    "Error Lines:(line,offset,magic)",
  473.                    &rclPaint,
  474.          CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  475.  
  476.       j = 0;
  477.       pulWorklines  = pulErrorLines;
  478.       pulWorkoff    = pulErrorOffsets;
  479.       pulWorkcookie = pulCookies;
  480.  
  481.       while( j  < ulErrorCount )
  482.          {
  483.          rclPaint.yTop = rclPaint.yBottom;
  484.          rclPaint.yBottom = rclPaint.yTop - lDivisor;
  485.          *szPaintStr = '\0';
  486.          i = 5;
  487.          while(( i > 0 ) && ( j < ulErrorCount ))
  488.             {
  489.             sprintf( szWorkStr,
  490.                      "(%4ld,%3ld,%4ld)",
  491.                      *pulWorklines, *pulWorkoff, *pulWorkcookie );
  492.             ++pulWorklines;
  493.             ++pulWorkoff  ;
  494.             ++pulWorkcookie ;
  495.             strcat( szPaintStr, szWorkStr );
  496.             strcat( szPaintStr, "  " );
  497.             --i;
  498.             ++j;
  499.             }
  500.  
  501.          WinDrawText( hPS,
  502.                       -1,
  503.                       szPaintStr,
  504.                       &rclPaint,
  505.             CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  506.          }
  507.  
  508.       if ( ulCurrentError > 0 )
  509.          {
  510.          sprintf( szPaintStr,
  511.                   "Current Error - %ld,%ld,%ld",
  512.                   ulCurrentError,
  513.  
  514.          ulCurrentOffset, ulCurrentCookie );
  515.          rclPaint.yTop = rclPaint.yBottom;
  516.          rclPaint.yBottom = rclPaint.yTop - lDivisor;
  517.          WinDrawText( hPS,
  518.                       -1,
  519.                       szPaintStr,
  520.                       &rclPaint,
  521.             CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  522.  
  523.          rclPaint.yTop    = rclPaint.yBottom;
  524.          rclPaint.yBottom = rclPaint.yTop - lDivisor;
  525.          WinDrawText( hPS,
  526.                       -1,
  527.                       szErrorMsg,
  528.                       &rclPaint,
  529.             CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  530.  
  531.          sprintf( szPaintStr, "Library - %s (%ld)", szLibraryFile, ulCurrentResID );
  532.          rclPaint.yTop = rclPaint.yBottom;
  533.          rclPaint.yBottom = rclPaint.yTop - lDivisor;
  534.          WinDrawText( hPS, -1, szPaintStr, &rclPaint,
  535.             CLR_NEUTRAL, CLR_BACKGROUND, DT_CENTER | DT_VCENTER | DT_ERASERECT );
  536.       }
  537.    }
  538.    WinEndPaint( hPS );
  539.  
  540.    WinInvalidateRect( hwndTrace, NULL, FALSE );
  541.    return( NULL );
  542. }
  543.  
  544.  
  545.  
  546. /* ----------------------------------------------------------------- */
  547. /* mrSize()                                                          */
  548. /* ----------------------------------------------------------------- */
  549.  
  550. MRESULT mrSize( HWND hwnd, MPARAM mp2 )
  551.    {
  552.    LONG  cxClient, cyClient;
  553.  
  554.  
  555.    if ( hwndTrace )
  556.       {
  557.       cyClient = SHORT2FROMMP( mp2 ) / 2;
  558.       cxClient = SHORT1FROMMP( mp2 ) - 1;
  559.       WinSetWindowPos( hwndTrace,
  560.                        HWND_TOP,
  561.                        0,
  562.                        0,
  563.                        cxClient,
  564.                         cyClient,
  565.                        SWP_MOVE | SWP_SIZE | SWP_SHOW );
  566.       }
  567.  
  568.    WinInvalidateRect( hwnd, NULL, FALSE );
  569.    return( NULL );
  570.    }
  571.  
  572.  
  573. /* ----------------------------------------------------------------- */
  574. /* ddeExecute()                                                      */
  575. /* ----------------------------------------------------------------- */
  576.  
  577. VOID ddeExecute( HWND hwnd, HWND hwndMsg, PDDESTRUCT pDDE )
  578.    {
  579.    PULONG pulWorkLines;
  580.    PULONG pulLineWork;
  581.    PULONG pulOffWork;
  582.    PULONG pulCookieWork;
  583.    ULONG ulIndex;
  584.    ULONG ulNewCookie;
  585.    PVOID pvWork;
  586.    HELPINIT hlpInit;
  587.  
  588.  
  589.    if ( pDDE && ( hwndMsg == hwndDDE ))
  590.       {
  591.       /* Convert pDDE offset into a pointer to the topic field */
  592.       /* using PM macro DDES_PSZITEMNAME */
  593.       sprintf( szTrace, "DDE_EXECUTE: %s", DDES_PSZITEMNAME( pDDE ));
  594.       TRACE( hwndTrace, szTrace );
  595.  
  596.       /* Check for "Initialize" message topic */
  597.       if ( !strcmp( DDES_PSZITEMNAME( pDDE ), CV_DDEINITIAL ))
  598.          {
  599.          /* Convert offset into a pointer to the message array using */
  600.          /* PM macro DDES_PABDATA */
  601.          pulWorkLines = (PULONG) DDES_PABDATA( pDDE );
  602.          ulErrorCount = *pulWorkLines;
  603.          ulErrorIndex = 0L;
  604.          ulErrorLimit = ulErrorCount - 1L;
  605.  
  606.          pulErrorLines = malloc( (size_t) ulErrorCount * 4 );
  607.          pulErrorOffsets = malloc( (size_t) ulErrorCount * 4 );
  608.          pulCookies = malloc( (size_t) ulErrorCount * 4 );
  609.  
  610.          pulLineWork = pulErrorLines;
  611.          pulOffWork = pulErrorOffsets;
  612.          pulCookieWork = pulCookies;
  613.          ++pulWorkLines;
  614.  
  615.          /* Store error line information in own variables */
  616.          for( ulIndex=0; ulIndex < ulErrorCount; ulIndex++ )
  617.             {
  618.             *pulLineWork++ = *pulWorkLines;
  619.             *pulOffWork++ = *(pulWorkLines+1);
  620.                         /* ignore length in pulWorkLines+2) */
  621.             *pulCookieWork++ = *(pulWorkLines+3);
  622.             pulWorkLines += 4;
  623.             }
  624.          /* Store help file name */
  625.          strcpy( szLibraryFile, (PSZ)(pulWorkLines+1));
  626.  
  627.          sprintf( szTrace, "LIBRARY: [%s]", szLibraryFile );
  628.          TRACE( hwndTrace, szTrace );
  629.  
  630.          /* Associate help instance */
  631.          memset( &hlpInit, 0, sizeof( hlpInit ));
  632.          hlpInit.pszHelpLibraryName = szLibraryFile;
  633.          if( hwndHelp = WinCreateHelpInstance( hAB, &hlpInit ))
  634.             WinAssociateHelpInstance( hwndHelp, hwndFrame );
  635.  
  636.          /* Enable Error menu items */ 
  637.          WinEnableMenuItem( hwndMenu, IDM_ERROR, ( ulErrorCount > 0L ));
  638.          WinEnableMenuItem( hwndMenu, IDM_NEXT, ( ulErrorLimit > 0L ));
  639.          WinEnableMenuItem( hwndMenu, IDM_PREVIOUS, FALSE );
  640.          WinInvalidateRect( hwnd, NULL, FALSE );
  641.          }
  642.       /* Check for "Goto" message topic */
  643.       else if( !strcmp( DDES_PSZITEMNAME( pDDE ), CV_DDEGOTO ))
  644.          {
  645.          pvWork = (PVOID) DDES_PABDATA( pDDE );
  646.          ulNewCookie = *((PULONG) pvWork+3 );
  647.  
  648.          for( ulIndex = 0; ulIndex < ulErrorCount; ulIndex++ )
  649.             if ( ulNewCookie == pulCookies[ulIndex] )
  650.                {
  651.                if ( ulCurrentCookie != ulNewCookie )
  652.                   {
  653.                   sprintf( szTrace, "Adjust error index (%ld)", ulIndex );
  654.                   TRACE( hwndTrace, szTrace );
  655.                   ulErrorIndex = ulIndex;
  656.  
  657.                   ulCurrentError = *(PULONG) pvWork;
  658.                   ulCurrentOffset = *((PULONG) pvWork+1 );
  659.                   ulCurrentResID = *((PULONG) pvWork+2 );
  660.                   ulCurrentCookie = ulNewCookie;
  661.                   pvWork = (PSZ) pvWork + 20;
  662.                   strcpy( szErrorLine, pvWork );
  663.                   WinInvalidateRect( hwnd, NULL, FALSE );
  664.                   }
  665.                break;
  666.                }
  667.          }
  668.       WinDdePostMsg( hwndDDE, hwnd, WM_DDE_ACK, pDDE, TRUE );
  669.       }
  670.    }
  671.  
  672.  
  673. /* ----------------------------------------------------------------- */
  674. /* ddeInitiate()                                                     */
  675. /* ----------------------------------------------------------------- */
  676.  
  677. VOID ddeInitiate( HWND hwnd, HWND hwndMsg, PDDEINIT pDDEi )
  678.    {
  679.    sprintf( szTrace, "DDE_INITIATE: FROM=%p TO=%p", hwndMsg, hwnd );
  680.    TRACE( hwndTrace, szTrace );
  681.    sprintf( szTrace, "APPNAME: %s", pDDEi->pszAppName ) ;
  682.    TRACE( hwndTrace, szTrace );
  683.    sprintf( szTrace, "TOPIC: %s", pDDEi->pszTopic ) ;
  684.    TRACE( hwndTrace, szTrace );
  685.  
  686.    if ( !fConnected && ( hwndMsg != hwnd )
  687.          && !strcmp( CV_DDEAPPNAME, pDDEi->pszAppName )
  688.          && !strcmp( szTopicName, pDDEi->pszTopic ))
  689.       {
  690.       fConnected = TRUE;
  691.       hwndDDE = hwndMsg;
  692.       WinDdeRespond( hwndDDE, hwnd, CV_DDEAPPNAME, szTopicName, NULL );
  693.       }
  694.    DosFreeMem( pDDEi );   /* REQUIRED msj v4n3 may 89   */
  695.    }
  696.  
  697.  
  698. /* ----------------------------------------------------------------- */
  699. /* pddeMakeRequest()                                                 */
  700. /*                                                                   */
  701. /* Entry:   Format, item name, and fsStatus are valid.               */
  702. /* Exit:    Valid data segment for WM_DDE_DATA message is built.     */
  703. /* Return:  pDDEstruct if successful, otherwise NULL.                */
  704. /*                                                                   */
  705. /* ----------------------------------------------------------------- */
  706.  
  707. PDDESTRUCT pddeMakeRequest( USHORT usFormat, PSZ pszItemName,
  708.    PVOID pvData, USHORT usDataSize )
  709.    {
  710.    PDDESTRUCT pDDE;
  711.    PVOID      pvMemory;
  712.    USHORT     usSegSize;
  713.    USHORT     usTotalSize;
  714.  
  715.    /* Allocate a givable memory segment. */
  716.  
  717.    usSegSize = (USHORT) strlen( pszItemName ) + 1;
  718.    usTotalSize = sizeof( DDESTRUCT ) + usDataSize + usSegSize;
  719.  
  720.    if ( DosAllocSharedMem( &pvMemory, NULL, usTotalSize, fALLOCSHR ))
  721.       {
  722.       WinAlarm( HWND_DESKTOP, WA_ERROR );
  723.       WinAlarm( HWND_DESKTOP, WA_WARNING );
  724.       WinAlarm( HWND_DESKTOP, WA_NOTE );
  725.       return( NULL );
  726.       }
  727.  
  728.    /* Fill in the new DDE structure. */
  729.  
  730.    pDDE = (PDDESTRUCT) pvMemory;
  731.  
  732.    memset( (PVOID) pDDE, 0, (size_t) usSegSize );
  733.    pDDE->usFormat = usFormat;
  734.    pDDE->offszItemName = (USHORT) sizeof( DDESTRUCT );
  735.    memcpy( DDES_PSZITEMNAME( pDDE ), pszItemName, usSegSize );
  736.    pDDE->offabData = (USHORT) sizeof( DDESTRUCT ) + usSegSize;
  737.    memcpy( DDES_PABDATA( pDDE ), pvData, usDataSize );
  738.    pDDE->fsStatus = 0;
  739.    pDDE->cbData = (ULONG) usTotalSize;
  740.  
  741.    return( pDDE );
  742.    }
  743.  
  744.  
  745. /* ----------------------------------------------------------------- */
  746. /* ddeSendGoto() - Send a "SendGoto" message to the WorkFrame/2      */
  747. /*                 program                                           */
  748. /* ----------------------------------------------------------------- */
  749. BOOL ddeSendGoto( HWND hwnd )
  750.    {
  751.    PDDESTRUCT pDDE;
  752.  
  753.  
  754.    pDDE = pddeMakeRequest( DDEFMT_TEXT, CV_SENDGOTO,
  755.       &pulCookies[ ulErrorIndex ], sizeof( PULONG ));
  756.    if ( !pDDE )
  757.       {
  758.       WinAlarm( HWND_DESKTOP, WA_ERROR );
  759.       return( FALSE );
  760.       }
  761.  
  762.    WinDdePostMsg( hwndDDE, hwnd, WM_DDE_DATA, pDDE, TRUE );
  763.    return( TRUE );
  764.    }
  765.  
  766.  
  767. /* ----------------------------------------------------------------- */
  768. /* ddeTerminate()                                                    */
  769. /* ----------------------------------------------------------------- */
  770.  
  771. VOID ddeTerminate( HWND hwnd, HWND hwndMsg )
  772.    {
  773.    TRACE( hwndTrace, "DDE_TERMINATE" );
  774.  
  775.    if ( hwndMsg == hwndDDE )
  776.       {
  777.       WinDdePostMsg( hwndDDE, hwnd, WM_DDE_TERMINATE, NULL, TRUE );
  778.       if( hwndHelp )
  779.          WinDestroyHelpInstance( hwndHelp );
  780.       hwndDDE = NULLHANDLE;
  781.       fConnected = FALSE;
  782.       *szSourceFile = '\0';
  783.       WinPostMsg( hwnd, WM_USER, NULL, NULL );
  784.  
  785.       }
  786.    }
  787.