home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / DROP.PRG < prev    next >
Text File  |  1994-05-23  |  8KB  |  291 lines

  1. ////////////////////////////
  2. //
  3. //      Clip-4-Win drop file demo 
  4. //
  5. //      Copyright (C) 1992 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
  6. //      All Rights Reserved.
  7. //
  8. //
  9. //      Make : rmake drop
  10. //     
  11. //
  12. ////////////////////////////
  13.  
  14.  
  15. #define WIN_WANT_ALL
  16. #include "windows.ch"
  17.  
  18. #include "drop.ch "
  19.  
  20. #define R_LEFT   1  //dimensions of rectangle
  21. #define R_TOP    2
  22. #define R_RIGHT  3
  23. #define R_BOTTOM 4
  24. #define FILE_NAME_LENGTH 60
  25.  
  26. static  cAppName := "Clip-4-Win"
  27. static  hWnd, hInst, hPrevInst, nCmdShow
  28. static  cText := ""
  29. static  aWnd := {}, aAction := {}       // for event handlers
  30.  
  31. function main()
  32. local   hMenu, nEvent
  33.  
  34. hWnd = WinSetup(cAppName, "Clip-4-Win drop file demo")
  35. hInst = _GetInstance()
  36. hMenu = MenuSetup()
  37. HideCaret(hWnd)
  38. AddHandler(hWnd, {|nEvent| MainEvent(nEvent)})
  39.  
  40. do while .t.
  41.         do while (nEvent := ChkEvent()) == EVENT_NONE
  42.                 // some "background" processing could go here
  43.         enddo
  44.         HandleEvent(nEvent)
  45.         do case
  46.         case nEvent == EVENT_QUIT
  47.                 DoExit()
  48.         endcase
  49. enddo
  50.  
  51. return 0
  52.  
  53.  
  54. procedure MainEvent(nEvent)
  55. local   hOldWnd
  56. do case
  57. case nEvent == EVENT_REDRAW
  58.     hOldWnd = SelectWindow(hWnd)
  59.     @ 10, 10 say "(This window intentionally left blank.)"
  60.     SelectWindow(hOldWnd)
  61. endcase
  62. return
  63.  
  64.  
  65. procedure DoExit()
  66. MessageBox(0, "Thanks for running this Clip-4-Win demo", "Clip-4-Win Demo Exiting", MB_OK)
  67. quit
  68. return
  69.  
  70.  
  71.  
  72.  
  73. procedure PaintWindow (hWnd, nColor)
  74.          
  75.  
  76.          local hBrush
  77.          local hDC
  78.          local aRect
  79.  
  80.          hDC = GetDC (hWnd)
  81.          aRect = GetClientRect (hWnd)
  82.          hBrush = CreateSolidBrush (nColor )
  83.          hBrush = SelectObject (hDC, hBrush)
  84.  
  85.          Rectangle (hDC, aRect[R_LEFT], aRect[R_TOP], aRect[R_RIGHT], aRect[R_BOTTOM])
  86.  
  87.          DeleteObject (SelectObject (hDC, hBrush))
  88.          ReleaseDC (hWnd, hDC)
  89. return
  90.  
  91.  
  92. procedure PaintTheBlock (hCtrl, nColor)
  93.  
  94.          InvalidateRect (hCtrl)
  95.          UpdateWindow (hCtrl)
  96.          PaintWindow (hCtrl, nColor)
  97. return
  98.  
  99.  
  100.  
  101. function DialogHandler(hDlg,  nMsg, nwParam, nlParam)
  102.    static   hCtrlBlk1, hCtrlBlk2
  103.    local    hFilesInfo
  104.    local    cFileName := ""
  105.    local    cBuf:=" "
  106.    static  arZone1, arZone2, arDlg  //arrays for bounding rectangles
  107.                                     // of zones and dialog window
  108.    local  aPointDrop := {0, 0}      //array that will contain coordinates
  109.                                    //of point where the file(s) were dropped
  110.    local nFilesDropped, nIndex
  111.  
  112.  
  113.  
  114. do case
  115. case nMsg == WM_INITDIALOG
  116.       hCtrlBlk1 = GetDlgItem (hDlg, IDD_ZONE1)
  117.       hCtrlBlk2 = GetDlgItem (hDlg, IDD_ZONE2)
  118.       SetFocus(GetDlgItem(hDlg, IDOK))
  119.       //enable WM_DROPFILES posting
  120.       DragAcceptFiles(hDlg, .T.)
  121.       arZone1 = GetWindowRect(hCtrlBlk1)
  122.       arZone2 = GetWindowRect(hCtrlBlk2)
  123.       arDlg  = GetWindowRect(hDlg)
  124.  
  125.      return 1                        // want system to set the focus
  126.  
  127. case nMsg == WM_SYSCOMMAND
  128.         if nwParam == SC_CLOSE          // system menu double click, or Alt-F4
  129.                 EndDialog(hDlg, .T.)
  130.           endif
  131.  
  132. case nMsg == WM_COMMAND
  133.         do case
  134.         case nwParam == IDOK
  135.          EndDialog( hDlg, .T.) 
  136.          return 1                // means msg has been processed
  137.         endcase
  138.  
  139.  
  140.             case nMsg == WM_PAINT
  141.                      PaintTheBlock (hCtrlBlk1, RGB(255,0,0))
  142.                      PaintTheBlock (hCtrlBlk2, RGB(0,0,255))
  143.  
  144.  
  145.             case nMsg == WM_DROPFILES
  146.  
  147.  
  148.             hFilesInfo = nwParam
  149.  
  150.             // Retrieve the window coordinates of the mouse
  151.             // pointer when the drop was made
  152.             DragQueryPoint ( nwParam,  @aPointDrop)
  153.  
  154.             // Get the total number of files dropped
  155.             nFilesDropped = DragQueryFile (hFilesInfo;
  156.                                           , -1 ;
  157.                                           , 0  ;
  158.                                           , 0)
  159.              
  160.             // Retrieve each file name and add to the buffer string
  161.             for nIndex = 0 to nFilesDropped-1
  162.  
  163.                 DragQueryFile (hFilesInfo;
  164.                                ,nIndex;
  165.                                ,@cFileName;
  166.                                ,FILE_NAME_LENGTH)
  167.  
  168.               cBuf += cFileName + "  "
  169.             next
  170.  
  171.             DragFinish (hFilesInfo)
  172.  
  173.             aPointDrop[1] += arDlg[1]
  174.             aPointDrop[2] += arDlg[2]
  175.             if ((aPointDrop[1] >= arZone1[R_LEFT]) .AND. (aPointDrop[1] <= arZone1[R_RIGHT]);
  176.                .AND. (aPointDrop[2] >= arZone1[R_TOP]) .AND. (aPointDrop[2] <=arZone1[R_BOTTOM]))
  177.                cBuf += "were dropped in ZONE1  "
  178.  
  179.             elseif ((aPointDrop[1] >= arZone2[R_LEFT]) .AND. (aPointDrop[1] <= arZone2[R_RIGHT]);
  180.                .AND. (aPointDrop[2] >= arZone2[R_TOP]) .AND. (aPointDrop[2] <=arZone2[R_BOTTOM]))
  181.                cBuf += "were dropped in ZONE2  "
  182.  
  183.             else
  184.               cBuf+= "were dropped outside of zones "
  185.             endif
  186.  
  187.             MessageBox(hDlg, cBuf, str(nFilesDropped) + " file(s):" , MB_OK);
  188.  
  189.             return 1
  190. endcase
  191. return 0        // means msg not processed (and want default action)
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. procedure DoDrop()
  199.  
  200. DialogBox( , "DropBox", ,                               ;
  201.               {|hDlg, msg, wparam, lparam|              ;
  202.                DialogHandler(hDlg, msg, wparam, lparam)})
  203.  
  204. return
  205.  
  206.  
  207.  
  208. function MenuSetup()
  209. local   hWnd := SelectWindow(), hMenu, hPopupMenu
  210.  
  211. if (hMenu := GetMenu(hWnd)) != nil
  212.     DestroyMenu(hMenu)
  213. endif
  214.  
  215. // do new one (forget old value)
  216. hMenu = CreateMenu()
  217. hPopupMenu = CreatePopupMenu()
  218. AppendMenu(hMenu, "file", MF_ENABLED + MF_POPUP, "&File", hPopupMenu)
  219. AppendMenu(hPopupMenu, "invoked", MF_ENABLED + MF_STRING, "Invoke &drop ...", {|| DoDrop()})
  220. AppendMenu(hPopupMenu, "", MF_SEPARATOR)
  221. AppendMenu(hPopupMenu, "exit", MF_ENABLED + MF_STRING, "E&xit", {|| DoExit()})
  222. SetMenu(hWnd, hMenu)
  223.  
  224. return hMenu
  225.  
  226.  
  227. function AddHandler(hWnd, bAction)  // --> nId  (for use with DelHandler)
  228. aadd(aWnd, hWnd)
  229. aadd(aAction, bAction)
  230. return len(aWnd)
  231.  
  232.  
  233. procedure DelHandler(nId)
  234. adel(aWnd, nId)
  235. asize(aWnd, len(aWnd) - 1)
  236. adel(aAction, nId)
  237. asize(aAction, len(aAction) - 1)
  238. return
  239.  
  240.  
  241. procedure HandleEvent(nEvent)
  242. local   hWnd := _LasthWnd(), i := 0
  243. do while (i := ascan(aWnd, hWnd, ++i)) != 0
  244.     eval(aAction[i], nEvent)
  245. enddo
  246. if nEvent == EVENT_DESTROY
  247.     // clean up, so the event handler needn't bother
  248.     do while (i := ascan(aWnd, hWnd)) != 0
  249.         DelHandler(i)
  250.     enddo
  251. endif
  252. return
  253.  
  254.  
  255. function WinNew(cAppName, cTitle, nX, nY, nWidth, nHeight)
  256. local   hWin, hInst, nCmdShow
  257.  
  258. hInst = _GetInstance()
  259. nCmdShow = _GetnCmdShow()
  260.  
  261. hWin = CreateWindow(cAppName,       ;   // window class
  262.             cTitle,         ;   // caption for title bar
  263.             WS_OVERLAPPEDWINDOW,;   // window style
  264.             nX,         ;   // x co-ordinate
  265.             nY,         ;   // y co-ordinate
  266.             nWidth,     ;   // width
  267.             nHeight,        ;   // height
  268.             hWnd,       ;   // hWnd of parent
  269.             0,          ;   // hMenu of menu (none yet)
  270.             hInst)          // our own app instance
  271.  
  272. if hWin == 0
  273.     // probably out of resources
  274.     MessageBox( , "Can't create window", "Error", MB_OK)
  275.     return nil
  276. endif
  277.  
  278. HideCaret(hWin)
  279.  
  280. // make sure it's displayed ...
  281. ShowWindow(hWin, nCmdShow)
  282.  
  283. // ... and up to date
  284. UpdateWindow(hWin)
  285.  
  286. return hWin
  287.  
  288.  
  289.  
  290.  
  291.