当前位置: 首页 > news >正文

C++仿C#实现事件处理

测试
#include "beacon/beacon.hpp"
#include <cstdio>
#include <thread>class mouseEvent : public beacon::args {
public:mouseEvent(int x, int y) : x(x), y(y) {}int x, y;
};class object : public beacon::sender {
public:};class mouseHandler : public beacon::multi_handler {
public:};class Button {
public:void on_event(beacon::sender* sender, beacon::args* args) {auto event = args->to<mouseEvent>();printf("Mouse event at %d, %d\n", event.x, event.y);}
};int main(int argc, char** argv) {mouseEvent event(10, 20);object sender;Button button;mouseHandler handler;handler.addListener<mouseEvent>(beacon::callback::bind(&Button::on_event, &button));handler.raise(&sender, &event);beacon::interval inter;inter.set(1000, [](const char* msg){ puts(msg); }, "Hello, World!");std::this_thread::sleep_for(std::chrono::milliseconds(10000));return 0;
}

g++ example.cpp -o test.exe

输出
Mouse event at 10, 20
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
编译错误

参考 

GitHub - ImanolFotia/beacon: Beacon is a multiparadigm C++ event management library with focus on fast and simple integration

C++ 仿QT信号槽二_c++模仿qt里面的信号与槽,做一个消息不同类消息传递-CSDN博客 

自定义窗口事件循环系统-CSDN博客 


创作不易,小小的支持一下吧!

http://www.lryc.cn/news/426369.html

相关文章:

  • SpringBoot-04--整合登录注册动态验证码
  • Qt如何打包桌面应用程序
  • AI作画提示词工程:技巧与最佳实践
  • Ugandan Knuckles
  • MVI、MVVM、MVP的对比
  • 基于 Flutter 从零开发一款产品(一)—— 跨端开发技术介绍
  • React + Vite项目别名配置
  • FFmpeg编译与配置 - Linux环境
  • MyBatis-Plus 提供的一个通用服务层实现类
  • 41-设计规则:线宽规则
  • 使用MicroApp重构旧项目
  • 【Golang】go mod的使用
  • Linux内核之网络套接字
  • SpringBoot事务-调度-缓存
  • 社交媒体分析:如何利用Facebook的数据提升业务决
  • 企业中的流程组织
  • Redis:查询是否包含某个字符/字符串之二
  • 算法笔记|Day23贪心算法
  • [星瞳科技]OpenMV使用时有哪些常见错误和解决办法?
  • 深度学习入门(二):PyTorch使用-张量的类型转换,拼接操作,索引操作,形状操作
  • 使用C#禁止Windows系统插入U盘(除鼠标键盘以外的USB设备)
  • 18. 基于ES实战海量数据检索
  • SpringBoot和Redis的交互数据操作以及Redis的持久化/删除策略和缓存问题
  • Butterworth filter的运行原理
  • 掌握SQL的威力:批量更新与删除的艺术
  • 《新一代数据可视化分析工具应用指南》正式开放下载
  • 数据结构与算法——BFS(广度优先搜索)
  • 登录 k8s-Dashboard 显示 Your connection is not private
  • 【Bifrost】ubuntu24.04 远程构建及clion设置编码风格google
  • 批量查询全国快递单号:高效追踪物流信息