Programming a strobe light with C++ - create a frequency dialog box
<p>Hi: I have connected a photographic flash gun to my PC using a relay switch connected via the serial port. The following program successfully fires the flash as a strobe:</p>

<pre><code>#include &lt;windows.h&gt;

//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 &lt; 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;
}
</code></pre>

<p>What I would like to do is have the flash fire at a frequency defined by the user (in Hz). Basically, this program, plus a dialog box that allows the user to choose values for 'freq' and 'iterations' before the thing starts flashing.</p>

<p>I have successfully implemented dialog boxes in previous projects by including the following code at the start of my main.c file:</p>

<pre><code>#ifdef WIN32
#include &lt;w32_dialogs.h&gt;
#endif
</code></pre>

<p>And using something along these lines where the actual dialog box should occur:</p>

<pre><code>#ifdef WIN32
    edit_dialog(NULL,"Dialog Title", "Please enter variable:", variable,260);
#endif#
</code></pre>

<p>So, based on this, I have updated the code to the following:</p>

<pre><code>#include &lt;windows.h&gt;

#ifdef WIN32
#include &lt;w32_dialogs.h&gt;
#endif

//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;

 //Buffers for variable entry into text box  
 char freq_buf[256];
 char iterations_buf[256];

 //Convert dialog buffer to useable values
 sprintf( freq_buf, "%lf", freq);
 sprintf( iterations_buf, "%lf", iterations);

 #ifdef WIN32
        edit_dialog(NULL,"Enter frequency", "Please enter frequency:", freq_buf,260);
 #endif#

 #ifdef WIN32
        edit_dialog(NULL,"Enter iterations", "Please enter number of iterations:", iterations_buf,260);
 #endif#

 freq = atoi(freq_buf);
 iterations = atoi(iterations_buf);

 for ( x = 0; x &lt; 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;
}
</code></pre>

<p>However, this does not compile. I am using Dev-C++ (I usually use VC++ but couldnt get it to work there either)</p>

<p>The errors are: - 'w32_dialogs.h': no such file or directory; 'sprintf' is undeclared; and 'edit_dialog' is undeclared.</p>

<p>It looks to me that this is a simple case of not being able to find the w32_dialogs.h file. How do I set this up in Dev-C++?</p>
