适用于嵌入式 “裸奔“ 设计,让大家了解消息如何传递以及如何触发事件
Application.h
#pragma once #include "Container.h" #include "label.h" #include "button.h" #include "EditBox.h"
class Application { CContainer window; Label label1; Label label2; Button button1; Button button2; EditBox edit1;
public: Application(void); void Run() { window.Run(); }
void OnButton1_Pressed(void* sender, int para); void OnButton2_Pressed(void* sender, int para); };
Application.cpp
#include "application.h"
Application::Application(void) { label1.SetRect(10, 2, 20, 1); label2.SetRect(10, 3, 20, 1); button1.SetRect(40, 2, 10, 1); button2.SetRect(40, 6, 10, 1); edit1.SetRect(10, 6, 10, 1); button1.SetText("Button1"); button2.SetText("Button2");
window.AddControl(&label1); window.AddControl(&label2); window.AddControl(&button1); window.AddControl(&button2); window.AddControl(&edit1);
button1.OnEnterKeyPressed.BindingHandler(this, Application::OnButton1_Pressed); button2.OnEnterKeyPressed.BindingHandler(this, Application::OnButton2_Pressed); }
void Application::OnButton1_Pressed(void* sender, int para) { label1.SetText("Test 1"); }
void Application::OnButton2_Pressed(void* sender, int para) { label1.SetText("Test 2"); }
秘密在 window.Run() 里。下面准备详细介绍,同时讲解 c++ 一些主要特性,以及object-oriented design 过程。
|