闪光灯实现的基本对话框输入

Basic dialog box input for a strobe light implementation

本文关键字:对话框 输入 实现 闪光灯      更新时间:2023-10-16

我已经使用连接到串行端口的继电器开关将一个摄影闪光灯连接到我的计算机。以下代码导致闪光灯以4Hz闪烁10次:

#include <windows.h>
//Initialise Windows module
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
 //Define the serial port precedure    
 HANDLE hSerial;
 int freq = 4;
 int iterations = 10;
 int x;
 for ( x = 0; x < iterations; x++)
 {
 //Fire the flash (open the serial port, and immediately close it)
 hSerial = CreateFile("COM1",GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
 CloseHandle(hSerial);
 //Sleep in between flashes for specified duration
 Sleep (1000/freq);
 }
 return 0;
}

如何在程序开始时实现对话框,以便用户可以输入"freq"answers"迭代"的值?

  1. 打开Visual Studio,新建,项目,Visual C++、Windows窗体应用这会给你一个GUI,您可以在其中拖放你需要。如果您没有VisualStudio也许你的IDE类似的东西?

  2. 让它成为一个控制台应用程序,在命令行中接受数据。从以任何其他编程语言/框架创建的GUI中使用适当的命令行调用应用程序。

  3. 在C#中制作GUI,并使用p/Invoke调用CreateFile;没那么难。

顺便说一句,CreateFile/CloseHandle方法真的有效吗?我觉得这有点"古怪",我不确定这是最好的方法。也许另一个答案或评论也会触及这一方面。