The code for this new functionality is in the EvLButtonDown function. The TPoint parameter that's passed to the EvLButtonDown contains the coordinates at which the mouse button was clicked. You'll need to add a char string to the function to hold the text representation of the point. You can then use the wsprintf function to format the string. Now you have to set up the window to print the string.
TClientDC has a single constructor that takes an HWND as its only parameter. Because you want a device context for your TDrawWindow object, you need the handle for that window. As it happens, the TWindow base class provides an HWND conversion operator. This operator is called implicitly whenever you use the window object in places that require an HWND. So the constructor for your TClientDC object looks something like this:
TClientDC dc(*this);Notice that the this pointer is dereferenced. The HWND conversion operator doesn't work with pointers to window objects.
virtual bool TextOut(int x, int y, const char far* str,
int count=-1);
The HDC parameter is filled by the TDC object. The second version of TextOut omits the HDC parameter and combines the x- and y-coordinates into a single TPoint structure:
bool TextOut(const TPoint& p, const char far* str,
int count=-1);
Because the coordinates are passed into the EvLButtonDown function in a TPoint object, you can use the second version of TextOut to print the coordinates in the window. Your completed EvLButtonDown function should look something like this:
void TDrawWindow::EvLButtonDown(uint, TPoint& point)
{
char s[16];
TClientDC dc(*this);
wsprintf(s, "(%d,%d)", point.x, point.y);
dc.TextOut(point, s, strlen(s));
}
You need to include the string.h header file to use the strlen function.
Therefore, to erase the entire client area of TDrawWindow, you need only call Invalidate, either specifying true or nothing at all for its parameter. To clear the screen when the user presses the right mouse button, you must make this call in the EvRButtonDown function. The function would look something like this:
void TDrawWindow::EvRButtonDown(uint, TPoint&)
{
Invalidate();
}