Tutorials
|
|
Menu of tutorialsTutorial 1: The Simplest Window
Our frame window has both a menu and a toolbar at the top.
Customising the menu is relatively straight forward, since we can use a
resource editor to perform that task. Customising the toolbar however is
another matter. While its true that the resource editor that ships
Microsoft's Visual Studio can edit the toolbar resource, this is not
standard, and we so need to come up with a standards compliant way of
modifying the toolbar. To set your own toolbar for your applications, you will need to perform
the following steps: Windows provides a ChooseColor function. This function displays a dialog
and allows us to select a color for our pen. The code that uses ChooseColor
is as follows: void CMainFrame::OnPenColor() { // An array of custom colors, initialized to white. static COLORREF custColors[16] = { RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255), RGB(255,255,255) }; CColorDialog colorDlg; ColorDlg.SetCustomColors(custColors); // Initialize the Choose Color dialog. if (colorDlg.DoModal(*this) == IDOK) { // Store the custom colors in the static array. memcpy(custColors, colorDlg.GetCustomColors(), 16*sizeof(COLORREF)); // Retrieve the chosen color. m_view.SetPenColor(colorDlg.GetColor()); } } The source code for this tutorial is located within the Tutorial folder of the software available from SourceForge at http://sourceforge.net/projects/win32-framework. |