如何用 C++ 为 Windows 编写屏幕保护程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5165133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:19:00  来源:igfitidea点击:

How can I write a screen saver for Windows in C++?

c++windowswinapiscreensaverwindows-screensaver

提问by kalani

I want to write a screen saver for Windows using the Windows API. How can I start to write it?

我想使用 Windows API 为 Windows 编写屏幕保护程序。我怎样才能开始写呢?

回答by Holstebroe

Basically a screensaver is just a normal application that accepts a few command line options, provided by windows, to determine if it should start fullscreen or in a preview window.

基本上,屏幕保护程序只是一个普通的应用程序,它接受一些由 Windows 提供的命令行选项,以确定它是应该全屏启动还是在预览窗口中启动。

So, write a normal exe-application that takes the following command line arguments (from http://msdn.microsoft.com/en-us/library/ms686421(v=vs.85).aspx):

因此,编写一个普通的 exe 应用程序,它采用以下命令行参数(来自http://msdn.microsoft.com/en-us/library/ms686421(v=vs.85).aspx):

  • /s – Start the screensaver in full-screen mode.
  • /c – Show the configuration settings dialog box.
  • /p #### – Display a preview of the screensaver using the specified window handle.
  • /s – 以全屏模式启动屏幕保护程序。
  • /c – 显示配置设置对话框。
  • /p #### – 使用指定的窗口句柄显示屏幕保护程序的预览。

Next check out some DirectX / OpenGL / SDL tutorials and write some eye candy.

接下来查看一些 DirectX / OpenGL / SDL 教程并写一些养眼的东西。

Obviously you should check for mouse movements and key presses and exit your application if the user wakes up.

显然,您应该检查鼠标移动和按键,并在用户醒来时退出您的应用程序。

回答by WalterG

Good luck on your search.

希望你能很快找到。

Its better if you can find real screensaver code instead of hacking up something. This way you can work on the screensaver faster.

如果您能找到真正的屏幕保护程序代码而不是破解某些东西,那就更好了。这样您就可以更快地处理屏幕保护程序。

There is more to screensavers than just modified exes. Do you want dual monitor support? How would you do it? Both screens as one big screen or both screens as separate screens?

屏幕保护程序不仅仅是修改过的 exe。你想要双显示器支持吗?你会怎么做?两个屏幕作为一个大屏幕还是两个屏幕作为单独的屏幕?

Opengl does things a bit differently and there are other issues.

Opengl 做的事情有点不同,还有其他问题。

Microsoft had demo code for opengl and directx screensavers, if you want I can find the names because I might have the code on my computer somewhere. Could make your search easier with some project names.

微软有 opengl 和 directx 屏幕保护程序的演示代码,如果你愿意,我可以找到名称,因为我的电脑上可能有代码。可以使用一些项目名称使您的搜索更容易。