#include "stdafx.h" #include "ButtonGroup.h" #include ".\weak_business_ctrl\GoodsDlg.h" IMPLEMENT_DYNAMIC(CButtonGroup, CWnd) CButtonGroup::CButtonGroup(void): maxColumn(6) ,xAlign(10) ,yAlign(10) ,width(176) ,height(113) ,x(50) ,y(50) ,groupIndex(0) ,type(0) { } CButtonGroup::~CButtonGroup(void) { for (size_t i = 0; i < pButtons.size(); i++) { delete(pButtons[i]); pButtons[i] = NULL; } } void CButtonGroup::addButton(CString name, UINT nID) { CMyButton* pBtn = new CMyButton; pButtons.push_back(pBtn); CString str; str.Format("%d",pButtons.size()); pBtn->Create("a",WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,getCurRect(pButtons.size()-1),pParent,nID); pBtn->name = name; pBtn->index = pButtons.size() - 1; pBtn->type = type; pBtn->pParent = this; row = pButtons.size() / maxColumn + 1; if (pButtons.size() % maxColumn == 0) { row -= 1; } column = maxColumn; } void CButtonGroup::changeButtonInfo(UINT index, CString name, CString otherInfo) { pButtons[index]->name = name; pButtons[index]->strInfo = otherInfo; ::SendMessage(pButtons[index]->m_hWnd,WM_PAINT,(LPARAM)0,(WPARAM)0); } void CButtonGroup::handleClick(UINT index) { UINT i = groupIndex; pParent->SendMessage(WM_BUTTONGROUP_MSG,groupIndex,index); if (type == 1) { for (size_t i = 0; i < pButtons.size(); i++) { if (i == index) { pButtons[i]->changeColor(TRUE); } else { pButtons[i]->changeColor(FALSE); } } } } void CButtonGroup::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { }