This example uses the DrgDrag function to drag a single object in response to the direct-manipulation button being pressed while the pointer is over a drag object. The example shows the initialization of the DRAGITEM, DRAGINFO, and DRAGIMAGE structures used by the DrgDrag function.
#define INCL_WINSTDDRAG /* Direct Manipulation (Drag) Functions */ #define INCL_WININPUT /* Window Input Functions */ #include <os2.h> PDRAGINFO pdinfo; /* Pointer to DRAGINFO structure */ HWND hwnd; /* Handle of calling (source) window */ BOOL flResult; /* Result indicator */ DRAGITEM ditem; /* DRAGITEM structure */ DRAGIMAGE dimg; /* DRAGIMAGE structure */ HBITMAP hbm; /* Bit-map handle */ HWND hwndDrop; /* Handle of drop (target) window */ case WM_BEGINDRAG: /*************************************************************/ /* Initialize the DRAGITEM structure */ /*************************************************************/ ditem.hwndItem = hwnd; /* Conversation partner */ ditem.ulItemID = ID_ITEM; /* Identifies item being dragged*/ ditem.hstrType = DrgAddStrHandle(DRT_TEXT); /* Text item */ ditem.hstrRMF = DrgAddStrHandle("<DRM_OS2FILE,DRF_TEXT>"); ditem.hstrContainerName = DrgAddStrHandle("C:\\"); ditem.hstrSourceName = DrgAddStrHandle("C:\\CONFIG.SYS"); ditem.hstrTargetName = DrgAddStrHandle("C:\\OS2\\CONFIG.SYS"); ditem.cxOffset = 0; /* X-offset of the origin of */ /* the image from the pointer */ /* hotspot */ ditem.cyOffset = 0; /* Y-offset of the origin of */ /* the image from the pointer */ /* hotspot */ ditem.fsControl = 0; /* Source item control flags */ /* object is open */ ditem.fsSupportedOps = 0; /*************************************************************/ /* Create the DRAGINFO structure */ /*************************************************************/ pdinfo = DrgAllocDraginfo(1); if (!pdinfo) return (FALSE); /* If allocation fails, */ /* return FALSE */ /*************************************************************/ /* Initialize the DRAGIMAGE structure */ /*************************************************************/ dimg.cb = sizeof(DRAGIMAGE); /* Size control block */ dimg.cptl = 0; dimg.hImage = hbm; /* Image handle passed to */ /* DrgDrag */ dimg.sizlStretch.cx = 20L; /* Size to stretch ico or bmp to*/ dimg.sizlStretch.cy = 20L; dimg.fl = DRG_BITMAP | /* Flags passed to DrgDrag */ DRG_STRETCH; /* Stretch to size specified */ /* in sizlStretch */ dimg.cxOffset = 0; /* Offset of the origin of */ dimg.cyOffset = 0; /* the image from the pointer */ /* hotspot */ /*************************************************************/ /* Set the drag item */ /*************************************************************/ flResult= DrgSetDragitem(pdinfo, &ditem, (ULONG)sizeof(ditem), 0); /*************************************************************/ /* Perform the drag operation: */ /* - Give the user a visual cue by changing the pointer to a */ /* bit map */ /* - Send DM_DRAGOVER messages to the target window (in this */ /* case it is also the source) */ /* NOTE: DrgDrag will fail if another window in the same */ /* thread already has the capture. */ /*************************************************************/ hwndDrop = DrgDrag(hwnd, /* Source of the drag */ pdinfo, /* Pointer to DRAGINFO structure */ (PDRAGIMAGE)&dimg, /* Drag image */ 1, /* Size of the pdimg array */ VK_ENDDRAG, /* Release of direct-manipulation */ /* button ends the drag */ NULL); /* Reserved */