home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
DROP.PRG
< prev
next >
Wrap
Text File
|
1994-05-23
|
8KB
|
291 lines
////////////////////////////
//
// Clip-4-Win drop file demo
//
// Copyright (C) 1992 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
//
// Make : rmake drop
//
//
////////////////////////////
#define WIN_WANT_ALL
#include "windows.ch"
#include "drop.ch "
#define R_LEFT 1 //dimensions of rectangle
#define R_TOP 2
#define R_RIGHT 3
#define R_BOTTOM 4
#define FILE_NAME_LENGTH 60
static cAppName := "Clip-4-Win"
static hWnd, hInst, hPrevInst, nCmdShow
static cText := ""
static aWnd := {}, aAction := {} // for event handlers
function main()
local hMenu, nEvent
hWnd = WinSetup(cAppName, "Clip-4-Win drop file demo")
hInst = _GetInstance()
hMenu = MenuSetup()
HideCaret(hWnd)
AddHandler(hWnd, {|nEvent| MainEvent(nEvent)})
do while .t.
do while (nEvent := ChkEvent()) == EVENT_NONE
// some "background" processing could go here
enddo
HandleEvent(nEvent)
do case
case nEvent == EVENT_QUIT
DoExit()
endcase
enddo
return 0
procedure MainEvent(nEvent)
local hOldWnd
do case
case nEvent == EVENT_REDRAW
hOldWnd = SelectWindow(hWnd)
@ 10, 10 say "(This window intentionally left blank.)"
SelectWindow(hOldWnd)
endcase
return
procedure DoExit()
MessageBox(0, "Thanks for running this Clip-4-Win demo", "Clip-4-Win Demo Exiting", MB_OK)
quit
return
procedure PaintWindow (hWnd, nColor)
local hBrush
local hDC
local aRect
hDC = GetDC (hWnd)
aRect = GetClientRect (hWnd)
hBrush = CreateSolidBrush (nColor )
hBrush = SelectObject (hDC, hBrush)
Rectangle (hDC, aRect[R_LEFT], aRect[R_TOP], aRect[R_RIGHT], aRect[R_BOTTOM])
DeleteObject (SelectObject (hDC, hBrush))
ReleaseDC (hWnd, hDC)
return
procedure PaintTheBlock (hCtrl, nColor)
InvalidateRect (hCtrl)
UpdateWindow (hCtrl)
PaintWindow (hCtrl, nColor)
return
function DialogHandler(hDlg, nMsg, nwParam, nlParam)
static hCtrlBlk1, hCtrlBlk2
local hFilesInfo
local cFileName := ""
local cBuf:=" "
static arZone1, arZone2, arDlg //arrays for bounding rectangles
// of zones and dialog window
local aPointDrop := {0, 0} //array that will contain coordinates
//of point where the file(s) were dropped
local nFilesDropped, nIndex
do case
case nMsg == WM_INITDIALOG
hCtrlBlk1 = GetDlgItem (hDlg, IDD_ZONE1)
hCtrlBlk2 = GetDlgItem (hDlg, IDD_ZONE2)
SetFocus(GetDlgItem(hDlg, IDOK))
//enable WM_DROPFILES posting
DragAcceptFiles(hDlg, .T.)
arZone1 = GetWindowRect(hCtrlBlk1)
arZone2 = GetWindowRect(hCtrlBlk2)
arDlg = GetWindowRect(hDlg)
return 1 // want system to set the focus
case nMsg == WM_SYSCOMMAND
if nwParam == SC_CLOSE // system menu double click, or Alt-F4
EndDialog(hDlg, .T.)
endif
case nMsg == WM_COMMAND
do case
case nwParam == IDOK
EndDialog( hDlg, .T.)
return 1 // means msg has been processed
endcase
case nMsg == WM_PAINT
PaintTheBlock (hCtrlBlk1, RGB(255,0,0))
PaintTheBlock (hCtrlBlk2, RGB(0,0,255))
case nMsg == WM_DROPFILES
hFilesInfo = nwParam
// Retrieve the window coordinates of the mouse
// pointer when the drop was made
DragQueryPoint ( nwParam, @aPointDrop)
// Get the total number of files dropped
nFilesDropped = DragQueryFile (hFilesInfo;
, -1 ;
, 0 ;
, 0)
// Retrieve each file name and add to the buffer string
for nIndex = 0 to nFilesDropped-1
DragQueryFile (hFilesInfo;
,nIndex;
,@cFileName;
,FILE_NAME_LENGTH)
cBuf += cFileName + " "
next
DragFinish (hFilesInfo)
aPointDrop[1] += arDlg[1]
aPointDrop[2] += arDlg[2]
if ((aPointDrop[1] >= arZone1[R_LEFT]) .AND. (aPointDrop[1] <= arZone1[R_RIGHT]);
.AND. (aPointDrop[2] >= arZone1[R_TOP]) .AND. (aPointDrop[2] <=arZone1[R_BOTTOM]))
cBuf += "were dropped in ZONE1 "
elseif ((aPointDrop[1] >= arZone2[R_LEFT]) .AND. (aPointDrop[1] <= arZone2[R_RIGHT]);
.AND. (aPointDrop[2] >= arZone2[R_TOP]) .AND. (aPointDrop[2] <=arZone2[R_BOTTOM]))
cBuf += "were dropped in ZONE2 "
else
cBuf+= "were dropped outside of zones "
endif
MessageBox(hDlg, cBuf, str(nFilesDropped) + " file(s):" , MB_OK);
return 1
endcase
return 0 // means msg not processed (and want default action)
procedure DoDrop()
DialogBox( , "DropBox", , ;
{|hDlg, msg, wparam, lparam| ;
DialogHandler(hDlg, msg, wparam, lparam)})
return
function MenuSetup()
local hWnd := SelectWindow(), hMenu, hPopupMenu
if (hMenu := GetMenu(hWnd)) != nil
DestroyMenu(hMenu)
endif
// do new one (forget old value)
hMenu = CreateMenu()
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "file", MF_ENABLED + MF_POPUP, "&File", hPopupMenu)
AppendMenu(hPopupMenu, "invoked", MF_ENABLED + MF_STRING, "Invoke &drop ...", {|| DoDrop()})
AppendMenu(hPopupMenu, "", MF_SEPARATOR)
AppendMenu(hPopupMenu, "exit", MF_ENABLED + MF_STRING, "E&xit", {|| DoExit()})
SetMenu(hWnd, hMenu)
return hMenu
function AddHandler(hWnd, bAction) // --> nId (for use with DelHandler)
aadd(aWnd, hWnd)
aadd(aAction, bAction)
return len(aWnd)
procedure DelHandler(nId)
adel(aWnd, nId)
asize(aWnd, len(aWnd) - 1)
adel(aAction, nId)
asize(aAction, len(aAction) - 1)
return
procedure HandleEvent(nEvent)
local hWnd := _LasthWnd(), i := 0
do while (i := ascan(aWnd, hWnd, ++i)) != 0
eval(aAction[i], nEvent)
enddo
if nEvent == EVENT_DESTROY
// clean up, so the event handler needn't bother
do while (i := ascan(aWnd, hWnd)) != 0
DelHandler(i)
enddo
endif
return
function WinNew(cAppName, cTitle, nX, nY, nWidth, nHeight)
local hWin, hInst, nCmdShow
hInst = _GetInstance()
nCmdShow = _GetnCmdShow()
hWin = CreateWindow(cAppName, ; // window class
cTitle, ; // caption for title bar
WS_OVERLAPPEDWINDOW,; // window style
nX, ; // x co-ordinate
nY, ; // y co-ordinate
nWidth, ; // width
nHeight, ; // height
hWnd, ; // hWnd of parent
0, ; // hMenu of menu (none yet)
hInst) // our own app instance
if hWin == 0
// probably out of resources
MessageBox( , "Can't create window", "Error", MB_OK)
return nil
endif
HideCaret(hWin)
// make sure it's displayed ...
ShowWindow(hWin, nCmdShow)
// ... and up to date
UpdateWindow(hWin)
return hWin