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

  1. /**************************************************************
  2. * This code creates an object window that will perform all 
  3. * processing in response to a drag operations on thread one
  4. **************************************************************/
  5. #define INCL_DEV
  6. #include "draginfo.h"
  7. #include "pmassert.h"
  8.  
  9. CHAR *szObjectClass = "DRI_OBJWIN";
  10.  
  11. typedef struct{
  12.   USHORT  unSz;
  13.   HWND    hwnd;
  14. } CREAT_PARM, *PCREAT_PARM;
  15.  
  16. #define MAKE_CREAT_PARM( pc, hw )\
  17.    (pc) = (PCREAT_PARM)malloc( sizeof(CREAT_PARM) );\
  18.     if( pc ) { (pc)->unSz = sizeof(CREAT_PARM); (pc)->hwnd = (hw); }
  19.  
  20.  
  21. MRESULT EXPENTRY ObjectWinProc( HWND, ULONG, MPARAM, MPARAM );
  22. MRESULT PrintObjects( PDRAGITEM, PPRINTDEST );
  23. VOID DiscardObjects( PDRAGINFO pDragInfo );
  24. VOID InitFileList( void );
  25.  
  26. static HAB hab;
  27. HWND       hObject;
  28.  
  29. /*************************************************************
  30. * create object window
  31. **************************************************************/
  32. VOID _Optlink ThreadMain( PVOID pvHwnd )
  33. {
  34.   BOOL       bOK;
  35.   HMQ        hmq;
  36.   QMSG       qmsg;
  37.   PCREAT_PARM  pCParm;
  38.  
  39.   hab = WinInitialize( 0 );
  40.   pmassert( hab, hab );
  41.   hmq = WinCreateMsgQueue( hab, 0 );
  42.   pmassert( hab, hmq );
  43.   
  44.   bOK = WinRegisterClass( hab, szObjectClass, ObjectWinProc, 
  45.                           0L, sizeof( PCREAT_PARM ) );
  46.   pmassert( hab, bOK );
  47.  
  48.   MAKE_CREAT_PARM( pCParm, (HWND)pvHwnd );
  49.   pmassert( hab, pCParm );
  50.   
  51.   hObject = WinCreateWindow( HWND_OBJECT, szObjectClass, "",
  52.                              0L, 0L, 0L, 0L, 0L, HWND_OBJECT,
  53.                              HWND_BOTTOM, 0L, pCParm, NULL);
  54.   pmassert( hab, hObject );
  55.  
  56.   while( WinGetMsg ( hab, &qmsg, (HWND)NULLHANDLE, 0L, 0L ))
  57.      WinDispatchMsg ( hab, &qmsg );
  58.  
  59.   /* clean up */
  60.   free( pCParm );
  61.   bOK = WinDestroyWindow( hObject );
  62.   bOK = WinDestroyMsgQueue( hmq );
  63.   bOK = WinTerminate( hab );
  64.   
  65.   /* tell thread one we're done */
  66.   DosPostEventSem( hSemThread );    
  67. }  /*  threadmain  */
  68.  
  69.  
  70. /************************************************/
  71. /*this is the window proc for the object window */
  72. /************************************************/
  73. MRESULT EXPENTRY 
  74. ObjectWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  75. {
  76.   switch( msg )
  77.   {
  78.   case WM_CREATE:
  79.     {
  80.     /* post an acknowledgement and pass object handle */
  81.     HWND hMain = ((PCREAT_PARM)PVOIDFROMMP(mp1))->hwnd;
  82.     WinPostMsg( hMain, DRI_THREAD_OK, MPFROMHWND(hwnd), 0L );
  83.     /* fall through */
  84.     }
  85.   case DRI_INIT_LIST:
  86.     InitFileList();
  87.     WinPostMsg( hwnd, DRI_GET_CURDIR, 0L, 0L );
  88.     return (MRESULT)FALSE;
  89.  
  90.   case DRI_GET_CURDIR:
  91.     {
  92.     ULONG ulDrv, ulTmp;
  93.     PCHAR pc;
  94.     DosQueryCurrentDisk( &ulDrv, &ulTmp );
  95.     szSelDir[0] = (CHAR)64+(CHAR)ulDrv;
  96.     DosQueryCurrentDir( ulDrv, szSelDir+3, &ulTmp );
  97.     pc = szSelDir + strlen( szSelDir ) - 1;
  98.     if( *pc != '\\' ) strcat( szSelDir, "\\" );
  99.     break;
  100.     }
  101.     return (MRESULT)FALSE;
  102.  
  103.   case DRI_CLOSE:
  104.     /* post quit msg to queue */
  105.     WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
  106.     break;
  107.  
  108.   case DRI_PRINT:
  109.     /* perform print operation */
  110.     PrintObjects( (PDRAGITEM)mp1, (PPRINTDEST)mp2 );
  111.     break;
  112.  
  113.   case DRI_DISCARD:
  114.     if( usItemsDragged )
  115.       DiscardObjects( (PDRAGINFO)mp1 );
  116.     break;
  117.  
  118.   default:
  119.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  120.   }
  121.  
  122.   return (MRESULT)NULL;
  123. }
  124.  
  125.  
  126. /*****************************************************************/
  127. /*this does the printing in response to a DRI_PRINT message */
  128. /*****************************************************************/
  129. MRESULT PrintObjects( PDRAGITEM pDragItem, PPRINTDEST ppd )
  130. {
  131.   CHAR    szFullFileName[ CCHMAXPATH + 1 ];
  132.   PSZ     pszFileName;
  133.   INT     cbFileName = sizeof( szFullFileName );
  134.   CHAR    achMsg[120];
  135.  
  136.   DrgQueryStrName( pDragItem->hstrContainerName,
  137.                    cbFileName, szFullFileName );
  138.  
  139.   pszFileName = szFullFileName + strlen( szFullFileName );
  140.  
  141.   if( *szFullFileName && *(pszFileName - 1) != '\\' )
  142.   {
  143.     strcpy(pszFileName, "\\");
  144.     pszFileName++;
  145.   }
  146.  
  147.   DrgQueryStrName( pDragItem->hstrTargetName,
  148.                    cbFileName - (pszFileName - szFullFileName),
  149.                    pszFileName );
  150.  
  151.   sprintf( achMsg, "File %s would be printed on %s ", szFullFileName,
  152.            ppd->pszPrinter );
  153.   WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, achMsg,
  154.                   "Printing", 0, MB_OK );
  155.  
  156.   if( !(--usItemsDragged) )
  157.     DrgFreeDragInfo( pDragInfo );
  158.  
  159.   return (MRESULT) DRR_SOURCE;
  160. }
  161.  
  162.  
  163. /***************************************************/
  164. /* this function handles DM_DISCARDOBJECT requests */
  165. /***************************************************/
  166. VOID DiscardObjects( PDRAGINFO pDInfo )
  167. {
  168.   DISCARD_PARAM param;
  169.   
  170.   param.sz = sizeof(DISCARD_PARAM);
  171.   param.pd = pDInfo;
  172.   
  173.   /* DM_DISCARDOBJECT always sends a full DragInfo, so we can
  174.    * cancel the operation after this one.
  175.    */
  176.   usItemsDragged = 0;
  177.   WinDlgBox( HWND_DESKTOP, HWND_DESKTOP, delLboxProc, NULLHANDLE,
  178.              IDD_DISCARD, ¶m );
  179.              
  180.   DrgFreeDraginfo( pDInfo );
  181.  
  182.   return;
  183. }
  184.  
  185.  
  186. /**********************************/
  187. /* fill 'Files' listbox with data */
  188. /**********************************/
  189. VOID InitFileList( void )
  190. {
  191.   HDIR          hDir = HDIR_SYSTEM;
  192.   FILEFINDBUF3  FindBuffer;
  193.   ULONG         ulCount=1;
  194.   APIRET        rc;         /* Return code */
  195.   
  196.   rc = DosFindFirst( "*.*", &hDir, 0, (PVOID) &FindBuffer,
  197.                     sizeof(FindBuffer), &ulCount, FIL_STANDARD);
  198.  
  199.   WinSendMsg( hFileList, LM_DELETEALL, (MPARAM)0, (MPARAM)0 );
  200.   while( !rc )
  201.   {
  202.     WinSendMsg( hFileList, LM_INSERTITEM, (MPARAM)LIT_END,
  203.                 MPFROMP(FindBuffer.achName));
  204.     rc = DosFindNext( hDir, &FindBuffer, sizeof(FindBuffer), &ulCount );
  205.   }
  206.   return;
  207. }
  208.