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
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
>>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.
// _Double_Task.cpp : implementation file
//
#include "stdafx.h"
#include "hashi.h"
#include "_Double_Task.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// C_Double_Task
C_Double_Task::C_Double_Task()
{
}
C_Double_Task::~C_Double_Task()
{
}
BEGIN_MESSAGE_MAP(C_Double_Task, CButton)
//{{AFX_MSG_MAP(C_Double_Task)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// C_Double_Task message handlers
BOOL C_Double_Task::OnRight()
{
return IsRight;
}
void C_Double_Task::OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
CRect ButtonRect ;
GetClientRect(ButtonRect) ;
m_previous_Mode =m_present_mode ;
m_present_mode =PLUS_DOWN ;
IsRight = FALSE ;
if(point.x > ButtonRect.right/2){
m_previous_Mode =m_present_mode ;
m_present_mode =MINUS_DOWN ;
IsRight = TRUE ;
}
CButton::OnLButtonDown(nFlags, point);
}
void C_Double_Task::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect upRect ;
GetClientRect(upRect) ;
CRect rect_left = upRect ;
rect_left .right = upRect.right/2 ;
if(PtInRect(upRect,point)){
if(PtInRect(rect_left,point )){
m_previous_Mode =m_present_mode ;
m_present_mode =PLUS_OVER ; ReleaseCapture();
}
else {
m_previous_Mode =m_present_mode ;
m_present_mode =MINUS_HOVER ;ReleaseCapture();
}
}
else {
m_previous_Mode =m_present_mode ;
m_present_mode =NORMAL ;ReleaseCapture();
}
CButton::OnLButtonUp(nFlags, point);
}
void C_Double_Task::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rec_total ;
GetClientRect(rec_total) ;
CRect Rec_right = rec_total ;
Rec_right.left = rec_total.right/2 ;
CRect Rct_left = rec_total;
Rct_left.right =rec_total.right/2 ;
if( PtInRect( rec_total ,point )){
if( PtInRect( Rec_right ,point )){
m_previous_Mode =m_present_mode ;
m_present_mode =MINUS_HOVER ;
Invalidate(FALSE) ;
}
else {
m_previous_Mode =m_present_mode ;
m_present_mode =PLUS_OVER ;
Invalidate(FALSE) ;
}
}
else if((m_previous_Mode == PLUS_DOWN || m_previous_Mode ==MINUS_DOWN) && PtInRect(Rec_right ,point)){
m_previous_Mode =m_present_mode ;
m_present_mode =MINUS_DOWN ;
}
else if((m_previous_Mode == PLUS_DOWN || m_previous_Mode ==MINUS_DOWN) && PtInRect(Rct_left ,point)){
m_previous_Mode =m_present_mode ;
m_present_mode =PLUS_DOWN ;
}
else{
m_previous_Mode =m_present_mode ;
m_present_mode =NORMAL ; Invalidate(FALSE) ;
}
TRACKMOUSEEVENT tn_Events ;
tn_Events.cbSize =sizeof(TRACKMOUSEEVENT) ;
tn_Events.dwFlags = TME_LEAVE ;
tn_Events.hwndTrack= m_hWnd ;
_TrackMouseEvent(&tn_Events) ;
CButton::OnMouseMove(nFlags, point);
}
BOOL C_Double_Task::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
void C_Double_Task::DrawItem(LPDRAWITEMSTRUCT lp_Draw_Items_Struct)
{
CDC *pMyDC =CDC::FromHandle(lp_Draw_Items_Struct->hDC);
CDC memDC_item ;
memDC_item.CreateCompatibleDC(pMyDC);
CBitmap* p_bitmap_mfc ;
switch(m_present_mode) {
// or use if statements
// NORMAL ,MINUS_HOVER ,MINUS_DOWN,PLUS_OVER,PLUS_DOWN
// m_bmp_normal_pic ,m_bmp_subtract_hover ,m_bitmap_subtract_down,m_bt_addition_hover ,m_bmp_addition_pushed;
case NORMAL :
p_bitmap_mfc = memDC_item.SelectObject( &m_bmp_normal_pic);
break ;
case MINUS_HOVER :
p_bitmap_mfc = memDC_item.SelectObject( &m_bmp_subtract_hover);
break ;
case MINUS_DOWN :
p_bitmap_mfc = memDC_item.SelectObject( &m_bitmap_subtract_down);
break ;
case PLUS_OVER :
p_bitmap_mfc = memDC_item.SelectObject( &m_bt_addition_hover);
break ;
case PLUS_DOWN :
p_bitmap_mfc = memDC_item.SelectObject( &m_bmp_addition_pushed);
break ;
}
pMyDC->BitBlt( 0,0, lp_Draw_Items_Struct->rcItem.right -lp_Draw_Items_Struct->rcItem.left ,lp_Draw_Items_Struct->rcItem.bottom -lp_Draw_Items_Struct->rcItem.top ,&memDC_item ,0,0,SRCCOPY);
memDC_item.SelectObject(p_bitmap_mfc) ;
memDC_item.DeleteDC();
}
BOOL C_Double_Task::IsOver(CRect &rct, CPoint &pt)
{
return ( pt.x>0 && (pt.x< rct.right-rct.left)&&pt.y > 0 && (pt.y< rct.bottom-rct.top))?TRUE:FALSE ;
// simple form of c++ conditional return
}
C_Double_Task::C_Double_Task(int nornel, int negative_over, int neg_dowm, int plus_hovrt, int plus_pressed)
{
m_present_mode =NORMAL ;
// ,m_bmp_subtract_hover ,m_bitmap_subtract_down,m_bt_addition_hover ,m_bmp_addition_pushed;
m_bmp_normal_pic.LoadBitmap(nornel) ;
m_bmp_subtract_hover.LoadBitmap(negative_over) ;
m_bitmap_subtract_down.LoadBitmap(neg_dowm) ;
m_bt_addition_hover.LoadBitmap(plus_hovrt);
m_bmp_addition_pushed.LoadBitmap(plus_pressed) ;
// five parameters constructor
}
// NORMAL ,MINUS_HOVER ,MINUS_DOWN,PLUS_OVER,PLUS_DOWN
LRESULT C_Double_Task::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
m_previous_Mode =m_present_mode ;
m_present_mode =NORMAL ; Invalidate() ;
return 0;
}
#if !defined(AFX__DOUBLE_TASK_H__CA7CF1D9_6392_4B5C_B458_1371288DC7D5__INCLUDED_)
#define AFX__DOUBLE_TASK_H__CA7CF1D9_6392_4B5C_B458_1371288DC7D5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// _Double_Task.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// C_Double_Task window
class C_Double_Task : public CButton
{
// Construction
public:
C_Double_Task();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_Double_Task)
public:
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_VIRTUAL
// Implementation
public:
LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
C_Double_Task(int nornel , int negative_over , int neg_dowm, int plus_hovrt ,int plus_pressed);
BOOL IsOver(CRect &rct,CPoint &pt);
BOOL OnRight();
BOOL IsRight;
CBitmap m_bmp_normal_pic ,m_bmp_subtract_hover ,m_bitmap_subtract_down,m_bt_addition_hover ,m_bmp_addition_pushed;
enum Btn_Condition{ NORMAL ,MINUS_HOVER ,MINUS_DOWN,PLUS_OVER,PLUS_DOWN} ;
Btn_Condition m_previous_Mode ,m_present_mode ;
virtual ~C_Double_Task();
// Generated message map functions
protected:
//{{AFX_MSG(C_Double_Task)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX__DOUBLE_TASK_H__CA7CF1D9_6392_4B5C_B458_1371288DC7D5__INCLUDED_)
I tried hard to make
can you add the functionality to let it do dual functions plz
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.