自己写一个简单的定时器settimer

Windows下定时器SetTimer以及KillTimer的用法 阅读详情


MyTimer.h

#pragma once
#include <process.h>

typedef void (*TimerProCB)(int Handler, void* context);

typedef struct TIMER_PARAM
{
	int Handler;
	void* context;
	TimerProCB timepro;
	unsigned int elapse;
}TIMER_PARAM;

class CMyTimer
{
public:
	CMyTimer(void);
	~CMyTimer(void);

	bool Settimer(TIMER_PARAM param);

	static unsigned int __stdcall WaitPro(void * pParam);
};

MyTimer.cpp

#include "StdAfx.h"
#include "MyTimer.h"



CMyTimer::CMyTimer(void)
{
}


CMyTimer::~CMyTimer(void)
{
}

bool CMyTimer::Settimer(TIMER_PARAM param)
{
	TIMER_PARAM* timeparam= new TIMER_PARAM;
	memcpy(timeparam, ¶m, sizeof(TIMER_PARAM));
	HANDLE hThread = (HANDLE)_beginthreadex(0, 0, WaitPro, (void*)timeparam, 0, 0);
	CloseHandle(hThread);
	return true;
}

unsigned int __stdcall CMyTimer::WaitPro(void * pParam)
{
	TIMER_PARAM* timeparam = (TIMER_PARAM*)pParam;
	Sleep(timeparam->elapse);
	timeparam->timepro(timeparam->Handler, timeparam->context);
	delete timeparam;
	return 0;
}


使用

TIMER_PARAM param;
	param.context = this;
	param.elapse = WAIT_PORT_ELAPSE;
	param.Handler = port;
	param.timepro = TimeProc;
	myTimer.Settimer(param);

TimeProc为回调函数, WAIT_PORT_ELAPSE为等待时间, TIMER_PARAM可以自己定义,自己发挥


Windows:SetTimer定时器编程 摘要: 什么时候我们需要用到SetTimer函数呢? 当你需要每隔一段时间执行一件事的的时候就需要使用SetTimer函数。使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOWS以此时间间隔周期性触发程序。通常有两种方法来实现:发送WM_TIMER消息和调用应用程序定义的回调函数。 Settimer是设置一个计时器并开始执行计时器Ontimer中的代码,Ontim... 阅读详情

相关推荐

MFC定时器SetTimer

什么时候我们需要用到SetTimer函数呢? 当你需要每个一段时间执行一件事的的时候就需要使用SetTimer函数 了。 使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOWS以此时间间隔周期性触发程序。 通常有两种方法来实现:发送WM_TIMER消息和调用应用程序定义的回调函数。 1.1 用WM_TIMER来设置定时器 先请看SetTimer这个API函数的原

大家好,我姓郑,就是那个被鲁智深三拳打死的那个屠夫的郑~_~~_~ 902

C++Windows核心编程读书笔记(转)

http://www.makaidong.com/(马开东博客) 这篇笔记是我在读《windows核心编程》第5版时做的记录和总结(部分章节是第4版的书),没有摘抄原句,包含了很多我个人的思考和对实现的推断,因此不少条款和windows实际机制可能有出入,但应该是合理的。开头几章由于我追求简洁,往往是很多单独的字句,后面的内容更为连贯。   海量细节。 第1章错误处理 1....

weixin_30627381的博客 389

MFC SetTimer用法

