Can anyone please tell me what is wrong with this code? When I debug it, it
sometimes generate error at the line v[i] = i; in RunProcesses().
Thanks,
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Hor_Slider.H>
#include <FL/math.h>
#include <FL/Fl_Int_Input.h>
#include <FL/Fl_Output.h>
#include <FL/Fl_Button.h>
#include <FL/Fl_Check_Button.h>
#include <FL/fl_ask.H>
#include <stdio.h>
#include <cstdlib>
#include <process.h>
#include <windows.h>
#include "aclapi.h"
Fl_Output* output_2;
Fl_Output* output_3;
Fl_Window *window_2;
Fl_Window *window_3;
Fl_Int_Input *idIniOrder;
Fl_Output *cb_infoN;
Fl_Button *start;
Fl_Check_Button *check1;
Fl_Check_Button *check2;
int processID = 0;
int processAC = 0;
const int numThreads = 2;
HANDLE threadArray[numThreads];
HANDLE driveSystemEvent;
HANDLE systemIDEvent;
int v[100000];
static void start_cb(Fl_Button *b, void *p);
static void check1_cb(Fl_Button *b, void *p)
{
processID = check1->value();
}
static void check2_cb(Fl_Button *b, void *p)
{
processAC = check2->value();
}
void plot_cb(void *p)
{
char msg[256];
int *data = (int*)p;
sprintf(msg, "%d", *data);
Fl::lock(); //
Obtain a lock before we access the browser widget...
output_2->value(msg);
output_2->redraw();
Fl::unlock(); // Release the
lock...
Fl::awake();
}
void make_first_window()
{
char tmp_s[10] = "19";
start = new Fl_Button(1,1,65,20, "&Start");
start->callback( (Fl_Callback*) start_cb );
start->labelsize(14);
start->tooltip("Save parameters and run close loop");
check1 = new Fl_Check_Button(1, 40, 65, 20," System ID");
check1->when(FL_WHEN_CHANGED);
check1->labelsize(13);
check1->callback((Fl_Callback*) check1_cb);
check2 = new Fl_Check_Button(1, 70, 65, 20," PFF AC");
check2->when(FL_WHEN_CHANGED);
check2->labelsize(13);
check2->callback((Fl_Callback*) check2_cb);
}
void window_1_cb(Fl_Widget *o, void *p) {
exit(0);
}
void window_2_cb(Fl_Widget *o, void *p) {
exit(0);
}
unsigned WINAPI RunProcesses(LPVOID lpParam)
{
int i;
for (i=0; i<100000; i++)
{
v[i] = i;
Fl::awake(plot_cb, (void*)&v[i]);
}
return (unsigned)1;
}
static void start_cb(Fl_Button *b, void *p)
{
unsigned threadID;
char msg[256];
sprintf(msg, "%s", "");
Fl::lock(); // Obtain a lock before we
access the browser widget...
output_3->value(msg);
output_3->redraw();
Fl::unlock(); // Release the lock...
Fl::awake();
if (processID)
{
window_3->show();
threadArray[0] = (HANDLE)_beginthreadex(NULL, 0, &RunProcesses,
NULL, CREATE_SUSPENDED, &threadID);
if ( threadArray[0] == 0 )
printf("Failed to create thread 1\n");
ResumeThread(threadArray[0]);
}
}
int main(int argc, char **argv) {
Fl::lock();
Fl_Window *window = new Fl_Window(100, 100, 200, 100, "1 Window");
window->begin();
make_first_window();
window->callback(window_1_cb);
window->end();
window->show(argc,argv);
window_3 = new Fl_Window(100, 400, 200, 100, "3 Window");
window_3->begin();
output_3 = new Fl_Output(10,10, 100, 25);
output_3->color(FL_BACKGROUND_COLOR);
output_3->labelsize(14); // 14 is default
output_3->type(14);
output_3->textsize(14);
window_3->end();
window_3->hide();
window_3->resizable(window_2);
WaitForMultipleObjects(2, threadArray, TRUE, INFINITE );
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk