처리되지 않은 WM_COMMAND와 WM_NOTIFY(, WM_DRAWITEM, WM_MEASUREITEM, WM_DELETEITEM, WM_COMPAREITEM, WM_VKEYTOITEM, WM_VKEYTOITEM) 메시지를 부모 프레임으로 전달한다.
.SetBarStyle()
CBRS_FLYBY
CBRS_TOOLTIPS
.GetBarStyle()
.EnableDocking()
CBRS_ALIGN_ANY
CBRS_ALIGN_TOP
CBRS_ALIGN_BOTTOM
.ShowControlBar()
툴바
동일한 크기로 이루어진 비트맵 버튼 만을 갖는다.
CToolBarCtrl
never assumes that it has a parent window derived from CFrameWnd
lacks some features like docking or automatic tooltips
can be used with any window whose parent is derived from CWnd
CRect rcWindow; GetWindowRect(rcWindow); rcWindow.right += rcClientStart.Width() - rcClientNow.Width(); rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height(); MoveWindow(rcWindow, FALSE);
// }} RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0);
// }
return TRUE; // return TRUE unless you set the focus to a control
}
... void CTry01Dlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); }
void CTry01Dlg::OnButton1() {
// TODO: Add your control notification handler code here m_FirstToolBar.GetToolBarCtrl().HideButton(ID_BUTTON32771, TRUE); }
void CTry01Dlg::OnButton2() {
// TODO: Add your control notification handler code here m_FirstToolBar.GetToolBarCtrl().EnableButton(ID_BUTTON32772,false); }
void CTry01Dlg::OnToolBarButton1()
{ MessageBox("Clicked!"); }
or
class CModelessMain : public CDialog
{ CToolBar m_toolBar;
// Construction
public:
CModelessMain();
...
// Generated message map functions
//{{AFX_MSG(CTry01Dlg)
...
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// Create status bar at the bottom of the dialog window
if (m_statusBar.Create(this))
{
m_statusBar.SetIndicators(m_lpaIDStatusBar, m_cIDStatusBar);
OnSetMessageString(AFX_IDS_IDLEMESSAGE);
// Make a sunken or recessed border around the first pane
m_statusBar.SetPaneInfo(0, m_statusBar.GetItemID(0),
SBPS_STRETCH, NULL );
}
// Create toolbar at the top of the dialog window
if (m_toolBar.Create(this))
{
m_toolBar.LoadBitmap(IDR_MAIN);
m_toolBar.SetButtons(auIDToolBar, sizeof(auIDToolBar)/sizeof(UINT));
}
m_toolBar.SetBarStyle(m_toolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// <<
// We need to resize the dialog to make room for control bars.
// First, figure out how big the control bars are.
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
0, reposQuery, rcClientNow);
// Now move all the controls so they are in the same relative
// position within the remaining client area as they would be
// with no control bars.
CPoint ptOffset(rcClientNow.left - rcClientStart.left,
rcClientNow.top - rcClientStart.top);
// Adjust the dialog window dimensions
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);
// >>
// And position the control bars
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
...
return TRUE;
}
... void CModelessMain::OnSize(UINT nType, int cx, int cy) { CModelessDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); }
void CModelessMain::OnOptionNow()
{
... }
리바
CReBarCtrl -> CWnd
CReBar -> CControlBar
.GetReBarCtrl()
다이얼로그 바
CDialogBar -> CControlBar
모달리스 대화상자
WM_INITDIALOG 메시지를 받지 않는다.
.Create()
.EnableDocking()
Style은 Child, Border는 None, Title Bar는 FALSE로 다이얼로그 리소스를 생성한다.
class CMainFrame : public CFrameWnd
{
...
// Implementation
public: CDialogBar m_wndDialogBar;
...
};
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// {
//다이얼로그바 생성 if (!m_wndDialogBar.Create(this, IDD_DIALOG_CALCULATOR, CBRS_LEFT, IDD_DIALOG_CALCULATOR)) return -1;
//도킹가능하도록 함. m_wndDialogBar.EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndDialogBar);
// }
return 0;
}
class CPractice6_4View : public CView
{
...
protected:
if (!m_wndChild.Create(WS_CHILD|WS_VISIBLE|
ES_MULTILINE|ES_WANTRETURN|ES_AUTOVSCROLL,
CRect(0,0,0,0), this, 123))
return -1;
m_wndChild.ModifyStyleEx(0, WS_EX_CLIENTEDGE);
// older versions of Windows* (NT 3.51 for instance)
// fail with DEFAULT_GUI_FONT
if (!m_font.CreateStockObject(DEFAULT_GUI_FONT))
if (!m_font.CreatePointFont(80, "MS Sans Serif"))
return -1;
m_wndChild.SetFont(&m_font);
return 0;
}
class CMainFrame : public CFrameWnd
{
// {
CMyBar m_wndMyBar;
// }
protected: // create from serialization only
CMainFrame();
...
};
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
DockControlBar(&m_wndToolBar);
// {
if (!m_wndMyBar.Create(_T("My Bar"), this, 123))
{
TRACE0("Failed to create mybar\n");
return -1;
// fail to create
}