Hi

iam trying to make dual function visual c++ button

what I did was http://www.4shared.com/file/105379147/23d04050/dualactionmfcbutton.html

I want it to work can anyone help me ?

Thanks

Dani AI

Generated

A practical approach is to subclass the button control and dispatch clicks to two handlers based on where (or how) the user clicks. That avoids changing dialog wiring or message routing and works whether the second action is a simple function, a popup menu, or a drop-down. Since got the project compiling, the next step is implementing that dispatch inside a custom CButton-derived class; ’s suggestion to keep the project attached makes reproducing the problem simpler for anyone testing fixes.

Implementation outline:

  • Subclass CButton (or add a control member and call SubclassDlgItem/DDX_Control).
  • Decide the trigger: split-area (left/right halves), left vs right mouse button, or click-on-arrow to show a menu.
  • Handle mouse messages (OnLButtonUp, OnRButtonUp). Use GetClientRect and the click CPoint to pick primary vs secondary action.
  • If a visual separator or arrow is desired, set BS_OWNERDRAW and override DrawItem; otherwise simple painting plus a small triangle on the right makes the dual nature clear.
  • For a popup, build a popup menu and call TrackPopupMenu (use ClientToScreen to convert coordinates).

Example skeleton (MFC style):

class CDualButton : public CButton
{
public:
    void DoPrimaryAction();
    void DoSecondaryAction();

protected:
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
    virtual void PreSubclassWindow();
    DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CDualButton, CButton)
    ON_WM_LBUTTONUP()
    ON_WM_RBUTTONUP()
END_MESSAGE_MAP()

void CDualButton::PreSubclassWindow()
{
    ModifyStyle(0, BS_OWNERDRAW);
    CButton::PreSubclassWindow();
}

void CDualButton::OnLButtonUp(UINT nFlags, CPoint point)
{
    CRect r; GetClientRect(&r);
    if (point.x < r.Width()/2)
        DoPrimaryAction();
    else
        DoSecondaryAction(); // or show popup via TrackPopupMenu
    CButton::OnLButtonUp(nFlags, point);
}

void CDualButton::OnRButtonUp(UINT, CPoint)
{
    DoSecondaryAction();
    CButton::OnRButtonUp(0, CPoint());
}

Troubleshooting notes: ensure the control is actually subclassed (DDX_Control or SubclassDlgItem), call the base class mouse handler at the end, use ClientToScreen for popup coordinates, and implement DrawItem when using BS_OWNERDRAW so the control repaints correctly. Keyboard activation (space/enter) should map to the primary action—handle BN_CLICKED or key messages if needed.

Recommended Answers

All 4 Replies

>>I want it to work can anyone help me
Probably not. Attach it to your thread here so people can easily download it. Just hit the Go Advanced button, then the Manage Attachments button.

helo
here is the attached it perform no action when clicked on the button

I changed the function prototype on line 32 of _Double_Task.h, and the actual function on line 224 of _Double_Task.cpp to allow it to compile. Im not sure if this is what you wanted, but stuff happens and it compiles :P

_Double_Task.cpp

_Double_Task.h

Hope this helps.

I tried hard to make

can you add the functionality to let it do dual functions plz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.