home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 May
/
Pcwk5b98.iso
/
Borland
/
Cplus45
/
BC45
/
TUTOROOT.PAK
/
STEP04.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-29
|
2KB
|
103 lines
//----------------------------------------------------------------------------
// ObjectWindows - (C) Copyright 1991, 1994 by Borland International
// Tutorial application -- step04.cpp
//----------------------------------------------------------------------------
#include <owl/owlpch.h>
#include <owl/applicat.h>
#include <owl/framewin.h>
#include <owl/dc.h>
class TDrawWindow : public TWindow {
public:
TDrawWindow(TWindow* parent = 0);
~TDrawWindow()
{
delete DragDC;
}
protected:
TDC* DragDC;
// Override member function of TWindow
bool CanClose();
// Message response functions
void EvLButtonDown(uint, TPoint&);
void EvRButtonDown(uint, TPoint&);
void EvMouseMove(uint, TPoint&);
void EvLButtonUp(uint, TPoint&);
DECLARE_RESPONSE_TABLE(TDrawWindow);
};
DEFINE_RESPONSE_TABLE1(TDrawWindow, TWindow)
EV_WM_LBUTTONDOWN,
EV_WM_RBUTTONDOWN,
EV_WM_MOUSEMOVE,
EV_WM_LBUTTONUP,
END_RESPONSE_TABLE;
TDrawWindow::TDrawWindow(TWindow* parent)
{
Init(parent, 0, 0);
DragDC = 0;
}
bool
TDrawWindow::CanClose()
{
return MessageBox("Do you want to save?", "Drawing has changed",
MB_YESNO | MB_ICONQUESTION) == IDNO;
}
void
TDrawWindow::EvLButtonDown(uint, TPoint& point)
{
Invalidate();
if (!DragDC) {
SetCapture();
DragDC = new TClientDC(*this);
DragDC->MoveTo(point);
}
}
void
TDrawWindow::EvRButtonDown(uint, TPoint&)
{
Invalidate();
}
void
TDrawWindow::EvMouseMove(uint, TPoint& point)
{
if (DragDC)
DragDC->LineTo(point);
}
void
TDrawWindow::EvLButtonUp(uint, TPoint&)
{
if (DragDC) {
ReleaseCapture();
delete DragDC;
DragDC = 0;
}
}
class TDrawApp : public TApplication {
public:
TDrawApp() : TApplication() {}
void InitMainWindow()
{
SetMainWindow(new TFrameWindow(0, "Drawing Pad", new TDrawWindow));
}
};
int
OwlMain(int /*argc*/, char* /*argv*/ [])
{
return TDrawApp().Run();
}