J
John Doe
Hi,
I am trying to port some C class routines into C++.
THe original functions are use to set/get properties of buttons inside a
toolbar :
// This function is used to set btton text
// Parameters : dwIndexOrId : index or cmd id
// EGetMode : select button by ID or by cmd index
enum EGetMode
{
BY_CMD,
BY_INDEX
};
void SetButtonText(DWORD dwIndexOrId, EGetMode eGetMode)
{
TBBUTTONINFO tbbi;
DWORD dwFlags (eGetMode == BY_INDEX) ? TBIF_BYINDEX : 0;
tbbi.dwMask = TBIF_TEXT | dwFlags;
tbbi.pszText = (LPWSTR) a_szText;
tbbi.cchText = _tcsclen( a_szText );
return ::SendMessage (m_hCB, TB_SETBUTTONINFO, dwIndexOrId, (LPARAM)&tbbi);
}
Since using C++ I wanted to be able to write this :
CxCommandBarCe cmdBar(m_hWndCECommandBar);
cmdBar.GetButton(0, CxCommandBarCe::BY_CMD).SetWindowText(_T("foo"));
so I have coded the class below
So I started with the following class :
class CxCommandBarCe
{
public:
enum EGetMode
{
BY_CMD,
BY_INDEX
};
class CxButtonCe
{
public:
CxButtonCe()
{
ZeroMemory( &m_tbbi, sizeof(m_tbbi) );
m_tbbi.cbSize = sizeof( m_tbbi );
}
BOOL SetWindowText(LPCTSTR a_szText)
{
m_tbbi.dwMask = TBIF_TEXT | m_dwFlags;
m_tbbi.pszText = (LPWSTR) a_szText;
m_tbbi.cchText = _tcsclen( a_szText );
return ::SendMessage (m_hCB, TB_SETBUTTONINFO, m_dwIndexOrId,
(LPARAM)&m_tbbi);
}
void Get(HWND hWndCECommandBar, DWORD dwIndexOrId, EGetMode eGetMode)
{
m_hCB = hWndCECommandBar;
m_dwIndexOrId = dwIndexOrId;
m_dwFlags = (eGetMode == BY_INDEX) ? TBIF_BYINDEX : 0;
}
HWND m_hCB;
DWORD m_dwFlags;
DWORD m_dwIndexOrId;
TBBUTTONINFO m_tbbi;
};
CxCommandBarCe():
m_hCB(NULL),
m_nButtons(0)
{
}
CxCommandBarCe(HWND hWndCECommandBar)
{
m_hCB = hWndCECommandBar;
}
// Buttons
int GetButtonCount()
{
return ::SendMessage(m_hCB, TB_BUTTONCOUNT, 0, 0);
}
CxButtonCe& GetButton(DWORD dwIndexOrId, EGetMode eGetMode)
{
m_btnCe.Get(m_hCB, dwIndexOrId, eGetMode);
return m_btnCe;
}
protected:
HWND m_hCB;
int m_nButtons;
CxButtonCe m_btnCe;
};
I am not very satisified with it, for instance is there any means the
inner class access the m_hCB parent class ?
I find it stupid to duplicate it...
If GetButton fails I am returning a CxButton reference anyway, but how
caller can know it has failed ?
If you have some suggestions I am also all eyes.
I am trying to port some C class routines into C++.
THe original functions are use to set/get properties of buttons inside a
toolbar :
// This function is used to set btton text
// Parameters : dwIndexOrId : index or cmd id
// EGetMode : select button by ID or by cmd index
enum EGetMode
{
BY_CMD,
BY_INDEX
};
void SetButtonText(DWORD dwIndexOrId, EGetMode eGetMode)
{
TBBUTTONINFO tbbi;
DWORD dwFlags (eGetMode == BY_INDEX) ? TBIF_BYINDEX : 0;
tbbi.dwMask = TBIF_TEXT | dwFlags;
tbbi.pszText = (LPWSTR) a_szText;
tbbi.cchText = _tcsclen( a_szText );
return ::SendMessage (m_hCB, TB_SETBUTTONINFO, dwIndexOrId, (LPARAM)&tbbi);
}
Since using C++ I wanted to be able to write this :
CxCommandBarCe cmdBar(m_hWndCECommandBar);
cmdBar.GetButton(0, CxCommandBarCe::BY_CMD).SetWindowText(_T("foo"));
so I have coded the class below
So I started with the following class :
class CxCommandBarCe
{
public:
enum EGetMode
{
BY_CMD,
BY_INDEX
};
class CxButtonCe
{
public:
CxButtonCe()
{
ZeroMemory( &m_tbbi, sizeof(m_tbbi) );
m_tbbi.cbSize = sizeof( m_tbbi );
}
BOOL SetWindowText(LPCTSTR a_szText)
{
m_tbbi.dwMask = TBIF_TEXT | m_dwFlags;
m_tbbi.pszText = (LPWSTR) a_szText;
m_tbbi.cchText = _tcsclen( a_szText );
return ::SendMessage (m_hCB, TB_SETBUTTONINFO, m_dwIndexOrId,
(LPARAM)&m_tbbi);
}
void Get(HWND hWndCECommandBar, DWORD dwIndexOrId, EGetMode eGetMode)
{
m_hCB = hWndCECommandBar;
m_dwIndexOrId = dwIndexOrId;
m_dwFlags = (eGetMode == BY_INDEX) ? TBIF_BYINDEX : 0;
}
HWND m_hCB;
DWORD m_dwFlags;
DWORD m_dwIndexOrId;
TBBUTTONINFO m_tbbi;
};
CxCommandBarCe():
m_hCB(NULL),
m_nButtons(0)
{
}
CxCommandBarCe(HWND hWndCECommandBar)
{
m_hCB = hWndCECommandBar;
}
// Buttons
int GetButtonCount()
{
return ::SendMessage(m_hCB, TB_BUTTONCOUNT, 0, 0);
}
CxButtonCe& GetButton(DWORD dwIndexOrId, EGetMode eGetMode)
{
m_btnCe.Get(m_hCB, dwIndexOrId, eGetMode);
return m_btnCe;
}
protected:
HWND m_hCB;
int m_nButtons;
CxButtonCe m_btnCe;
};
I am not very satisified with it, for instance is there any means the
inner class access the m_hCB parent class ?
I find it stupid to duplicate it...
If GetButton fails I am returning a CxButton reference anyway, but how
caller can know it has failed ?
If you have some suggestions I am also all eyes.