home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
CMD
/
DRAW.PRG
< prev
next >
Wrap
Text File
|
1995-05-08
|
2KB
|
97 lines
////////////////////////////
//
// draw.prg
//
// Copyright (C) 1993 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// Drawing program, using a window procedure.
//
// Instructions:
// press left mouse button somewhere in the client area
// move around
// release button
//
// (use system box or Alt-F4 to make program exit)
//
////////////////////////////
#define WIN_WANT_ALL
#include "windows.ch"
#include "msg.ch"
#include "paint.ch"
#include "topclass.ch"
#define NO_C4WCLASS
#include "commands.ch"
#define MAXPOINTS 2000
#define MOUSE_LBUTTON MK_LBUTTON // from windows.ch
static aX[MAXPOINTS]
static aY[MAXPOINTS]
static nCount := 0
function main()
local oApp, hWnd
CREATE APPLICATION oApp WINDOW hWnd TITLE "Join the dots" ;
CURSOR LoadCursor(0, IDC_CROSS) ;
ON WM_LBUTTONDOWN OnLBtnDown() ;
ON WM_LBUTTONUP OnLBtnUp() ;
ON WM_MOUSEMOVE OnMouseMove() ;
ON WM_PAINT OnPaint()
return nil
static function OnLBtnDown(hWnd, nMsg, nwParam, nlParam)
// this is logically the 1st event we want to handle...
nCount = 0
InvalidateRect(hWnd)
return 0 // 0 means we processed the msg
static function OnMouseMove(hWnd, nMsg, nwParam, nlParam)
local hDC
// ... but it would be faster to put this first
// (only matters on a _slow_ cpu) ...
if C4W_And(nwParam, MOUSE_LBUTTON) != 0 .and. nCount < MAXPOINTS
nCount++
aX[nCount] = c4w_LoWord(nlParam)
aY[nCount] = c4w_HiWord(nlParam)
// leave a trail of black dots
hDC = GetDC(hWnd)
SetPixel(hDC, aX[nCount], aY[nCount], RGB(0,0,0))
ReleaseDC(hWnd, hDC)
endif
return 0 // 0 means we processed the msg
static function OnLBtnUp(hWnd, nMsg, nwParam, nlParam)
// ... then this is the last of the sequence, before...
InvalidateRect(hWnd)
return 0 // 0 means we processed the msg
static function OnPaint(hWnd, nMsg, nwParam, nlParam)
local aPaint[PS_LENGTH], hDC, i, j
// ... now we join the dots in many ways!
hDC = BeginPaint(hWnd, aPaint)
for i = 1 to nCount - 1
for j = 1 to nCount
MoveTo(hDC, aX[i], aY[i])
LineTo(hDC, aX[j], aY[j])
next j
next i
EndPaint(hWnd, aPaint)
return 0 // 0 means we processed the msg