#include "stdafx.h" #include "StabtypeControl.h" #include "SRadioBox2.h" namespace SOUI { StabtypeControl::StabtypeControl() { m_evtSet.addEvent(EVENTID(EventTabtypeControl)); } StabtypeControl::~StabtypeControl() { } void StabtypeControl::DestroyWindowcon() { SOUI::SWindow * wins = FindChildByName2(L"con"); if (wins) { //remove all children at first. SWindow *pChild = wins->GetWindow(GSW_FIRSTCHILD); while (pChild) { SWindow *pNext = pChild->GetWindow(GSW_NEXTSIBLING); pChild->DestroyWindow(); pChild = pNext; } } } void StabtypeControl::ItemCreateChildren(int id, SStringW title,bool checked) { SOUI::SWindow * win = FindChildByName2(L"con"); if (win) { //font=\"face:微软雅黑, size : 16\" SOUI::SStringW strXmlName; if (checked) { //US strXmlName.Format(L" \ %s", id, title, id, title); } else { strXmlName.Format(L" \ %s", id, title, id, title); } win->CreateChildren(strXmlName); SOUI::SStringW strbutto; strbutto.Format(L"%d", id); SOUI::SRadioBox2* pButton = FindChildByName2(strbutto); pButton->GetEventSet()->subscribeEvent(SOUI::EVT_CMD, Subscriber(&StabtypeControl::OnBtnClick, this)); } } // 创建控件:初始化 xml,绑定事件等等 int StabtypeControl::OnCreate(LPCREATESTRUCT lpCreateStruct) { pugi::xml_document xmlDoc; SOUI::SStringW strXml = L"tabtype_control"; if (!LOADXML(xmlDoc, strXml, L"LAYOUT")) { return E_FAIL; } pugi::xml_node itemXmlNode = xmlDoc.child(L"tabtypecontrol"); if (!itemXmlNode) { return E_FAIL; } this->CreateChildren(itemXmlNode); return 0; } // 按钮点击响应 bool StabtypeControl::OnBtnClick(SOUI::EventArgs* pEvt) { // 获取按钮名称,获取后缀数字 SOUI::SWindow* pButton = SOUI::sobj_cast(pEvt->sender); SOUI::SStringW strName = pButton->GetName(); //SOUI::SStringW strIndex = strName.Right(1); INT nIndex = _wtoi(strName); // 发送全局的自定义消息 EventTabtypeControl evt(this); evt.nIndex = nIndex; FireEvent(evt); // 激活事件 Fire!!! return true; } }