home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DRGDRO.ZIP / DRAGINFO.ZIP / DRAGINFO.C < prev    next >
Text File  |  1993-04-06  |  23KB  |  613 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  PROGRAM NAME:  DRAGINFO                                                  */
  4. /*                                                                           */
  5. /*  PURPOSE:       This program provides information for testing and         */
  6. /*                 debugging drag-and-drop applications.  When an object is  */
  7. /*                 dragged from this program's window, the window shows the  */
  8. /*                 messages received from the target.                        */
  9. /*                 Additionally, the Draginfo and Dragitem-structures that   */
  10. /*                 are used to specify the requested operation can be        */
  11. /*                 configured on screen.It is also possible to select the    */
  12. /*                 desired Drag-API (DrgDrag or DrgDragFiles).               */
  13. /*                 This program only simulates the dragging; no explicit     */
  14. /*                 rendering is performed (yet).                             */
  15. /*                                                                           */
  16. /*                 This program was created using code from the DROPINFO     */
  17. /*                 sample program that comes with the Redbook Vol.4 sample   */
  18. /*                 code. Both programs complement eachother.                 */
  19. /*                                                                           */
  20. /*                 As far as I'm concerned you may use this code in whatever */
  21. /*                 way you choose, provided I'm in no way responsible for    */
  22. /*                 the outcome. Good luck.                                   */
  23. /*                                                                           */
  24. /*                 Christian Sell, CIS 100021,3151                   */
  25. /*****************************************************************************/
  26.  
  27. #define INCL_DOSFILEMGR   
  28. #include "draginfo.h"                            /* Application header file  */
  29. #include "pmassert.h"
  30.  
  31. /*****************************************************************************/
  32. /* Window procedure prototypes                                               */
  33. /*****************************************************************************/
  34. MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  35. MRESULT EXPENTRY wpFileList( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  36.  
  37. /*****************************************************************************/
  38. /* Function prototypes                                                       */
  39. /*****************************************************************************/
  40. void PutMsg( USHORT unSrc, ULONG msg, MPARAM mp1, MPARAM mp2);
  41. HWND DoDrgDrag( HWND hwndSrc );
  42. void DoDragFiles( HWND hwnd );
  43.  
  44. /*****************************************************************************/
  45. /* Global data                                                               */
  46. /*****************************************************************************/
  47. HAB  hAB;                       /* Anchor block handle      */
  48. PFNWP pwpFList;                 /* Listbox winproc address  */
  49. HWND  hwndTarget;
  50. HWND  hFileList;                /* Listbox window handle    */
  51. HWND  hMsgList;                 /* Listbox window handle    */
  52. HPOINTER  hptrDrag;             /* Drag Pointer handle */
  53. HEV   hSemThread;               /* Semaphore to signal thread is running */
  54. PDRAGINFO     pDragInfo;
  55. USHORT usItemsDragged;
  56. BOOL   bDragActive;
  57.  
  58.  
  59. /*****************************************************************************/
  60. /* Application main routine                                                  */
  61. /*****************************************************************************/
  62. INT main (VOID)
  63. {
  64.   HMQ  hMsgQ;                                    /* Message queue handle     */
  65.   QMSG qMsg;                                     /* Message structure        */
  66.   HWND hFrame;                                   /* Frame window handle      */
  67.  
  68.   ULONG flCreate = FCF_STANDARD;     /* Frame creation flags     */
  69.  
  70.   ULONG rc;                                      /* Return code              */
  71.  
  72.   hAB = WinInitialize(0);                        /* Register application     */
  73.  
  74.   hMsgQ = WinCreateMsgQueue(hAB, 0);             /* Create message queue     */
  75.  
  76.   rc = WinRegisterClass(hAB,                     /* Register window class    */
  77.                         (PSZ)"MyWindow",         /* Class name               */
  78.                         (PFNWP)MyWindowProc,     /* Window procedure address */
  79.                         CS_SIZEREDRAW,           /* Class style              */
  80.                         sizeof(PVOID));          /* Window words             */
  81.  
  82.   hFrame = WinCreateStdWindow(HWND_DESKTOP,      /* Desktop is parent        */
  83.                               0,                 /* Standard window style    */
  84.                               &flCreate,         /* Frame control flags      */
  85.                               "MyWindow",        /* Window class name        */
  86.                               "DragInfo",        /* Window title text        */
  87.                               0,                 /* No special class style   */
  88.                               (HMODULE)0L,       /* Resources in EXE file    */
  89.                               ID_WINDOW,         /* Frame window identifier  */
  90.                               NULL);             /* No pres params           */
  91.  
  92.   /* we need to insure that the second thread is terminated before the
  93.    * main thread. Create a semaphore to handle that.
  94.    */
  95.   rc = DosCreateEventSem( NULL, &hSemThread, 0L, 0L );
  96.   pmassert( hAB, !rc );
  97.   
  98.   while (WinGetMsg(hAB, &qMsg, 0L, 0, 0))        /* Process messages until   */
  99.         WinDispatchMsg(hAB, &qMsg);              /* WM_QUIT received         */
  100.  
  101.   WinDestroyWindow(hFrame);                      /* Destroy window           */
  102.   WinDestroyMsgQueue(hMsgQ);                     /* Destroy message queue    */
  103.   WinTerminate(hAB);                             /* Deregister application   */
  104.   
  105.   return (0);
  106. }
  107.  
  108. /*****************************************************************************/
  109. /* Main window procedure                                                     */
  110. /*****************************************************************************/
  111. MRESULT EXPENTRY MyWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  112. {
  113.   SWP   swp;
  114.   RECTL Rect;
  115.   ULONG rc;
  116.   LONG  dx;
  117.   HWND  hFrame, hwndMenu;
  118.  
  119.   hFrame = WinQueryWindow(hwnd, QW_PARENT);
  120.   switch (msg)
  121.   {
  122.   case WM_CREATE:
  123.     /* create & subclass 'Files' listbox */
  124.     hFileList = WinCreateWindow(hwnd, WC_LISTBOX, NULL,
  125.                                WS_VISIBLE | LS_NOADJUSTPOS | LS_HORZSCROLL |
  126.                                LS_MULTIPLESEL,
  127.                                0, 0, 0, 0,
  128.                                hwnd, HWND_TOP, ID_LISTBOX, 0, 0);
  129.  
  130.     pwpFList = WinSubclassWindow(hFileList,
  131.                  wpFileList);
  132.  
  133.     /* create & subclass 'Messages' listbox */
  134.     hMsgList = WinCreateWindow(hwnd, WC_LISTBOX, NULL,
  135.                                WS_VISIBLE | LS_NOADJUSTPOS | LS_HORZSCROLL,
  136.                                0, 0, 0, 0,
  137.                                hwnd, HWND_TOP, ID_LISTBOX, 0, 0);
  138.  
  139.  
  140.     /* set window position */
  141.     rc = WinSetWindowPos(hFrame, HWND_TOP, 50, 250, 400, 200,
  142.                          SWP_MOVE | SWP_SIZE | SWP_ACTIVATE | SWP_SHOW);
  143.     hptrDrag = WinLoadPointer( HWND_DESKTOP, NULLHANDLE, ID_DRAGPTR );
  144.  
  145.     WinPostMsg( hFileList, DRI_CREATE_THREAD, 0L, 0L );
  146.     break;
  147.        
  148.   case WM_SIZE:
  149.     WinQueryWindowRect( hwnd, &Rect );
  150.     WinQueryWindowPos(hwnd, &swp);
  151.     dx = swp.cx*2/3;
  152.     WinSetWindowPos(hFileList, HWND_TOP,
  153.                     0, 0, 
  154.                     swp.cx-dx, swp.cy,
  155.                     SWP_SIZE | SWP_SHOW);
  156.     WinSetWindowPos(hMsgList, HWND_TOP,
  157.                     Rect.xLeft+(swp.cx-dx), Rect.yBottom,
  158.                     dx, swp.cy,
  159.                     SWP_MOVE | SWP_SIZE | SWP_SHOW );
  160.     break;
  161.        
  162.   /* just record drag messages sent to client window */
  163.   case DM_DROP:
  164.   case DM_DRAGOVER:
  165.   case DM_DRAGLEAVE:
  166.   case DM_DROPHELP:
  167.   case DM_ENDCONVERSATION:
  168.   case DM_PRINT:
  169.   case DM_RENDER:
  170.   case DM_RENDERCOMPLETE:
  171.   case DM_RENDERPREPARE:
  172.   case DM_DRAGFILECOMPLETE:
  173.   case DM_EMPHASIZETARGET:
  174.   case DM_DRAGERROR:
  175.   case DM_FILERENDERED:
  176.   case DM_RENDERFILE:
  177.   case DM_DRAGOVERNOTIFY:
  178.   case DM_PRINTOBJECT:
  179.   case DM_DISCARDOBJECT:
  180.     PutMsg( 0, msg, mp1, mp2 );
  181.     return (MRESULT)FALSE;
  182.  
  183.   case WM_MENUSELECT:
  184.     switch( SHORT1FROMMP(mp1) )
  185.     {
  186.     case ID_OPTIONS:
  187.       WinCheckMenuItem(HWNDFROMMP(mp2), IDM_DRGDRAG, bDrgDrag);
  188.       WinCheckMenuItem(HWNDFROMMP(mp2), IDM_DRGDRAGFILES, !bDrgDrag);
  189.       return (MRESULT)FALSE;
  190.  
  191.     default:
  192.       return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  193.     }
  194.   case WM_COMMAND:
  195.     if( SHORT1FROMMP(mp2) == CMDSRC_MENU )
  196.     {
  197.       hwndMenu = WinWindowFromID(hFrame, FID_MENU);
  198.       switch( SHORT1FROMMP(mp1) )
  199.       {
  200.       case IDM_CHANGEDIR:
  201.         WinDlgBox(HWND_DESKTOP, hwnd, wpCDDlg, NULLHANDLE, IDD_CDIR, NULL);
  202.         return (MRESULT)FALSE;
  203.  
  204.       case IDM_DRGDRAG:
  205.         bDrgDrag = TRUE;
  206.         WinCheckMenuItem(hwndMenu, IDM_DRGDRAG, bDrgDrag);
  207.         WinCheckMenuItem(hwndMenu, IDM_DRGDRAGFILES, !bDrgDrag);
  208.         return (MRESULT)FALSE;
  209.   
  210.       case IDM_DRGDRAGFILES:
  211.         bDrgDrag = FALSE;
  212.         WinMessageBox(HWND_DESKTOP, hwnd, "Use DrgDragFiles at your own risk!!",
  213.                        "Warning", 0, MB_OK );
  214.         WinCheckMenuItem(hwndMenu, IDM_DRGDRAG, bDrgDrag);
  215.         WinCheckMenuItem(hwndMenu, IDM_DRGDRAGFILES, !bDrgDrag);
  216.         return (MRESULT)FALSE;
  217.   
  218.       case IDM_CONFIGDLG:
  219.         if( bDrgDrag == TRUE )
  220.           WinDlgBox(HWND_DESKTOP, hwnd, wpConfDrgDrag, NULLHANDLE,
  221.                     IDD_CONFIG1, NULL);
  222.         else
  223.           WinDlgBox(HWND_DESKTOP, hwnd, wpConfDrgDragFiles, NULLHANDLE,
  224.                     IDD_CONFIG2, NULL);
  225.         return (MRESULT)TRUE;
  226.     
  227.       case IDM_CLEARLIST:
  228.         WinSendMsg( hMsgList, LM_DELETEALL, (MPARAM)0, (MPARAM)0 );
  229.         return((MRESULT)TRUE);
  230.     
  231.       case IDM_DOSOMETHING:
  232.         if( WinMessageBox(HWND_DESKTOP, hwnd, "OK, so do something else!",
  233.                        "Message", 0, MB_OKCANCEL ) == MBID_OK )
  234.           WinPostMsg( hwnd, WM_QUIT, (MPARAM)0, (MPARAM)0 );
  235.         return((MRESULT)TRUE);
  236.       }
  237.     }
  238.     break;
  239.  
  240.   default:
  241.     return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  242.   }
  243.   return((MRESULT)FALSE);
  244. }
  245.  
  246. /*****************************************************************************/
  247. /* Listbox subclass window procedure                                         */
  248. /*****************************************************************************/
  249. MRESULT EXPENTRY wpFileList(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  250. {
  251.   HWND    hObject;
  252.   BOOL    bOK;
  253.   APIRET  rc;
  254.  
  255.   /* get object object window data from owner's window words */
  256.   hObject = (HWND) WinQueryWindowULong( WinQueryWindow(hwnd, QW_OWNER), 
  257.                                         QWL_USER );
  258.                                       
  259.   switch (msg)
  260.   {
  261.   case DRI_INIT_LIST:
  262.     if( hObject )
  263.       WinPostMsg( hObject, DRI_INIT_LIST, 0L, 0L );
  264.     return (MRESULT)FALSE;
  265.  
  266.   case DRI_CREATE_THREAD:
  267.     if( !_beginthread( ThreadMain, NULL, THREAD_STACK, (PVOID)hwnd ) )
  268.       WinMessageBox(HWND_DESKTOP, hwnd, "error creating thread",
  269.                          "Main", 0, MB_OK|MB_ERROR );
  270.     break;
  271.   case DRI_ERROR_THREAD:
  272.     WinMessageBox(HWND_DESKTOP, hwnd, "error in thread",
  273.                        "Main", 0, MB_OK|MB_ERROR );
  274.     break;
  275.   case DRI_THREAD_OK:
  276.     /* store object window handle in owners window words */
  277.     bOK = WinSetWindowULong( WinQueryWindow(hwnd, QW_OWNER), QWL_USER, 
  278.                              (ULONG) mp1 );                  
  279.     pmassert( hAB, bOK );
  280.     break;
  281.   case WM_DESTROY:
  282.     pmassert( hAB, hObject );
  283.     if( hObject )
  284.     {
  285.       /* tell thread 2 to close and wait until closed */
  286.       WinPostMsg( hObject, DRI_CLOSE, 0L, 0L ); 
  287.       rc = DosWaitEventSem( hSemThread, 3000L );
  288.       pmassert( hAB, !rc );
  289.     }
  290.     break;
  291.   /***********************/
  292.   /*Drag-Initialisierung */
  293.   /***********************/
  294.   case WM_BEGINDRAG:
  295.     if( bDrgDrag == TRUE )
  296.     {
  297.       hwndTarget = DoDrgDrag( hwnd );
  298.       return (MRESULT)(hwndTarget ? TRUE : FALSE);
  299.     }
  300.     else
  301.     {
  302.       DoDragFiles( hwnd );
  303.       return (MRESULT)TRUE;
  304.     }
  305.   /****************************************/
  306.   /* messages to drag source window       */
  307.   /****************************************/
  308.   case DM_DRAGOVERNOTIFY:   /* Objekt über anderem window */
  309.                             /* mp1: Draginfo, mp2: Target indicators */
  310.     /*PutMsg( 1, msg, mp1, mp2 );*/
  311.     return (MRESULT)FALSE;
  312.  
  313.   case DM_RENDER:           /* Render-Anforderung */
  314.     /* mp1: DragTransfer, return: success/error */
  315.     if( !(--usItemsDragged) )
  316.       DrgFreeDraginfo( pDragInfo );
  317.     PutMsg( 1, msg, mp1, mp2 );
  318.     return (MRESULT)FALSE;
  319.  
  320.   case DM_PRINT:           /* old print msg - what parameters?? */
  321.     if( usItemsDragged )
  322.     {
  323.       DrgFreeDraginfo( pDragInfo );
  324.       usItemsDragged = 0;
  325.     }
  326.     PutMsg( 1, msg, mp1, mp2 );
  327.     return (MRESULT)FALSE;
  328.  
  329.   case DM_PRINTOBJECT:      /* Print-Anforderung */
  330.     /* mp1: Draginfo, mp2: PrintDest, returns: action */
  331.     PutMsg( 1, msg, mp1, mp2 );
  332.     if( usDrgReturn == DRR_SOURCE && hObject )
  333.       WinPostMsg( hObject, DRI_PRINT, mp1, mp2 );
  334.     return (MRESULT)usDrgReturn;      
  335.  
  336.   case DM_DISCARDOBJECT:    /* Discard-Anforderung */
  337.     /* mp1: Draginfo, mp2: reserved, returns: action */
  338.     PutMsg( 1, msg, mp1, mp2 );
  339.     if( usDrgReturn == DRR_SOURCE && hObject )
  340.       WinPostMsg( hObject, DRI_DISCARD, mp1, mp2 );
  341.     return (MRESULT)usDrgReturn;  
  342.  
  343.   case DM_ENDCONVERSATION:  /* Ende-Meldung */
  344.     /* mp1: ItemId, mp2: success/fail */ 
  345.     PutMsg( 1, msg, mp1, mp2 );
  346.     return (MRESULT)FALSE;
  347.  
  348.   case DM_RENDERFILE: /* DrgDragFiles Render message */
  349.     PutMsg( 1, msg, mp1, mp2 );
  350.     DrgSendTransferMsg( ((PRENDERFILE)mp1)->hwndDragFiles, DM_FILERENDERED, mp1, 
  351.                         (MPARAM)TRUE );
  352.     return (MRESULT)TRUE;
  353.  
  354.   /*****************************/
  355.   /* messages to target window */
  356.   /*****************************/
  357.   case DM_DRAGOVER:
  358.     /* mp1: Draginfo, mp2: Koordinaten, return: indicator */
  359.     PutMsg( 1, msg, mp1, mp2 );
  360.     return(MPFROM2SHORT(DOR_NEVERDROP, DO_UNKNOWN));
  361.   case DM_EMPHASIZETARGET:
  362.     /* mp1: Koordinaten, mp2: Flag */
  363.   case DM_DRAGLEAVE:
  364.     /* mp1: Draginfo */
  365.   case DM_DROP:
  366.     /* mp1: Draginfo, return: indicator */
  367.  
  368.   case DM_DRAGERROR:        /* messages generated by DrgDragFiles protocol */
  369.   case DM_FILERENDERED:
  370.     /* mp1: Renderfile, mp2: success/fail */
  371.   case DM_DRAGFILECOMPLETE:
  372.     PutMsg( 1, msg, mp1, mp2 );
  373.     return (MRESULT)FALSE;
  374.   } /* endswitch */
  375.  
  376.   return((MRESULT)pwpFList(hwnd, msg, mp1, mp2));
  377. }
  378.  
  379.  
  380. /*************************************************************************/
  381. /* fhis function performs the drag ...                                   */
  382. /*************************************************************************/
  383. HWND DoDrgDrag( HWND hwndSrc )
  384. {
  385.   CHAR          achFile[50];
  386.   DRAGITEM      DItem;
  387.   DRAGIMAGE     DImage;
  388.   HWND          hDrop=NULLHANDLE;
  389.   APIRET        rc;
  390.   SHORT         sRet, asSel[50] = {LIT_NONE};
  391.   USHORT        unCount;
  392.  
  393.   if( usUseSelected )
  394.   {
  395.     WinPostMsg( hObject, DRI_GET_CURDIR, 0L, 0L );
  396.     for( unCount=0, sRet=LIT_FIRST; unCount<49; unCount++ )
  397.     {
  398.       sRet = (USHORT)WinSendMsg( hFileList, LM_QUERYSELECTION,
  399.                                  MPFROMSHORT(sRet), 0L );
  400.       asSel[unCount] = sRet;
  401.       if( sRet == LIT_NONE )
  402.         break;
  403.     }
  404.     if( unCount )
  405.     {
  406.       usItemsDragged = unCount;
  407.       pDragInfo = DrgAllocDraginfo(unCount);  /* Allocate DRAGINFO     */
  408.       pDragInfo->usOperation = usDrgOperation;
  409.     }
  410.     for( unCount=0; asSel[unCount] != LIT_NONE; unCount++ )
  411.     {
  412.       WinQueryLboxItemText( hFileList, asSel[unCount], achFile, 50 );
  413.       DItem.hwndItem            = hwndSrc;         
  414.       DItem.ulItemID            = (ULONG)asSel[unCount];
  415.       DItem.hstrType            = DrgAddStrHandle( szDrgType );
  416.       DItem.hstrRMF             = DrgAddStrHandle( szDrgRMF );
  417.       DItem.hstrContainerName   = DrgAddStrHandle( szSelDir );
  418.       DItem.hstrSourceName      = DrgAddStrHandle( achFile );
  419.       DItem.hstrTargetName      = DrgAddStrHandle( achFile );
  420.       DItem.fsControl           = usDrgControl;
  421.       DItem.cxOffset            = 2;
  422.       DItem.cyOffset            = 2;
  423.       DItem.fsSupportedOps      = DO_COPYABLE|DO_MOVEABLE|DO_LINKABLE;
  424.      
  425.       rc = DrgSetDragitem(pDragInfo, &DItem, sizeof(DItem), unCount);
  426.     }
  427.   }
  428.   else
  429.   {
  430.     usItemsDragged = 1;
  431.     pDragInfo = DrgAllocDraginfo(1);  /* Allocate DRAGINFO     */
  432.     pDragInfo->usOperation = usDrgOperation;
  433.   
  434.     DItem.hwndItem            = hwndSrc;         
  435.     DItem.ulItemID            = (ULONG)55;       /* nothing special */
  436.     DItem.hstrType            = DrgAddStrHandle( szDrgType );
  437.     DItem.hstrRMF             = DrgAddStrHandle( szDrgRMF );
  438.     DItem.hstrContainerName   = DrgAddStrHandle( szPath );
  439.     DItem.hstrSourceName      = DrgAddStrHandle( szSource );
  440.     DItem.hstrTargetName      = DrgAddStrHandle( szTarget );
  441.     DItem.fsControl           = usDrgControl;
  442.     DItem.cxOffset            = 2;
  443.     DItem.cyOffset            = 2;
  444.     DItem.fsSupportedOps      = DO_COPYABLE|DO_MOVEABLE|DO_LINKABLE;
  445.    
  446.     rc = DrgSetDragitem(pDragInfo, &DItem, sizeof(DItem), 0);
  447.   }
  448.  
  449.   DImage.cb = sizeof(DRAGIMAGE); /* Initialize DRAGIMAGE  */
  450.   DImage.cptl = 0;               /* Not a polygon         */
  451.   DImage.hImage = hptrDrag;      /* Icon handle for drag  */
  452.   DImage.fl = DRG_ICON | DRG_TRANSPARENT;
  453.   DImage.cxOffset = 0;           /* No hotspot            */
  454.   DImage.cyOffset = 0;
  455.  
  456.   /*****************************/
  457.   /* now do the drag           */
  458.   /*****************************/
  459.   hDrop = DrgDrag(hwndSrc,          /* Initiate drag         */
  460.              pDragInfo,             /* DRAGINFO structure    */
  461.              &DImage,            /* DRAGIMAGE structure  */
  462.              1,                  /* Only one DRAGIMAGE    */
  463.              VK_ENDDRAG,         /* End of drag indicator */
  464.              NULL);              /* Reserved              */
  465.   if( hDrop )
  466.     bDragActive = TRUE;
  467.  
  468.   return hDrop;
  469. }
  470.  
  471. /**********************************************************/
  472. /*this performs the drag via the DrgDragFiles API         */
  473. /**********************************************************/
  474. void DoDragFiles( HWND hwnd )
  475. {
  476.   CHAR      achFile[CCHMAXPATHCOMP];
  477.   PCHAR     pcName;
  478.   PSZ       apFiles[50];   /* no more than 50 files */
  479.   USHORT    usCount, usLen;
  480.   SHORT     sRet;
  481.  
  482.   if( usUseSelected )
  483.   {
  484.     strcpy( achFile, szSelDir );
  485.     usLen = strlen( achFile );
  486.     pcName = achFile + usLen;
  487.     usLen = sizeof( achFile ) - usLen;
  488.     for( usCount=0, sRet=LIT_FIRST; usCount<50; )
  489.     {
  490.       sRet = (USHORT)WinSendMsg( hFileList, LM_QUERYSELECTION, MPFROMSHORT(sRet), 0L );
  491.       if( sRet != LIT_END )
  492.       {
  493.         WinQueryLboxItemText( hFileList, sRet, pcName, usLen );
  494.         apFiles[usCount] = strdup( achFile );
  495.         usCount++;
  496.       }
  497.       else
  498.         break;
  499.     }
  500.     apFiles[usCount] = NULL;
  501.   }
  502.   else
  503.   {
  504.     usCount = 1;
  505.     apFiles[0] = szFilePath;
  506.   }
  507.  
  508.   if( !DrgDragFiles(hwnd, apFiles, NULL, NULL, usCount,
  509.                    hptrDrag, VK_ENDDRAG, bSourceRender, 0L) )
  510.     PutMsg( 2, (ULONG)"DrgDragFiles failed", NULL, NULL );
  511.   else
  512.     PutMsg( 2, (ULONG)"DrgDragFiles OK", NULL, NULL );
  513.  
  514.   if( usUseSelected )
  515.     for( usCount=0; apFiles[usCount]; usCount++ )
  516.       free( apFiles[usCount] );
  517. }
  518.  
  519.  
  520. /*****************************************************************************/
  521. /* Put message info in listbox item                                          */
  522. /*****************************************************************************/
  523. void PutMsg( USHORT unSrc, ULONG msg, MPARAM mp1, MPARAM mp2)
  524. {
  525.   char   buf[120];                 /* Message buffer */
  526.   char  *pc;
  527.  
  528. #define MAKE_MSG(c)\
  529.   sprintf( buf+strlen(buf), "%s, %p, %p", c, mp1, mp2 )
  530.  
  531.   switch( unSrc )
  532.   {
  533.   case 0:
  534.     strcpy( buf, "msg (client win): " );
  535.     break;
  536.   case 1:
  537.     strcpy( buf, "msg (listbox): " );
  538.     break;
  539.   default:
  540.     strcpy( buf, "general: " );
  541.     strcat( buf, (char *)msg );
  542.   }
  543.  
  544.   switch( msg )
  545.   {
  546.   case DM_DROP:
  547.     MAKE_MSG( "DM_DROP" );
  548.     break;
  549.   case DM_DRAGOVER:
  550.     MAKE_MSG( "DM_DRAGOVER" );
  551.     break;
  552.   case DM_DRAGLEAVE:
  553.     MAKE_MSG( "DM_DRAGLEAVE" );
  554.     break;
  555.   case DM_DROPHELP:
  556.     MAKE_MSG( "DM_DROPHELP" );
  557.     break;
  558.   case DM_ENDCONVERSATION:
  559.     switch((ULONG)mp2)
  560.     {
  561.     case DMFL_TARGETSUCCESSFUL:
  562.       pc = "DMFL_TARGETSUCCESSFUL"; break;
  563.     case DMFL_TARGETFAIL:
  564.       pc = "DMFL_TARGETFAIL"; break;
  565.     default:
  566.       pc = "unknown"; break;
  567.     }
  568.     sprintf( buf+strlen(buf), "DM_ENDCONVERSATION, %lu, %s", (ULONG)mp1,pc);
  569.     break;
  570.   case DM_PRINT:
  571.     MAKE_MSG( "DM_PRINT" );
  572.     break;
  573.   case DM_RENDER:
  574.     MAKE_MSG( "DM_RENDER" );
  575.     break;
  576.   case DM_RENDERCOMPLETE:
  577.     MAKE_MSG( "DM_RENDERCOMPLETE" );
  578.     break;
  579.   case DM_RENDERPREPARE:
  580.     MAKE_MSG( "DM_RENDERPREPARE" );
  581.     break;
  582.   case DM_DRAGFILECOMPLETE:
  583.     MAKE_MSG( "DM_DRAGFILECOMPLETE" );
  584.     break;
  585.   case DM_EMPHASIZETARGET:
  586.     MAKE_MSG( "DM_EMPHASIZETARGET" );
  587.     break;
  588.   case DM_DRAGERROR:
  589.     MAKE_MSG( "DM_DRAGERROR" );
  590.     break;
  591.   case DM_FILERENDERED:
  592.     MAKE_MSG( "DM_FILERENDERED" );
  593.     break;
  594.   case DM_RENDERFILE:
  595.     MAKE_MSG( "DM_RENDERFILE" );
  596.     break;
  597.   case DM_DRAGOVERNOTIFY:
  598.     MAKE_MSG( "DM_DRAGOVERNOTIFY" );
  599.     break;
  600.   case DM_PRINTOBJECT:
  601.     MAKE_MSG( "DM_PRINTOBJECT" );
  602.     break;
  603.   case DM_DISCARDOBJECT:
  604.     MAKE_MSG( "DM_DISCARDOBJECT" );
  605.     break;
  606.   }
  607.   WinSendMsg( hMsgList, LM_INSERTITEM, (MPARAM)LIT_END, MPFROMP(buf));
  608.  
  609.   return;
  610. }
  611.  
  612.  
  613.