什么时候我们需要用到SetTimer函数呢?当你需要每个一段时间执行一件事的的时候就需要使用SetTimer函数了。 使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOWS以此时间间隔周期性触发程序。通常有两种方法来实现:发送WM_TIMER消息和调用应用程序定义的回调函数。 <br />1.1 用WM_TIMER来设置定时器先请看SetTimer这个API函数的原型 UINT_PTR SetTimer(<br />  HWND hWnd,              // 窗口句柄

loonghua1314的专栏 3426

SetTimer()中如何使用TimerProc()

 都是回调函数的错^_^,是回调函数就不要把它定义为一个类的非静态成员!回调函数是基于C编程的Windows SDK的技术,不是针对C++的,我们可以将一个C函数直接作为回调函数,但是如果试图直接使用C++的成员函数作为回调函数将发生错误,甚至编译就不能通过。其原因是普通的C++成员函数都隐含了一个“this”指针,C++通过传递一个指向自身的指针给其成员函数从而实现程序函数可以访问C++

collective的专栏 1万+

MFC定时器SetTimer函数用法总结

CWnd类的SetTimer成员函数只能在CWnd类或其派生类中调用,而API函数SetTimer则没有这个限制,这是一个很重要的区别。 1、启动定时器。 启动定时器就需要使用CWnd类的成员函数SetTimer。CWnd::SetTimer的原型如下: 参数nIDEvent指定一个非零的定时器ID; 参数nElapse指定间隔时间,单位为毫秒; 参数lp

星如雨落 5万+

VB编写的计时器的简单运用

VB刚开始学,自己编写的计时器程序,简单面板,简单的函数

C语言Windows程序设计 -> 第十二天 -> 使用计时器

C语言Windows程序设计 -&gt; 第十二天 -&gt; 使用计时器     传统意义上的计时器是指利用特定的原理来测量时间的装置, 在古代, 常用沙漏、点燃一炷香等方式进行粗略的计时, 在现代科技的带动下, 计时水平越来越高, 也越来越精确, 之所以需要进行计时是在很多情况下我们需要知道时间已经过去了多少, 举例说, 上课下课的打铃、 考试时的计时、车站按时间间隔进行发车等。 不仅在日常...

weixin_34293059的博客 527

X猫免费小说安卓逆向分析

七猫免费小说安卓逆向分析 难度(♥♥) 文章目录七猫免费小说安卓逆向分析 难度(♥♥)1. 查壳2. 抓包分析3. sign1. Frida-rpc2. Native函数分析快3点了. 睡觉~ 白天再继续写! 1. 查壳 我这边使用的是ApkTool, 拖进去显示未加壳。 2. 抓包分析 POST https://xiaoshuo.wtzw.com/api/v1/login/index HTTP/1.1 net-env: 1 channel: qm-cbcpa056_wm is-white: 0 platf

Qiled的博客 4366

第五篇,STM32系统定时器和通用定时器编程

STM32系统定时器和通用定时器编程

weixin_44651073的博客 3743

解密TMS320F28377D双核工程中的内存分配艺术:从CMD文件到实战优化

本文深入解析TMS320F28377D双核DSP的内存管理艺术,从CMD文件配置到实战优化技巧。详细介绍了SARAM、GSRAM等内存类型的特性与配置方法,提供双核协同、性能优化及高级调试的实用方案,帮助开发者提升系统实时性和稳定性。

weixin_29190651的博客 662

Ubuntu使用cmake出现Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed

解决 Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed

qq_44225529的博客 1万+

定时器的三种方法

定时器,就像是Linux系统里的一个贴心小助手。它可以帮你自动完成一些需要在特定时间或每隔一段时间才做的任务。比如,你设定好每天自动备份文件,定时器就会准时帮你完成,无需你每次都手动操作。本文将介绍systemd定时器、crond和at三种定时器使用方法。

博客 3293

Android Qcom USB Driver学习(五)

在前面的第二期中,我们知道一些非标的USB的充电类型Floatingcharger,其具有和普通DCP相似的大电流能力,但在最初检测的时候会限制Inputcurrentlimit到100mA,来进行检测是否是SDP类型,所以要支持大电流输入就需要进行vote操作,前面的几篇都有涉及,所以本文学习一下pmicusbcharger都相关的vote机制。...

Android驱动开发 2900

MFC中如何使用定时器(SetTimer)

定时器是指在软件运行的过程中,在特定的而时间段之后动作。使其产生消息或者回调函数工作,从而实现有一定的功能。 定时器有两种工作方式,一种是通过发送消息,使其WM_TIMER消息动作。另一种是通过回调函数来动作。 主要使用的函数: SetTimer()函数是用来创建定时器的 KillTimer()函数是用来结束定时器的 以下是一个例程: 通过发送消息 1、首先创建定时器,在此例子中定时器是在按钮的点击事件中创建的 void CSetTimerDlg::OnBnClickedButton1() { /

qq_43812868的博客 1万+

SAP-MM:SAP MM(物料管理)模块 的系统化学习计划

SAP MM模块的系统化学习计划

baidu_35680696的博客 1546

泛微OA提交流程到下一个节点

泛微OA后端接口强制流程归档

CXYCMY的博客 2245

[Win32]定时器SetTimer

要调用的地方 SetTimer(g_hMainWnd,ID_GIVEUP,1000,NULL);//会给主窗口发送WM_TIMER消息;1000=1秒;ID_GIVEUP为标识 if (MessageBox(g_hMainWnd,L"确定要退出吗?",L"提示",MB_YESNO)==IDYES) { KillTimer(g_hMainWnd,ID_GIVEUP); //自己的

超越 2073

零基础学simulink仿真建模--基于Simulink进行近端策略优化(PPO)路径规划的仿真建模

特点高效性与稳定性:通过引入剪裁机制,在更新策略时限制步长,从而提高了训练过程的稳定性和效率。适用于多种动作空间:可以处理连续和离散的动作空间问题。无需模型:不需要预先知道环境的确切模型,适合复杂或未知环境。挑战收敛速度与稳定性:确保算法能够在合理的时间内找到近似最优解,并保持训练过程的稳定性。探索与利用平衡:在探索新路径和利用已知信息之间取得平衡。计算资源:对于大规模状态空间和动作空间,计算资源需求较高。首先明确要模拟的任务内容。目标(例如到达指定地点、避开障碍物等)。

amy_mhd的博客 249

SetTimer定时器的用法

什么时候我们需要用到SetTimer函数呢?当你需要每个一段时间执行一件事的的时候就需要使用SetTimer函数了。 使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOWS以此时间间隔周期性触发程序。通常有两种方法来实现:发送WM_TIMER消息和调用应用程序定义的回调函数。  

jiahehao的专栏 3720

华为MetaERP的交易计税模块(即“税务引擎”)在设计上确实受到Oracle E-Business Tax(EBTax)等国际先进税务架构理念的影响,但结合了华为自身全球化运营、多准则合规、高并发处

华为MetaERP税务引擎在借鉴Oracle EBTax三层架构基础上,创新升级为五层智能税务架构,实现从"税码驱动"到"场景+规则+AI驱动"的转变。该模块采用云原生微服务架构,支持全球190+国家税务规则动态加载,具备实时计税、多准则并行处理、AI风险预警等核心能力,深度适配金税工程等国内合规要求。通过税务数字孪生、RPA机器人等创新,形成自主可控的智能税务中枢,为跨国企业提供全栈国产化税务解决方案,重新定义ERP税务管理范式。

金牌架构师 114

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C++-SetTimer定时器

1. Windows定时器是一种周期性的消息产生装置,它会每隔一段指定时间发送一次定时消息WM_TIMER。它是一个很重要的系统消息,当系统所设置的时间到达以后,系统就会自动发送该消息。 与该消息联系密切的函数是SetTimer(),它设置一个系统时钟,当设置的时间到时,系统产生WM_TIMER消息。 通过对SetTimer()函数的参数进行设置,可以告诉用户哪一个时钟的时间到了。因此,可以将一些...

明夷TEC的博客 3340

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

MFC 定时器用法 SetTimer、KillTimer

什么时候我们需要用到SetTimer函数呢?当你需要每个一段时间执行一件事的的时候就需要使用SetTimer函数了。 使用定时器的方法比较简单,通常告诉WINDOWS一个时间间隔,然后WINDOWS以此时间间隔周期性触发程序。通常有两种方法来实现:发送WM_TIMER消息和调用应用程序定义的回调函数。 1.1 用WM_TIMER来设置定时器 先请看SetTimer这个API函数的原型 UI...

雪雪 1304

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

创建定时器SetTimer(1,1000,NULL)

1表示定时器的ID,1000表示没1000ms也就是1s调用一次处理函数,最后一个参数是处理的函数,如果填NULL表示,使用系统默认的,默认处理函数是On Timer()那个函数,在这里面写你要执行的操作就可以了,如果你有多个定时器要在这里写if(id == 1)类似的东西去区分不同的定时器,更换贴图最好是在OnTimer里面更换当前显示的图片编号,然后刷新界面,更换图片的工作让OnPaint去做

xuyuefei1988的专栏 1万+

VC定时器的用法:SetTimer和Ontimer

     Settimer是设置一个计时器并开始执行计时器Ontimer中的代码,Ontimer是计时器所执行的代码。KillTimer用于停止计时器。 Settimer是设置,Ontimer是响应Settimer消息的。SetTimer函数的用法1 )用WM_TIMER来设置定时器先请看SetTimer这个API函数的原型UINT_PTR SetTimer(           

MannHello的专栏 3万+
上一篇: JNI之helloworld
下一篇: Linux目录结构和常用命令
mincheat
博客等级 码龄17年 46粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值