Toolbar¾È¿¡ ´Ù¸¥ Control³Ö±â


1.¿ä¾à

FontÁ¾·ù³ª È®´ë/Ãà¼Ò ºñÀ²À» Á¤ÇÒ ¶§ Toolbar¿¡ ComboBox¸¦ ³Ö¾î¼­ ¸¹ÀÌ ¾¹´Ï´Ù. ÀÌó·³ ÀڱⰡ ¿øÇÏ´Â Control¸¦ Toolbar¾È¿¡ ¾î¶»°Ô »ðÀÔÇÏ´ÂÁö ¼³¸íÇϰڽÀ´Ï´Ù.


2.º»¹®

ComboBox¸¦ »ý¼ºÇÏ´Â °ÍÀ» ¿¹·Î µé¾ú½À´Ï´Ù.
CToolBarEx¸¦ »ó¼Ó¹Þ´Â CCombobar¸¦ »ý¼ºÇÑ´Ù.
CCombobar¿¡¼­ ´ÙÀ½°ú °°ÀÌ ±¸ÇöÇØ ÁØ´Ù.

/////////////////////

// combobar.cpp



BEGIN_MESSAGE_MAP(CComboBar, CToolBarEx) 

//{{AFX_MSG_MAP(CComboBar) 

ON_CBN_SELENDOK(IDW_TOOLCOMBO, OnSelEndOk) 

//}}AFX_MSG_MAP 

END_MESSAGE_MAP() 



// À̾ȿ¡¼­ Toolbarµµ »ý¼ºÇϰí ComboBoxµµ »ý¼ºÇÑ´Ù. 

BOOL CComboBar::Create(CFrameWnd * pParent, UINT nID, UINT nComboID, 

                       const int nWidth, 

                       const int nHeight) 

{ 

    // Create the toolbar as CMainFrame::OnCreate() would do 

    if (!CToolBar::Create(pParent) || 

        !LoadToolBar(nID)) 

    { 

        TRACE0("Falied to create the toolbar.\n"); 

        return FALSE;      // fail to create 

    } 

    

    // set the size of combo-control 

    CRect rect(-nWidth, -nHeight, 0, 0); 

    

    

    // ComboxBox°¡ µé¾î°¥ À§Ä¡¸¦ TBBS_SEPARATOR¼Ó¼ºÀ¸·Î ¹Ù²Ù°í 

    // ³ÐÀ̸¦ ÁöÁ¤ÇØ ÁØ´Ù. 

    ASSERT(CommandToIndex(nComboID) >= 0); // make sure the id is valid 

    SetButtonInfo(CommandToIndex(nComboID), nComboID, TBBS_SEPARATOR, nWidth); 

    

    // ComboBox¸¦ »ý¼ºÇÑ´Ù. 

    if (!m_pWndBox.Create(WS_CHILD | CBS_DROPDOWN | 

        CBS_AUTOHSCROLL | WS_VSCROLL | CBS_HASSTRINGS, rect, this, 

        nComboID)) 

    { 

        TRACE("Failed to create the combo-box %p .\n", ComboID); 

        return FALSE; 

    } 

    

    // ComboBox°¡ µé¾î°¥ À§Ä¡ÀÇ Å©±â¸¦ °¡Á®¿Â´Ù. 

    // ±× Å©±â¿¡ µû¶ó ComboBoxÀÇ Å©±â¿Í À§Ä¡¸¦ Á¶ÀýÇØ ÁØ´Ù. 

    GetItemRect(CommandToIndex(nComboID), &rect); 

    m_pWndBox.SetWindowPos(0, rect.left, rect.top, 0, 0, 

        SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOCOPYBITS); 

    m_pWndBox.SetFont(&m_GuiFont); 

    m_pWndBox.ShowWindow(SW_SHOW); 

    

    if (!OnInitialCreate()) 

    { 

        TRACE("Failed to add strings to %p\n", nComboID); 

        return FALSE; 

    } 

    

    return TRUE; 

} 



// ComboBoxÀÇ µ¥ÀÌÅ͸¦ ÃʱâÈ­ÇÑ´Ù. 

BOOL CComboBar::OnInitialCreate() 

{ 

    if(m_pWndBox.m_hWnd != NULL) 

    { 

        //This is where you add your strings 

        m_pWndBox.AddString("Page Width"); 

        m_pWndBox.AddString("150 %"); 

        m_pWndBox.AddString("125 %"); 

        m_pWndBox.AddString("100 %"); 

        m_pWndBox.AddString("75  %"); 

        m_pWndBox.AddString("50  %"); 

        m_pWndBox.AddString("25  %"); 

        //Don't forget the initial position. 

        m_pWndBox.SetCurSel(0); 

        

        return TRUE; 

    } 

    return FALSE; 

} 



int CComboBar::m_cbIndex = 0; 



void CComboBar::OnSelEndOk() 

{ 

    m_cbIndex = m_pWndBox.GetCurSel(); 

} 





/////////////////////////

// combobar.h 





class CComboBar : public CToolBarEx 

{ 

    // Construction 

public: 

    CComboBar(); 

    CComboBox m_pWndBox; 

    

    static int m_cbIndex; 

    

    // Attributes 

public: 

    

    // Operations 

public: 

    BOOL OnInitialCreate(); 

    //  is the toolbar-resource to load 

    //  is the ID of the button, that shall be used as the 

    combo-control 

        BOOL Create(CFrameWnd * pParent, UINT nID, UINT nComboID, const int 

        nWidth, 

        const int nHeight); 

    

    // Overrides 

    // ClassWizard generated virtual function overrides 

    //{{AFX_VIRTUAL(CComboBar) 

public: 

    virtual void OnFinalRelease(); 

    //}}AFX_VIRTUAL 

    

    // Implementation 

public: 

    virtual ~CComboBar(); 

    

    // Generated message map functions 

protected: 

    //{{AFX_MSG(CComboBar) 

    //}}AFX_MSG 

    

    DECLARE_MESSAGE_MAP() 

        // Generated OLE dispatch map functions 

        //{{AFX_DISPATCH(CComboBar) 

        // NOTE - the ClassWizard will add and remove member functions here. 

        afx_msg void OnSelEndOk(); 

    //}}AFX_DISPATCH 

    DECLARE_DISPATCH_MAP() 

        DECLARE_INTERFACE_MAP() 

}; 

CMainFrame¿¡¼­ CCombobar¸¦ ¼±¾ðÇØ¼­ ÀÏ¹Ý Åø¹Ù¿Í °°Àº ¹æ¹ýÀ¸·Î »ç¿ëÇÑ´Ù.



- 2001.08.13 Smile Seo -