📄 messagingtest.cpp
字号:
// MessagingTest.cpp//// test application for the wGui messaging system////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#include "wgui.h"#include <vector>using namespace std;using namespace wGui;class CTestLabel : public CLabel{public: CTestLabel(const CRect& WindowRect, CWindow* pParent) : CLabel(WindowRect, pParent) { CMessageServer::Instance().RegisterMessageClient(this, CMessage::USER); } virtual bool HandleMessage(CMessage* pMessage);};class CTestView : public CView{public: CTestView(void); virtual bool HandleMessage(CMessage* pMessage);protected: CButton* m_pExitButton;};class CTestApp : public CApplication{public: CTestApp(int argc, char **argv) : CApplication(argc, argv) { m_pTestView = 0; } ~CTestApp(void) { delete m_pTestView; } virtual void Init(void) { CApplication::Init(); m_pTestView = new CTestView(); }protected: CTestView* m_pTestView;};bool CTestLabel::HandleMessage(CMessage* pMessage){ bool bHandled = false; if (pMessage) { switch (pMessage->MessageType()) { case CMessage::USER: { TIntMessage* pIntMessage = dynamic_cast<TIntMessage*>(pMessage); if (pIntMessage) { SetWindowText(stdex::itoa(pIntMessage->Value())); pIntMessage->SetValue(pIntMessage->Value() + 1); } } default: bHandled = CLabel::HandleMessage(pMessage); break; } } return bHandled;}CTestView::CTestView(void) : CView(CRect(0, 0, 400, 100), "Messaging Test", true){ SetWindowText(std::string("Messaging Test - wGui version ") + CwgStringResourceHandle(WGRES_VERSION_STRING).String()); m_pExitButton = new CButton(ClientToScreen(CRect(320, 20, 380, 40)), this, "Exit"); new CLabel(ClientToScreen(CRect(20, 20, 300, 40)), this, "Numbers should increment from left to right."); for (int iLeft = 20; iLeft < 340; iLeft += 60) { new CTestLabel(ClientToScreen(CRect(iLeft, 50, iLeft + 40, 70)), this); } CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_LCLICK); // queue the test message CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::USER, 0, 0, 1));}bool CTestView::HandleMessage(CMessage* pMessage){ bool bHandled = false; if (pMessage) { switch (pMessage->MessageType()) { case CMessage::CTRL_LCLICK: { if (pMessage->Destination() == this) { if (pMessage->Source() == m_pExitButton) { CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_EXIT, 0, this)); bHandled = true; } } } default: bHandled = CView::HandleMessage(pMessage); break; } } return bHandled;}int main(int argc, char **argv){ int iExitCode = EXIT_FAILURE; try { CTestApp TestApp(argc, argv); TestApp.Init(); TestApp.Exec(); iExitCode = TestApp.ExitCode(); } catch (Wg_Ex_Base& e) { cerr << "Unhandled wGui exception : " << e.std_what() << endl; exit(EXIT_FAILURE); } catch (exception& e) { cerr << "Unhandled std exception : " << e.what() << endl; exit(EXIT_FAILURE); } catch (...) { cerr << "Unhandled exception." << endl; exit(EXIT_FAILURE); } exit(iExitCode);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -