CListCtrl
CTreeCtrl
CSpinButtonCtrl
CHeaderCtrl
CSliderCtrl
CProgressCtrl
CHotKeyCtrl
CToolTipCtrl
CTabCtrl
CAnimateCtrl
CToolBarCtrl
CStatusBarCtrl
CRichEditCtrl
Figure 6 CmainFrame
Mainfrm.h
////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
/////////////////
// Main frame window has menu manager, flatbar, status bar
//
class CMainFrame : public CFrameWnd {
public:
CMainFrame();
~CMainFrame();
protected:
DECLARE_DYNCREATE(CMainFrame)
CStatusBar m_wndStatusBar; // standard status bar
CToolBar m_wndToolBar; // if using toolbar
// overrides
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
// message handlers
DECLARE_MESSAGE_MAP()
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// command handlers
afx_msg void OnToolbarDropDown(NMTOOLBAR* pnmh, LRESULT* plRes);
};
Mainfrm.cpp
////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#include "StdAfx.h"
#include "MainFrm.h"
#include "View.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////
// CMainFrame
//
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)
END_MESSAGE_MAP()
static UINT indicators[] = {
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
CMainFrame::CMainFrame()
{
}
CMainFrame::~CMainFrame()
{
}
////////////////
// Override flicker-free drawing with no CS_VREDRAW and CS_HREDRAW. This has
// nothing to do with coolbars, but I it's a good thing to do.
//
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = AfxRegisterWndClass(
0, // no redraw
NULL, // no cursor (use default)
NULL, // no background brush
AfxGetApp()->LoadIcon(IDR_MAINFRAME)); // app icon
ASSERT(cs.lpszClass);
return CFrameWnd::PreCreateWindow(cs);
}
//////////////////
// Create handler creates control bars
//
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
VERIFY(CFrameWnd::OnCreate(lpCreateStruct) == 0);
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT);
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT))) {
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips or a resizable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
#ifndef TB_SETEXTENDEDSTYLE
#define TB_SETEXTENDEDSTYLE (WM_USER + 84) // For TBSTYLE_EX_*
#define TBSTYLE_EX_DRAWDDARROWS 0x00000001
#endif
CToolBar& tb = m_wndToolBar;
tb.SendMessage(TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS);
// change button style to dropdown
int iButton = tb.SendMessage(TB_COMMANDTOINDEX, ID_FILE_OPEN);
DWORD dwStyle = tb.GetButtonStyle(iButton);
dwStyle |= TBSTYLE_DROPDOWN;
tb.SetButtonStyle(iButton, dwStyle);
return 0;
}
//////////////////
// Handle TBN_DROPDOWN
// Default is to display the specified menu at the right place.
// You can override to generate dynamic menus
//
// Args:
// - NMTOOLBAR struct from TBN_DROPDOWN
// - command id of button
// - point to display menu at
//
void CMainFrame::OnToolbarDropDown(NMTOOLBAR* pnmtb, LRESULT *plr)
{
// load and display popup menu
CMenu menu;
menu.LoadMenu(IDR_FILEDROPDOWN);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);
CRect rc;
m_wndToolBar.SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rc);
m_wndToolBar.ClientToScreen(&rc);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, this, &rc);
}
Figure 7 Newtb.h
#define TB_MARKBUTTON (WM_USER + 6)
#define TB_ISBUTTONHIGHLIGHTED (WM_USER + 14)
#define VIEW_VIEWMENU 12
#define TB_GETOBJECT (WM_USER + 62) // wParam == IID, lParam void
// **ppv
#define TB_GETHOTITEM (WM_USER + 71)
#define TB_SETHOTITEM (WM_USER + 72) // wParam == iHotItem
#define TB_SETANCHORHIGHLIGHT (WM_USER + 73) // wParam == TRUE/FALSE
#define TB_GETANCHORHIGHLIGHT (WM_USER + 74)
#define TB_MAPACCELERATORA (WM_USER + 78) // wParam == ch, lParam int *
// pidBtn
typedef struct {
int iButton;
DWORD dwFlags;
} TBINSERTMARK, * LPTBINSERTMARK;
#define TBIMHT_AFTER 0x00000001 // TRUE = insert After iButton, otherwise
// before
#define TBIMHT_BACKGROUND 0x00000002 // TRUE iff missed buttons completely
#define TB_GETINSERTMARK (WM_USER + 79) // lParam == LPTBINSERTMARK
#define TB_SETINSERTMARK (WM_USER + 80) // lParam == LPTBINSERTMARK
#define TB_INSERTMARKHITTEST (WM_USER + 81) // wParam == LPPOINT lParam ==
// LPTBINSERTMARK
#define TB_MOVEBUTTON (WM_USER + 82)
#define TB_GETMAXSIZE (WM_USER + 83) // lParam == LPSIZE
#define TB_SETEXTENDEDSTYLE (WM_USER + 84) // For TBSTYLE_EX_*
#define TB_GETEXTENDEDSTYLE (WM_USER + 85) // For TBSTYLE_EX_*
#define TB_GETPADDING (WM_USER + 86)
#define TB_SETPADDING (WM_USER + 87)
#define TB_SETINSERTMARKCOLOR (WM_USER + 88)
#define TB_GETINSERTMARKCOLOR (WM_USER + 89)
#define TB_SETCOLORSCHEME CCM_SETCOLORSCHEME // lParam is color scheme
#define TB_GETCOLORSCHEME CCM_GETCOLORSCHEME // fills in COLORSCHEME
// pointed to by lParam
#define TB_SETUNICODEFORMAT CCM_SETUNICODEFORMAT
#define TB_GETUNICODEFORMAT CCM_GETUNICODEFORMAT
#define TB_MAPACCELERATORW (WM_USER + 90) // wParam == ch, lParam int *
// pidBtn
#ifdef UNICODE
#define TB_MAPACCELERATOR TB_MAPACCELERATORW
#else
#define TB_MAPACCELERATOR TB_MAPACCELERATORA
#endif