【问题标题】:Basic dialog box input for a strobe light implementation频闪灯实现的基本对话框输入
【发布时间】:2011-06-06 16:59:28
【问题描述】:

我使用连接到串行端口的继电器开关将摄影闪光灯连接到我的计算机。以下代码使频闪灯以 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'和'iterations'的值?

【问题讨论】:

标签: c++ dialog


【解决方案1】:
  1. 打开 Visual Studio,新建项目, Visual C++、Windows 窗体 应用。这会给你一个 GUI,您可以在其中拖放什么 你需要。如果你没有视觉 Studio 那么也许你的 IDE 有 类似的东西?

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

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

顺便说一句,CreateFile/CloseHandle 方法真的有效吗?我发现它有点“hacky”,我不确定这是最好的方法。也许另一个答案或评论也会涉及到这方面。

【讨论】:

    猜你喜欢
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多