Book Image

Microsoft Visual C++ Windows Applications by Example

By : Stefan Bjornander, Stefan Björnander
Book Image

Microsoft Visual C++ Windows Applications by Example

By: Stefan Bjornander, Stefan Björnander

Overview of this book

Table of Contents (15 chapters)
Microsoft Visual C++ Windows Applications by Example
Credits
About the Author
About the Reviewer
Preface
Index

Menus, Accelerators, and Toolbars


So far, we could only paint rings in one color, now it is time to change that. Let us add a field m_nextColor to the document class and initialize it with the white color. We also modify the function MouseDown and OnDraw.

RingDoc.h

class CRingDoc : public CDocument
{
// ...

priva

te:
  COLORREF m_nextColor;
};

RingDoc.cpp

CRingDoc::CRingDoc()

  : m_nextColor(WHITE)
{
  // Empty.
}

void CRingDoc::MouseDown(CPoint point)
{
  m_pointArray.Add(point);
  m_colorArray.Add(m_nextColor);

  UpdateAllViews(NULL);
}

When we created the application with theApplication Wizard, we got a standard menu bar. We can modify it by editing the resource file resource.rc manually, or we can use the tool Resource View.

We can add mnemonic markers for the menus and items by preceding the character with an ampersand (&), and we can set a tabulator between words with \t. Then we pick a name for the menu items, lets us choose ID_COLOR_WHITE, ID_COLOR_GREY, and ID_COLOR_BLACK...