Basic dialog box input for a strobe light implementation

时光总嘲笑我的痴心妄想 提交于 2019-12-24 07:32:30

问题


I have connected a photographic flash unit to my computer using a relay switch connected to the serial port. The following code causes the strobe to flash at 4Hz for 10 flashes:

#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;
}

How do I implement dialog boxes at the beginning of the program so that the user can input the values of 'freq' and 'iterations'?


回答1:


  1. Open Visual Studio, New, Project, Visual C++, Windows Forms Application. This will give you a GUI where you can drag and drop what you need. If you don't have Visual Studio then perhaps your IDE has something similar?

  2. Make this a console app that accepts the data in the command line. Call the app with an appropriate command line from a GUI created in any other programming language/ framework.

  3. Make the GUI in C# and use P/Invoke to call CreateFile; it's not that hard.

Btw, does the CreateFile/CloseHandle approach really work? I find it to be a bit "hacky" and I'm not sure it's the best approach. Perhaps another answer or a comment will touch this aspect as well.



来源:https://stackoverflow.com/questions/6255445/basic-dialog-box-input-for-a-strobe-light-implementation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!