Why the CMFCButton variable is disable

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I created a CDialogBar class named CMyBottomDlgBar, and I droped a button resouce in the dialog, and created a CMFCButton m_btn related to the button.
But why is the m_btn always display as disable?
<pre class="prettyprint" style=" #if !defined(AFX_MyBottomDlgBar_H__3C6B41A8_97B4_441D_9148_B624A74DF364__INCLUDED_)
#define AFX_MyBottomDlgBar_H__3C6B41A8_97B4_441D_9148_B624A74DF364__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyBottomDlgBar.h : header file
//

#include "resource.h"

/////////////////////////////////////////////////////////////////////////////
// CMyBottomDlgBar dialog

class CMyBottomDlgBar : public CDialogBar
{
// Construction
public:
CMyBottomDlgBar(); // standard constructor

// Dialog Data
//{{AFX_DATA(CMyBottomDlgBar)
enum { IDD = IDD_DIALOG_BOTTOMBAR };
CMFCButton m_btn;

//}}AFX_DATA


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyBottomDlgBar)
public:
virtual BOOL Create(CWnd* pParent, UINT nIDTemplate, UINT nStyle, UINT nID);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CMyBottomDlgBar)
afx_msg LONG OnInitDialog ( UINT, LONG );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MyBottomDlgBar_H__3C6B41A8_97B4_441D_9148_B624A74DF364__INCLUDED_)[/code]
<br/>
<pre class="prettyprint" style=" // MyBottomDlgBar.cpp : implementation file
//

#include "stdafx.h"
#include "commctrl.h"
#include "MyBottomDlgBar.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyBottomDlgBar dialog


CMyBottomDlgBar::CMyBottomDlgBar()
{
//{{AFX_DATA_INIT(CMyBottomDlgBar)
//}}AFX_DATA_INIT
}


void CMyBottomDlgBar::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyBottomDlgBar)
DDX_Control(pDX, IDC_BUTTON, m_btn);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyBottomDlgBar, CDialogBar)
//{{AFX_MSG_MAP(CMyBottomDlgBar)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_INITDIALOG, OnInitDialog )
ON_WM_NCHITTEST()
ON_WM_SIZE()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyBottomDlgBar message handlers

LONG CMyBottomDlgBar::OnInitDialog ( UINT wParam, LONG lParam)
{

BOOL bRet = HandleInitDialog(wParam, lParam);

if (!UpdateData(FALSE))
{
TRACE0("Warning: UpdateData failed during dialog init.n");
}
return bRet;

//::IsolationAwareInitCommonControls();
}


BOOL CMyBottomDlgBar::Create(CWnd* pParent, UINT nIDTemplate, UINT nStyle, UINT nID)
{
// TODO: Add your specialized code here and/or call the base class

BOOL bReturn = CDialogBar::Create(pParent, nIDTemplate, nStyle, nID);


return bReturn;
}

LRESULT CMyBottomDlgBar::OnNcHitTest(CPoint point)
{
//return CDialogBar::OnNcHitTest(point);
return 0;
}

void CMyBottomDlgBar::OnSize(UINT nType, int cx, int cy)
{
CDialogBar::OnSize(nType, cx, cy);

CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);

CRect ctrlRect;

if (m_btn.m_hWnd)
{
m_btn.GetWindowRect(&ctrlRect);
ScreenToClient(&ctrlRect);
m_btn.MoveWindow(rect.Width()-ctrlRect.Width()-20, ctrlRect.top, ctrlRect.Width(), ctrlRect.Height());
}

}[/code]
<br/>

<
Never give in or give up. Stay healthy and help others.
<br/>

View the full article
 
Back
Top