[ Home | Syllabus |Course Notes]
PROBLEM: Add GUI controls for accessing message folders.
SOLUTION: menus, list boxes, dialog boxes
There are three ways to create menus:
VC++ IDE has visual tools for creating resources (like menus). which automatically create a ".rc" and a resource.h file.
or you can edit directly.
Resource file for Project "simple1"
#include "resource.h" // for ID constants #include <afxres.h> // for VK_F4 ///////////////////////////////////////////////////////////////////////////// // // Menu // IDR_MENU1 MENU DISCARDABLE // names a menu IDR_MENU1 BEGIN POPUP "&Folder" // this will appear in the title bar of the window (see below) BEGIN MENUITEM "&Open\tCtrl-O", IDM_FOLDER_OPEN // \t is tab Ctrl-O bound below MENUITEM "Close", IDM_FOLDER_CLOSE // ID for Message Handler MENUITEM SEPARATOR MENUITEM "E&xit\tAlt-F4", IDM_FOLDER_EXIT END END IDR_MENUACC ACCELERATORS PRELOAD MOVEABLE BEGIN "O", IDM_FOLDER_OPEN, VIRTKEY,CONTROL VK_F4, IDM_FOLDER_EXIT, VIRTKEY,ALT END
// Once loaded, these two resources give menus with mouse and keyboard control
Use a value greater than 100
CMainWindow::CMainWindow()
{
// Create the window
Create(NULL, "Message Folder Demo",
WS_OVERLAPPEDWINDOW,
CRect(0,0,700,500),
NULL,
MAKEINTRESOURCE(IDR_MENU1)); // Loads Menu from resource file
and associates with window
LoadAccelTable(MAKEINTRESOURCE(IDR_MENUACC)); // load
keyboard accelerators
}
void CMainWindow::OnCloseFolder() { MessageBox("You clicked Close", "MsgFolder Close"); } void CMainWindow::OnExit() { if(MessageBox("Are you sure you want to Exit?", "MsgFolder Exit", MB_YESNO) == IDYES) SendMessage(WM_CLOSE, 0, 0); }