DrgSendTransferMsg - Example Code

This function is used to send a message from one window to another when a direct manipulation is in progress. In this example, the function is used to inform the target that the operation is complete and successful.

#define INCL_WINSTDDRAG  /* Direct Manipulation (Drag) Functions */
#include <os2.h>

PDRAGINFO pdinfo;
MPARAM    mp1;
TID       tid;

case DM_DROP:
  pdinfo = (PDRAGINFO) mp1;

  /***************************************************************/
  /* If this is a copy operation, spawn a thread to do the copy  */
  /***************************************************************/
  if (pdinfo->usOperation == DO_COPY)
  {
    DosCreateThread (&tid, CopyThread, pdinfo, FALSE, 4096);
  }
  break;

void Copy Thread (PDRAGINFO pdinfo)
{
  PDRAGITEM pditem;
  USHORT    i;
  ULONG     flResult;
  HAB       hab;
  HMQ       hmq;
  char      szSource[CCH_MAXPATH];
  char      szTarget[CCH_MACPATH];

  /***************************************************************/
  /* DrgSendTransferMsg needs a message queue, so create one for */
  /* this thread                                                 */
  /***************************************************************/
  hab = WinInitialize (0);
  hmq = WinCreateMsgQueue (hab, 0);

  /***************************************************************/
  /* Try to copy each item that was dragged                      */
  /***************************************************************/
  for (i = 0; i < pdinfo->cditem; i++)
  {
    /*************************************************************/
    /* Get a pointer to the DRAGITEM                             */
    /*************************************************************/
    pditem = DrgQueryDragitemPtr (pdinfo, i);

    /*************************************************************/
    /* If we could query the source and target names, and the    */
    /* copy was successful, return success                       */
    /*************************************************************/
    if (DrgQueryStrName (pditem->hstrSourceName, sizeof (szSource),
                         szSource)
        DrgQueryStrName (pditem->hstrTargetName, sizeof (szTarget),
                         szTarget)
        !DosCopy (szSource, szTarget, 0))
    {
      flResult = DMFL_TARGETSUCCESSFUL;
    }

    /*************************************************************/
    /* Otherwise, return failure                                 */
    /*************************************************************/
    else
    {
      flResult = DMFL_TARGETFAIL;
    }

    /*************************************************************/
    /* Let the source know we're done with this item             */
    /*************************************************************/
    DrgSendTransferMsg (pditem->hwndItem, DM_ENDCONVERSATION,
                        (MPARAM) pditem->ulItemID,
                        (MPARAM) flResult);
  }

  WinDestroyMsgQueue (hmq);
  WinTerminate (hab);
}


[Back: DrgSendTransferMsg - Related Functions]
[Next: DrgSendTransferMsg - Topics]