home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DRGDRO.ZIP / DROPINFO.ZIP / DROPINFO.C next >
Text File  |  1993-03-22  |  10KB  |  230 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  PROGRAM NAME:  DROPINFO                                                  */
  4. /*                                                                           */
  5. /*  PURPOSE:       This program provides information for testing and         */
  6. /*                 debugging drag-and-drop applications.  When an object is  */
  7. /*                 dropped over this program's window, the window shows the  */
  8. /*                 information received from the source.                     */
  9. /*                                                                           */
  10. /*****************************************************************************/
  11.  
  12. #include "dropinfo.h"                            /* Application header file  */
  13.  
  14. /*****************************************************************************/
  15. /* Window procedure prototypes                                               */
  16. /*****************************************************************************/
  17. MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  18. MRESULT EXPENTRY wpSubList( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  19.  
  20. /*****************************************************************************/
  21. /* Function prototypes                                                       */
  22. /*****************************************************************************/
  23. VOID SendDiscardMsg( HWND hwnd, PDRAGITEM pDItem );
  24. VOID ProcessDrop( HWND hwnd, PDRAGINFO pDInfo );
  25. MRESULT ProcessRendercomplete( MPARAM mp1, MPARAM mp2 );
  26.  
  27. /*****************************************************************************/
  28. /* Global data                                                               */
  29. /*****************************************************************************/
  30. HAB  hAB;                                        /* Anchor block handle      */
  31. HWND  hListBox;                                  /* Listbox window handle    */
  32. PFNWP pwpList;                                   /* Listbox winproc address  */
  33.  
  34. /*****************************************************************************/
  35. /* Application main routine                                                  */
  36. /*****************************************************************************/
  37. INT main (VOID)
  38. {
  39.   HMQ  hMsgQ;                                    /* Message queue handle     */
  40.   QMSG qMsg;                                     /* Message structure        */
  41.   HWND hFrame;                                   /* Frame window handle      */
  42.  
  43.   ULONG flCreate = FCF_STANDARD;
  44.  
  45.   ULONG rc;                                      /* Return code              */
  46.  
  47.   hAB = WinInitialize(0);                        /* Register application     */
  48.  
  49.   hMsgQ = WinCreateMsgQueue(hAB, 0);             /* Create message queue     */
  50.  
  51.   rc = WinRegisterClass(hAB,                     /* Register window class    */
  52.                         (PSZ)"MyWindow",         /* Class name               */
  53.                         (PFNWP)MyWindowProc,     /* Window procedure address */
  54.                         CS_SIZEREDRAW,           /* Class style              */
  55.                         sizeof(PVOID));          /* Window words             */
  56.  
  57.   hFrame = WinCreateStdWindow(HWND_DESKTOP,      /* Desktop is parent        */
  58.                               0,                 /* Standard window style    */
  59.                               &flCreate,         /* Frame control flags      */
  60.                               "MyWindow",        /* Window class name        */
  61.                               "DropInfo Sample", /* Window title text        */
  62.                               0,                 /* No special class style   */
  63.                               (HMODULE)0L,       /* Resources in EXE file    */
  64.                               ID_WINDOW,         /* Frame window identifier  */
  65.                               NULL);             /* No pres params           */
  66.  
  67.   while (WinGetMsg(hAB, &qMsg, 0L, 0, 0))        /* Process messages until   */
  68.         WinDispatchMsg(hAB, &qMsg);              /* WM_QUIT received         */
  69.  
  70.   WinDestroyWindow(hFrame);                      /* Destroy window           */
  71.   WinDestroyMsgQueue(hMsgQ);                     /* Destroy message queue    */
  72.   WinTerminate(hAB);                             /* Deregister application   */
  73. }
  74.  
  75. /*****************************************************************************/
  76. /* Main window procedure                                                     */
  77. /*****************************************************************************/
  78. MRESULT EXPENTRY MyWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  79. {
  80.   SWP   swp;
  81.   ULONG rc;
  82.  
  83.   HWND  hFrame;
  84.  
  85.   switch (msg)
  86.   {
  87.   case WM_CREATE:
  88.     hListBox = WinCreateWindow(hwnd, WC_LISTBOX, NULL,
  89.                                WS_VISIBLE | LS_NOADJUSTPOS | LS_HORZSCROLL,
  90.                                0, 0, 0, 0,
  91.                                hwnd, HWND_TOP, ID_LISTBOX, 0, 0);
  92.  
  93.     pwpList = WinSubclassWindow(hListBox,
  94.                  wpSubList);
  95.  
  96.     hFrame = WinQueryWindow(hwnd,
  97.                             QW_PARENT);
  98.     rc = WinSetWindowPos(hFrame, HWND_TOP, 300, 30, 350, 220,
  99.                          SWP_SIZE | SWP_ACTIVATE | SWP_SHOW);
  100.     break;
  101.  
  102.   case WM_SIZE:
  103.     WinQueryWindowPos(hwnd, &swp);
  104.     hListBox=WinWindowFromID(hwnd,
  105.                              ID_LISTBOX);
  106.     WinSetWindowPos(hListBox, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
  107.                     SWP_SIZE | SWP_SHOW);
  108.     break;
  109.  
  110.   case WM_COMMAND:
  111.     if( SHORT1FROMMP(mp2) == CMDSRC_MENU )
  112.     {
  113.       switch( SHORT1FROMMP(mp1) )
  114.       {
  115.       case IDM_RESPONSE:
  116.         /*WinDlgBox(HWND_DESKTOP, hwnd, wpConfDrgDragFiles, NULLHANDLE,
  117.                   IDD_RESPONSE, NULL);*/
  118.         return (MRESULT)TRUE;
  119.     
  120.       case IDM_CLEARLIST:
  121.         WinSendMsg( hListBox, LM_DELETEALL, (MPARAM)0, (MPARAM)0 );
  122.         return((MRESULT)TRUE);
  123.     
  124.       case IDM_EXIT:
  125.         WinPostMsg( hwnd, WM_QUIT, (MPARAM)0, (MPARAM)0 );
  126.         return((MRESULT)TRUE);
  127.       }
  128.     }
  129.   default:
  130.        return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  131.   }
  132.   return ((MRESULT)FALSE);
  133. }
  134.  
  135. /*****************************************************************************/
  136. /* Listbox subclass window procedure                                         */
  137. /*****************************************************************************/
  138. MRESULT EXPENTRY wpSubList(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  139. {
  140.   PDRAGINFO pDInfo;                              /* Pointer to DRAGINFO      */
  141.   PDRAGITEM pDItem;                              /* Pointer to DRAGITEM      */
  142.   ULONG rc;                                      /* Return code              */
  143.   int i;                                         /* Loop counter             */
  144.  
  145.   switch (msg)
  146.   {
  147.   case DM_DRAGOVER:
  148.     pDInfo = (PDRAGINFO)mp1;
  149.     rc = DrgAccessDraginfo(pDInfo);
  150.     pDItem = DrgQueryDragitemPtr(pDInfo, 0);
  151.     return(MPFROM2SHORT(DOR_DROP,      /* Drop Allowed             */
  152.                         DO_UNKNOWN));
  153.  
  154.   case DM_DROP:                           /* Object being dropped     */
  155.     PutMsg(hwnd,"DM_DROP",mp1,mp2);    /* Put message in listbox   */
  156.     pDInfo = (PDRAGINFO)mp1;           /* Extract DRAGINFO pointer */
  157.     rc =DrgAccessDraginfo(pDInfo);     /* Access DRAGINFO data     */
  158.     PutDInfo(hwnd, pDInfo);            /* Put DRAGINFO in listbox  */
  159.  
  160.     pDItem = DrgQueryDragitemPtr(pDInfo, 0); /* Get DRAGITEMs      */
  161.  
  162.     for (i=0; i < pDInfo->cditem; i++) /* For each DRAGITEM        */
  163.     {
  164.       /*SendRenderMsg( pDInfo->hwndSource, pDItem );*/
  165.       PutDItem(hwnd, pDItem++);      /* Put DRAGITEM in listbox  */
  166.     }
  167.     /*ProcessDrop( hwnd, pDInfo );*/
  168.     DrgFreeDraginfo( pDInfo );
  169.     break;
  170.  
  171.   case DM_RENDERCOMPLETE:
  172.     /*PutMsg(hwnd,"DM_RENDERCOMPLETE",mp1,mp2);*/
  173.     return ProcessRendercomplete( mp1, mp2 );
  174.  
  175.   default:                                
  176.     return((MRESULT)pwpList(hwnd, msg, mp1, mp2));
  177.   }
  178.   return (MRESULT)NULL;
  179. }
  180.  
  181. /********************************************/
  182. /* send a fake message to source for test purposes */
  183. /********************************************/
  184. VOID SendRenderMsg( HWND hwndSource, PDRAGITEM pDItem )
  185. {
  186.   PRINTDEST pDest;
  187.  
  188.   WinSendMsg( hwndSource, DM_PRINTOBJECT, pDItem, (MPARAM)&pDest );
  189. }
  190.  
  191. /******************************************************************/
  192. /*  do the DM_RENDER conversation, possibly with DM_RENDERPREPARE */
  193. /******************************************************************/
  194. VOID ProcessDrop( HWND hwnd, PDRAGINFO pDInfo )
  195. {
  196.   PDRAGITEM pDItem;  
  197.   PDRAGTRANSFER pdxfer;
  198.   MRESULT rc;                        
  199.  
  200.   pDItem = DrgQueryDragitemPtr(pDInfo, 0);           
  201.  
  202.   pdxfer = DrgAllocDragtransfer(1);          
  203.   pdxfer->cb = sizeof(DRAGTRANSFER);         
  204.   pdxfer->hwndClient = hwnd;
  205.   pdxfer->pditem = pDItem;
  206.   pdxfer->hstrSelectedRMF =
  207.           DrgAddStrHandle("<DRM_TEST,DRF_TEXT>");
  208.   pdxfer->hstrRenderToName =
  209.           DrgAddStrHandle("TESTEST");
  210.   pdxfer->ulTargetInfo = 0;
  211.   pdxfer->usOperation = DO_COPY;
  212.  
  213.   rc=DrgSendTransferMsg(pDInfo->hwndSource, DM_RENDER, 
  214.                         (MPARAM)pdxfer, NULL);
  215.   /*if( rc == TRUE ) ... */
  216.  
  217.   rc=DrgSendTransferMsg(pDInfo->hwndSource, DM_ENDCONVERSATION,
  218.                         MPFROMLONG(pDItem->ulItemID), 
  219.                         MPFROMSHORT(DMFL_TARGETFAIL));
  220.  
  221.   DrgFreeDragtransfer(pdxfer);  
  222.   return;            
  223. }
  224.  
  225. MRESULT ProcessRendercomplete( MPARAM mp1, MPARAM mp2 )
  226. {
  227.   return (MRESULT)0;
  228. }
  229.  
  230.