写入文件--cpp构建器 [英] Writing to a file - cpp builder

查看:95
本文介绍了写入文件--cpp构建器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我只是创建了一个计算计算机运行时间的程序。我已经创建了一个时间计数器,但如果您在关闭计算机时可以自动保存Label的内容,则会出现问题(我的意思是该程序将单独保存Label的值,无需用户干预)。我很感激你的帮助。



我的尝试:



我正在寻求帮助,因为我不知道该怎么做。

Hello. I'm just creating a program that's supposed to count how long the computer is on. I have already created a counting of time, but there was a problem if you can save Label's content automatically when you shut down your computer (I mean that the program would save Label's value alone, without user intervention). I would be grateful for help.

What I have tried:

I am asking for help, because I have no idea how to do it.

推荐答案

参见 WM_QUERYENDSESSION消息 - Windows应用程序| Microsoft Docs [ ^ ]。


使用 GetTickCount64函数(sysinfoapi.h)| Microsoft Docs [ ^ ] - 它返回自Windows启动以来的毫秒数。它更加准确,因为Windows中的计时器仅在一段时间后而不是在一段时间内触发。例如,如果你使用计时器来计算秒数,那么当系统繁忙时它们会漂移很大。



请记住,虽然WM_QUERYENDSESSION会告诉你Windows即将关闭,拔出电源线不会有任何影响!
Instead of counting, use GetTickCount64 function (sysinfoapi.h) | Microsoft Docs[^] - it returns the milliseconds since Windows was started. It's a lot more accurate, since timers in Windows only fire "after a time period", not "on a time period". If you use timers to count seconds for example, they will drift quite significantly when the system is busy.

Remember that while WM_QUERYENDSESSION will tell you windows is about to close, it won't have any effect if the power cord is pulled out!


这篇关于写入文件--cpp构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