CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    399

    Using CSplitButton in VC6

    Is there any chance to use CSplitButton in VC6 ?
    I had tried to use something appropriate founded on CP, but they are using DrawItem, and I had problems with windows style, and I had tried to make myself one, overriding OnPaint, but I front with flickering (I put the sample below)... so, I wonder if I could get (from somewhere) CSplitButton and add to my project ... if you say that I could, can you provide me the CSplitButton source code ? I mean, only .cpp implementation file ...

    Thank you.
    Attached Files Attached Files
    Last edited by mesajflaviu; December 5th, 2013 at 08:17 AM.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Using CSplitButton in VC6

    Much simpler:
    If the target OS is Windows Vista or newer, you can make from an ordinary push button a split button by adding BS_SPLITBUTTON or BS_DEFSPLITBUTTON style.
    Next, just handle BCN_DROPDOWN (reflected) notification and do something cool, e.g. show a drop-down menu.

    Example
    Code:
    // MySplitButton.h
    #pragma once
    
    class CMySplitButton : public CButton
    {
        // ...
        virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
        virtual void PreSubclassWindow();
        // ...
        afx_msg void OnBnDropDown(NMHDR *pNMHDR, LRESULT *pResult);
    };
    Code:
    // MySplitButton.cpp
    // ...
    
        // ...
        ON_NOTIFY_REFLECT(BCN_DROPDOWN, OnBnDropDown)
    END_MESSAGE_MAP()
    
    // ...
    BOOL CMySplitButton::PreCreateWindow(CREATESTRUCT& cs)
    {
        cs.style |= BS_SPLITBUTTON;
        return CButton::PreCreateWindow(cs);
    }
    
    void CMySplitButton::PreSubclassWindow()
    {
        ModifyStyle(0, BS_SPLITBUTTON);
        CButton::PreSubclassWindow();
    }
    
    void CMySplitButton::OnBnDropDown(NMHDR *pNMHDR, LRESULT *pResult)
    {
        LPNMBCDROPDOWN pDropDown = reinterpret_cast<LPNMBCDROPDOWN>(pNMHDR);
        // Do something here, e.g. show a drop-down menu.
        *pResult = 0;
    }
    If you are using an older SDK (like the one which comes with VS6.0), you can define missing constants and structures as follows:
    Code:
    #ifndef BCN_FIRST
    
    #define BCN_FIRST           (0U-1250U)
    #define BCN_DROPDOWN        (BCN_FIRST + 0x0002)
    #define BS_SPLITBUTTON      0x0000000CL
    #define BS_DEFSPLITBUTTON   0x0000000DL
    
    typedef struct tagNMBCDROPDOWN
    {
        NMHDR   hdr;
        RECT    rcButton;
    } NMBCDROPDOWN, * LPNMBCDROPDOWN;
    
    #endif // BCN_FIRST
    Alternatively and much better, get rid of old VS6.0 and use a newer one. Visual Studio 2008 and newer, comes with a split button control resource and a CSplitButton class which
    do the work for you.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured