Enhanced Classes | |
CHeaderCtrl | Supports drag and drop operations and bitmaps in a header control. |
CImageList | Supports images used by other controls such as in header controls and list controls. |
CListCtrl | Supports the grouping of items using working areas. Also supports virtual list views. |
CProgressCtrl | Supports smooth and vertical styles for progress controls. |
CSliderCtrl | Supports tooltips in a slider control and additional slider control styles. |
CSpinButtonCtrl | Supports 32-bit ranges in a spin button control. |
CStatusBar CStatusBarCtrl |
Supports tooltips, icons, and background color in a status bar. |
CTabCtrl | Supports new styles for tab focus and appearance. Also supports inserting new tabs into an existing tab control. |
CToolBar CToolBarCtrl |
Supports Internet Explorer 4.0 flat and transparent toolbar styles. |
CToolTipCtrl | Implements updating of a ToolTip and its attributes. |
CTreeCtrl | Supports checkboxes and automatic single-node expansion in a tree control. |
New Classes | |
CComboBoxEx | Encapsulates an extended combobox with image lists. |
CDateTimeCtrl | Encapsulates date/time control—either an extended edit control or a simple calendar interface control that allows a user to choose a specific date or time value. |
CIPAddressCtrl | Encapsulates the IP address control, an edit box for manipulating an IP address. |
CMonthCalCtrl | Encapsulates the month/calendar control, which lets the user select a date. |
CReBar | Encapsulates the rebar (coolbar) control, an Internet Explorer-style toolbar that can |
CRebarCtrl | contain additional child windows as controls. |
Figure 6 Implementing a Rebar
//************************************************************************
// These code fragements show the MFC-generated code for an app with rebar.
//************************************************************************
//************************************************************************
// In mainframe.h
class CMainFrame : public CMDIFrameWnd {
.
.
.
CToolBar m_wndToolBar; // toolbar
CReBar m_wndReBar; // rebar
CDialogBar m_wndDlgBar; // dialog bar
};
//************************************************************************
// In MainFrm.cpp
•
•
•
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Create toolbar
if (!m_wndToolBar.CreateEx(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// Create dialog bar
if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR)) {
TRACE0("Failed to create dialogbar\n");
return -1; // fail to create
}
// Create rebar
if (!m_wndReBar.Create(this) ||
!m_wndReBar.AddBar(&m_wndToolBar) || // add toolbar
!m_wndReBar.AddBar(&m_wndDlgBar)) { // add dialog bar
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
•
•
•
return 0;
}
Figure 17 Needs a Table
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.
.
.
CString str;
// set up each toolbar button
// Don't ever write code like this!!
//
m_wndToolBar.SetButtonInfo(0, ID_GO_BACK, TBSTYLE_BUTTON, 0);
str.LoadString(IDS_BACK);
m_wndToolBar.SetButtonText(0, str);
m_wndToolBar.SetButtonInfo(1, ID_GO_FORWARD, TBSTYLE_BUTTON, 1);
str.LoadString(IDS_FORWARD);
m_wndToolBar.SetButtonText(1, str);
m_wndToolBar.SetButtonInfo(2, ID_VIEW_STOP, TBSTYLE_BUTTON, 2);
str.LoadString(IDS_STOP);
m_wndToolBar.SetButtonText(2, str);
m_wndToolBar.SetButtonInfo(3, ID_VIEW_REFRESH, TBSTYLE_BUTTON, 3);
str.LoadString(IDS_REFRESH);
m_wndToolBar.SetButtonText(3, str);
m_wndToolBar.SetButtonInfo(4, ID_GO_START_PAGE, TBSTYLE_BUTTON, 4);
str.LoadString(IDS_HOME);
m_wndToolBar.SetButtonText(4, str);
m_wndToolBar.SetButtonInfo(5, ID_GO_SEARCH_THE_WEB, TBSTYLE_BUTTON, 5);
str.LoadString(IDS_SEARCH);
m_wndToolBar.SetButtonText(5, str);
m_wndToolBar.SetButtonInfo(6, ID_FAVORITES_DROPDOWN, TBSTYLE_BUTTON |
TBSTYLE_DROPDOWN, 6);
str.LoadString(IDS_FAVORITES);
m_wndToolBar.SetButtonText(6, str);
m_wndToolBar.SetButtonInfo(7, ID_FILE_PRINT, TBSTYLE_BUTTON, 7);
str.LoadString(IDS_PRINT);
m_wndToolBar.SetButtonText(7, str);
m_wndToolBar.SetButtonInfo(8, ID_FONT_DROPDOWN, TBSTYLE_BUTTON |
TBSTYLE_DROPDOWN, 8);
str.LoadString(IDS_FONT);
m_wndToolBar.SetButtonText(8, str);
.
.
.
return 0;
}
Figure 18 A Better Example
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
static struct {
UINT idCmd;
UINT idStr;
DWORD style;
} Buttons[] = {
// command ID string style flags
{ ID_GO_BACK, IDS_BACK, 0},
{ ID_GO_FORWARD, IDS_FORWARD 0},
{ ID_VIEW_STOP, IDS_STOP 0},
{ ID_VIEW_REFRESH, IDS_REFRESH 0},
{ ID_GO_START_PAGE, IDS_HOME 0},
{ ID_GO_SEARCH_THE_WEB, IDS_SEARCH 0},
{ ID_FAVORITES_DROPDOWN,IDS_FAVORITES, TBSTYLE_DROPDOWN },
{ ID_FILE_PRINT, IDS_PRINT 0},
{ ID_FONT_DROPDOWN, IDS_FONT, TBSTYLE_DROPDOWN },
{ 0, 0, 0 }
}
// set up each toolbar button
CString str;
for (int i=0; Buttons[i].idCmd; i++) {
m_wndToolBar.SetButtonInfo(i, Buttons[i].idCmd,
TBSTYLE_BUTTON | Buttons[i].style, i);
str.LoadString(Buttons[i].idStr);
m_wndToolBar.SetButtonText(i, str);
}
.
.
.
return 0;
}
Figure 19 CHtmlView Versus DWebBrowserEvents2
CHtmlView Virtual Function | DWebBrowserEvents2 Event | Description |
OnStatusTextChange | StatusTextChange | Fired when the status bar text has changed. |
OnProgressChange | ProgressChange | Fired when the progress of a download operation is updated. |
OnCommandStateChange | CommandStateChange | Fired when the enabled state of a command changes. |
OnDownloadBegin | DownloadBegin | Fired when a navigation operation is beginning, shortly after the BeforeNavigate2 event, unless the navigation is canceled. |
OnDownloadComplete | DownloadComplete | Fired when a navigation operation finishes, is halted, or fails. |
OnTitleChange | TitleChange | Fired when the title of a document in the WebBrowser control becomes available or changes. |
OnPropertyChange | PropertyChange | Fired when the IWebBrowser2::PutProperty method changes the value of a property. |
OnBeforeNavigate2 | BeforeNavigate2 | Fired when the WebBrowser control is about to navigate to a new URL. |
OnNewWindow2 | NewWindow2 | Fired when a new window is to be created for displaying a resource. |
OnNavigateComplete2 | NavigateComplete2 | Fired after the browser has successfully navigated to a new location. |
OnDocumentComplete | DocumentComplete | Fired when the document being navigated to is ready. |
OnQuit | OnQuit | Fired when the Internet Explorer application is ready to quit. |
OnVisible | OnVisible | Fired when the window for the WebBrowser should be shown/hidden. |
OnToolBar | OnToolBar | Fired when the ToolBar property has changed. |
OnMenuBar | OnMenuBar | Fired when the MenuBar property has changed. |
OnStatusBar | OnStatusBar | Fired when the StatusBar property has changed. |
OnFullScreen | OnFullScreen | Fired when the FullScreen property has changed. |
OnTheaterMode | OnTheaterMode | Fired when the TheaterMode property has changed. |