Basic dialog box input for a strobe light implemen

2019-08-03 04:46发布

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'?

标签: c++ dialog
1条回答
我只想做你的唯一
2楼-- · 2019-08-03 05:05
  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.

查看更多
登录 后发表回答