Example #1
0
void write_captfile(unsigned char actbyte)
{
	DWORD dwWritten;
	 char buf[10];

	switch (CAPTFILE.filetype)
	{
	  case FILE_TEXTMODE:
	      wsprintf(buf, "%d, ", (int) actbyte);
		  while (strlen(buf)<5) strcat(buf," ");
		  if (++GLOBAL.actcolumn==TTY.bytes_per_packet)
		  { 
			strcat (buf,"\r\n ");
			GLOBAL.actcolumn=0;
		  }
		  if (!WriteFile(CAPTFILE.filehandle,buf,strlen(buf), &dwWritten, NULL))  
		  {    report_error("Could not write to Archive"); 
		       close_captfile();
		  }
		  break;
	  case FILE_INTMODE:
		  buf[0]=actbyte;
		  if (!WriteFile(CAPTFILE.filehandle,buf,1, &dwWritten, NULL))  
		  {   report_error("Could not write to Archive"); 
		      close_captfile(); 
		  }
		  break;
	}
}
Example #2
0
BOOL load_configfile(LPCTSTR pszFileName)
{

    HANDLE hFile;
	int t, act_samplingrate=DEF_PACKETSPERSECOND; 
	int act_type,num_objects, save_toolbox, save_connected, try_connect;
	const char * d_name;
	char new_name[256],szdata[20];

	write_logfile("loading design configuration: %s",(char *)pszFileName);

    hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if(hFile != INVALID_HANDLE_VALUE)
    {
		GLOBAL.loading=1;
		d_name=pszFileName;
		while (strstr(d_name,"\\")) d_name=strstr(d_name,"\\")+1;
		strcpy(new_name,"BrainBay - ");strcat(new_name,d_name);
	    SetWindowText(ghWndMain,new_name);
		strcpy(GLOBAL.configfile,pszFileName);
		save_settings();
		save_toolbox=-1;

		save_connected=TTY.CONNECTED;
		SendMessage(ghWndStatusbox,WM_COMMAND, IDC_STOPSESSION,0);
		
		//TTY.read_pause=1;
		close_captfile();

		if (ghWndAnimation!=NULL) SendMessage(ghWndAnimation,WM_CLOSE,0,0);
		ghWndAnimation=NULL;

		close_toolbox();actobject=NULL;
		//InvalidateRect(ghWndMain, NULL, TRUE);

		while (GLOBAL.objects>0)
		    free_object(0);

		GLOBAL.run_exception=0;
		GLOBAL.minimized=FALSE;

	     load_next_config_buffer(hFile);
		 load_property("objects",P_INT,&GLOBAL.objects);
		 load_property("main-top",P_INT,&GLOBAL.top);
		 load_property("main-left",P_INT,&GLOBAL.left);
		 load_property("main-right",P_INT,&GLOBAL.right);
		 load_property("main-bottom",P_INT,&GLOBAL.bottom);
		 load_property("anim-top",P_INT,&GLOBAL.anim_top);
		 load_property("anim-left",P_INT,&GLOBAL.anim_left);
		 load_property("anim-right",P_INT,&GLOBAL.anim_right);
		 load_property("anim-bottom",P_INT,&GLOBAL.anim_bottom);
		 load_property("design-top",P_INT,&GLOBAL.design_top);
		 load_property("design-left",P_INT,&GLOBAL.design_left);
		 load_property("design-right",P_INT,&GLOBAL.design_right);
		 load_property("design-bottom",P_INT,&GLOBAL.design_bottom);
		 load_property("tool-top",P_INT,&GLOBAL.tool_top);
		 load_property("tool-left",P_INT,&GLOBAL.tool_left);
		 load_property("tool-right",P_INT,&GLOBAL.tool_right);
		 load_property("tool-bottom",P_INT,&GLOBAL.tool_bottom);
		 load_property("showdesign",P_INT,&GLOBAL.showdesign);
		 load_property("hidestatus",P_INT,&GLOBAL.hidestatus);
		 load_property("showtoolbox",P_INT,&GLOBAL.showtoolbox);
		 load_property("autorun",P_INT,&GLOBAL.autorun);
		 load_property("minimized",P_INT,&GLOBAL.minimized);
		 save_toolbox=GLOBAL.showtoolbox;


		 TTY.PORT=0;try_connect=0;
		 load_property("comport",P_INT,&TTY.PORT);		 
		 load_property("connected",P_INT,&try_connect);	 
		 load_property("bidirect",P_INT,&TTY.BIDIRECT);
		 load_property("devicetype",P_INT,&TTY.devicetype);
		 load_property("samplingtype",P_INT,&TTY.samplingrate);
		 load_property("baudtype",P_INT,&TTY.BAUDRATE);
		 load_property("flow_control",P_INT,&TTY.FLOW_CONTROL);

		 if (save_connected) { update_p21state(); save_connected=TTY.CONNECTED; }
		 BreakDownCommPort();  
		 if (try_connect) { TTY.CONNECTED=SetupCommPort(TTY.PORT); update_p21state(); }
		
		 load_property("captfilename",P_STRING,CAPTFILE.filename);
		 load_property("captfiletype",P_INT,&CAPTFILE.filetype);
		 load_property("captfileoffset",P_INT,&CAPTFILE.offset);
	 	 load_property("dialoginterval",P_INT,&GLOBAL.dialog_interval);
		 load_property("drawinterval",P_INT,&GLOBAL.draw_interval);
		 load_property("samplingrate",P_INT,&act_samplingrate);
		 PACKETSPERSECOND=act_samplingrate;

		 MoveWindow(ghWndMain,GLOBAL.left,GLOBAL.top,GLOBAL.right-GLOBAL.left,GLOBAL.bottom-GLOBAL.top,TRUE);
		 MoveWindow(ghWndDesign,GLOBAL.design_left,GLOBAL.design_top,GLOBAL.design_right-GLOBAL.design_left,GLOBAL.design_bottom-GLOBAL.design_top,TRUE);
		 if (!GLOBAL.showdesign)
		 {  
			 ShowWindow(ghWndDesign, FALSE); 
			 SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Show Design"); 
		 }
		 else 
		 {
			 ShowWindow(ghWndDesign,TRUE);
		     SetWindowPos(ghWndDesign,0,0,0,0,0,SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE);
			 SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Hide Design"); 
		 }
		 if (!GLOBAL.hidestatus)
		 	 ShowWindow(ghWndStatusbox, TRUE); 
		 else	 ShowWindow(ghWndStatusbox,FALSE);
		     
		 num_objects=GLOBAL.objects;
		 GLOBAL.objects=0;
   		 for (t=0;t<num_objects;t++)
		 {
			act_type=load_next_config_buffer(hFile);
			if (act_type>=0)
			{	
				create_object(act_type);
				if (actobject != NULL )
				{
					actobject->load(hFile);
					link_object(actobject);
				}
				else critical_error("Could not load all objects, quitting ...\ndelete brainbay.cfg to prevent this at program startup ... ");

			}
		 }
		 CloseHandle(hFile);
		 for (t=0;t<num_objects;t++) objects[t]->update_inports();
		 update_dimensions();

		 CAPTFILE.filehandle=INVALID_HANDLE_VALUE;
		 CAPTFILE.do_read=0;
		 if (strcmp(CAPTFILE.filename,"none"))
		 {
			 char st[150];
			 reduce_filepath(st,CAPTFILE.filename);
			 strcpy(CAPTFILE.filename,GLOBAL.resourcepath);
			 strcat(CAPTFILE.filename,"ARCHIVES\\");
			 strcat(CAPTFILE.filename,st);			 
			 open_captfile(CAPTFILE.filename);
		 }

		 init_system_time();
		 reset_oscilloscopes();
		 PACKET.readstate=0;
		 ShowWindow( ghWndMain, TRUE ); UpdateWindow( ghWndMain ); 

 		 update_samplingrate(act_samplingrate);
		 update_devicetype();
		 get_session_length();


		 SetDlgItemInt(ghWndStatusbox,IDC_SAMPLINGRATE,act_samplingrate,0);
		 SetDlgItemText(ghWndStatusbox,IDC_STATUS,"Configuration loaded");
		 SetDlgItemText(ghWndStatusbox,IDC_TIME,"0.0");
		 SetDlgItemText(ghWndStatusbox,IDC_JUMPPOS,"0.0");
		 sprintf(szdata, "%.1f", (float)GLOBAL.session_length/(float)PACKETSPERSECOND);
		 SetDlgItemText(ghWndStatusbox,IDC_SESSLEN,szdata);
 		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)0);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,(LONG)0);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,(LONG)0);

		 SetWindowPos(ghWndMain,0,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		 InvalidateRect(ghWndMain,NULL,TRUE);
 		 InvalidateRect(ghWndDesign,NULL,TRUE);

		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,0);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,1000);
		 SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)(0));
		 if (GLOBAL.minimized) ShowWindow(ghWndMain, SW_MINIMIZE);

		 GLOBAL.loading=0;
		 if ((GLOBAL.autorun) && (!GLOBAL.run_exception)) SendMessage(ghWndStatusbox,WM_COMMAND, IDC_RUNSESSION,0);
  	    
		 if (save_toolbox!=-1)
		 {
			GLOBAL.showtoolbox=save_toolbox;
			actobject=objects[GLOBAL.showtoolbox];
			actobject->make_dialog();
		 } 
		 
		write_logfile("load successful");
		return TRUE;
		 
    }
	write_logfile("could not load design configuration file.");
	return FALSE;    	
}
Example #3
0
//
//  function: MainWndHandler(HWND, unsigned, WORD, LONG)
//
//  purpose:	make initialisations (globals, Def-TTY settings)
//				create Toolbox Dialog
//
//			    process  Menu Selections
//					load/save Config
//					play/capture Archive 
//					open midi-device
//					change com settings
//					connect/disconnect to EEG-amp
//					load/save Config
//
//				scale and paint the channel-oscilloscope
//
//
//
LRESULT CALLBACK MainWndHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	char sztemp[256];
    
	switch( message ) 
	{

	 case WM_CREATE:
		break;

	 case WM_ENABLE:
		 if ((wParam==TRUE) && (NB_OBJ != NULL)) 
		 {
			 NB_OBJ->update_channelinfo();
			 NB_OBJ=NULL;
		 }
		 break;

	 case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Menüauswahlen analysieren:
			switch( wmId ) 
			{

				case IDM_NEWCONFIG:
					stop_timer();
					TTY.read_pause=1;
					//BreakDownCommPort();
					CAPTFILE.do_read=0;
					close_captfile();

					if (ghWndAnimation!=NULL) SendMessage(ghWndAnimation,WM_CLOSE,0,0);
					ghWndAnimation=NULL;
					close_toolbox();

	 		   	    write_logfile("new config: deleting all objects.");
					while (GLOBAL.objects>0)
						free_object(0);

					deviceobject=NULL;
					GLOBAL.showdesign=TRUE;
					ShowWindow(ghWndDesign,TRUE);
				    SetWindowPos(ghWndDesign,HWND_TOP,0,0,0,0,SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE);
					SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Hide Design"); 
					GLOBAL.hidestatus=FALSE;
					ShowWindow(ghWndStatusbox,TRUE);
				    SetWindowText(ghWndMain,"BrainBay");
					GLOBAL.configfile[0]=0;
					init_system_time();	PACKET.readstate=0;
					GLOBAL.session_length=0;
					SetDlgItemText(ghWndStatusbox,IDC_STATUS,"ready.");
					SetDlgItemInt(ghWndStatusbox,IDC_SAMPLINGRATE,PACKETSPERSECOND,0);
					SetDlgItemText(ghWndStatusbox,IDC_STATUS,"Configuration loaded");
					SetDlgItemText(ghWndStatusbox,IDC_TIME,"0.0");
					SetDlgItemText(ghWndStatusbox,IDC_JUMPPOS,"0.0");
					SetDlgItemText(ghWndStatusbox,IDC_SESSLEN,"0.0");
 					SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)0);
					SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,(LONG)0);
					SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,(LONG)0);

 					InvalidateRect(ghWndDesign,NULL,TRUE);
					InvalidateRect(ghWndMain,NULL,TRUE);
					break;

				case IDM_SAVECONFIG:
					{ 
						char configfilename[MAX_PATH];
						int save_toolbox=GLOBAL.showtoolbox;

						close_toolbox();
						GLOBAL.showtoolbox=save_toolbox;
						strcpy(configfilename,GLOBAL.resourcepath); 
						if (GLOBAL.configfile[0]==0)
  						  strcat(configfilename,"CONFIGURATIONS\\*.con");
						else strcpy(configfilename,GLOBAL.configfile);
						if (open_file_dlg(hWnd,configfilename, FT_CONFIGURATION, OPEN_SAVE))
						{
						   if (!save_configfile(configfilename))  report_error("Could not save Config File");
						   else
						   {
							  char * d_name,new_name[80];
		  	 		   	      write_logfile("configruation saved.");

							  d_name=configfilename;
							  while (strstr(d_name,"\\")) d_name=strstr(d_name,"\\")+1;
							  strcpy(new_name,"BrainBay - ");strcat(new_name,d_name);
							  SetWindowText(ghWndMain,new_name);
						   }
						}
						if (GLOBAL.showtoolbox!=-1)
						{	
							actobject=objects[GLOBAL.showtoolbox];
							actobject->make_dialog();
						}
					}
					break;
				case IDM_LOADCONFIG:
					{ 
						char configfilename[MAX_PATH];
						close_toolbox();
						strcpy(configfilename,GLOBAL.resourcepath); 
						strcat(configfilename,"CONFIGURATIONS\\*.con");
						if (open_file_dlg(hWnd,configfilename, FT_CONFIGURATION, OPEN_LOAD))
						{
			 		   	    write_logfile("load config: free existing objects.");
							if (!load_configfile(configfilename)) report_error("Could not load Config File");
							else sort_objects();
						}
					
					}
					break;

				case IDM_ABOUT:
					close_toolbox();
				    DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)AboutDlgHandler);
					break;

				case IDM_HELP:
					{
						char tmpfile [250];
						close_toolbox();
						strcpy(tmpfile,GLOBAL.resourcepath);
						strcat(tmpfile,"brainbay_user_manual.pdf");
						ShellExecute(0, "open", tmpfile, NULL, NULL, SW_SHOWNORMAL);
					}
					break;
				case IDM_VIEWLASTLOGFILE:
					{
						char tmpfile [250];
						close_toolbox();
						strcpy(tmpfile,GLOBAL.resourcepath);
						strcat(tmpfile,"bbay.log");
						ShellExecute(0, "open", tmpfile, NULL, NULL, SW_SHOWNORMAL);
					}

					break;
				case IDM_EXIT:	
					DestroyWindow( hWnd );
				    break;
                
				case IDM_PLAY:	
						SendMessage(ghWndStatusbox,WM_COMMAND, IDC_RUNSESSION,0);
				    break;
				case IDM_STOP:			
						SendMessage(ghWndStatusbox,WM_COMMAND, IDC_STOPSESSION,0);
				    break;

				case IDM_NEUROSERVER:
						strcpy(sztemp,GLOBAL.resourcepath); 
						strcat(sztemp,"NETWORK\\nsd.exe");
						ShellExecute(hWnd, "open", sztemp, NULL, NULL, SW_SHOWNORMAL);
						break;
				case IDM_READEDF:
						{
							char edffilename[MAX_PATH];
							close_toolbox();
							strcpy(edffilename,GLOBAL.resourcepath); 
							strcat(edffilename,"ARCHIVES\\*.edf");
							if (open_file_dlg(hWnd,edffilename, FT_EDF, OPEN_LOAD))
							{
								strcpy(sztemp,GLOBAL.resourcepath); 
								strcat(sztemp,"NETWORK\\readedf.exe");
								ShellExecute(hWnd, NULL, sztemp, edffilename, NULL, SW_SHOWNORMAL);
							}
						}
						break;
				case IDM_EDITCOLORS:
					close_toolbox();
					display_toolbox(CreateDialog(hInst, (LPCTSTR)IDD_EDITCOLORBOX, ghWndStatusbox, (DLGPROC)COLORDlgHandler));
					break;
				case IDM_EDITSCALES:
					close_toolbox();
					display_toolbox(CreateDialog(hInst, (LPCTSTR)IDD_EDITSCALEBOX, ghWndStatusbox, (DLGPROC)SCALEDlgHandler));
					break;
				case IDM_SETTINGS:
                     if (ghWndSettings==NULL) ghWndSettings=CreateDialog(hInst, (LPCTSTR)IDD_SETTINGSBOX, ghWndStatusbox, (DLGPROC)SETTINGSDlgHandler);
					 else SetForegroundWindow(ghWndSettings);
					break;
				case IDM_DEVICESETTINGS:
					if (deviceobject) 
					{
						close_toolbox();
						actobject=deviceobject;
	//					GLOBAL.showtoolbox=find_object(devicebox);
						actobject->make_dialog(); 
						if (actobject->displayWnd) 
							SetWindowPos(actobject->displayWnd,HWND_TOP,0,0,0,0,SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE);
					} else report ("No Amplifier Device present in the design");
					break;

				case IDM_INSERTMIDI: create_object(OB_MIDI); 
					break;
				case IDM_INSERTSPECTRUM: create_object(OB_FFT);
					break;	
				case IDM_INSERTTHRESHOLD: create_object(OB_THRESHOLD); 
					break;
				case IDM_INSERTFILTER:	create_object(OB_FILTER);						
					break;	
				case IDM_INSERTMAGNITUDE:create_object(OB_MAGNITUDE);						
					break;	
				case IDM_INSERTPARTICLE:create_object(OB_PARTICLE);						
					break;	
				case IDM_INSERTOSCI:create_object(OB_OSCI);						
					break;	
				case IDM_INSERTTRANSLATE:create_object(OB_TRANSLATE);						
					break;
				case IDM_INSERTSIGNAL:create_object(OB_SIGNAL);
					break;
				case IDM_INSERTAND:create_object(OB_AND);
					break;
				case IDM_INSERTOR:create_object(OB_OR);
					break;
				case IDM_INSERTNOT:create_object(OB_NOT);
					break;
				case IDM_INSERTWAV:
					if (!count_objects(OB_WAV)) create_object(OB_WAV);
					else report_error("Currently only one Sound player is supported.");
					break;
				case IDM_INSERTTCPRECEIVER:create_object(OB_TCP_RECEIVER);
					break;
				case IDM_INSERTDOKU:create_object(OB_DOKU);
					break;
                case IDM_INSERTEVAL:create_object(OB_EVAL);
					break;
				case IDM_INSERTAVI:create_object(OB_AVI);
					break;
				case IDM_INSERTAVERAGE:create_object(OB_AVERAGE);
					break;
				case IDM_INSERTCORR:create_object(OB_CORR);
					break;
				case IDM_INSERTEDFWRITER:create_object(OB_EDF_WRITER);
					break;
				case IDM_INSERTTCPSENDER:create_object(OB_TCP_SENDER);
					break;
				case IDM_INSERTEDFREADER:create_object(OB_EDF_READER);
					break;
				case IDM_INSERTCOMPARE:create_object(OB_COMPARE);
					break;
				case IDM_INSERTBALLGAME:create_object(OB_BALLGAME);
					break;
				case IDM_INSERTMIXER4:create_object(OB_MIXER4);
					break;
				case IDM_INSERTMOUSE:create_object(OB_MOUSE);
					break;
				case IDM_INSERTERPDETECT:create_object(OB_ERPDETECT);
					break;
				case IDM_INSERTCOM_WRITER:create_object(OB_COM_WRITER);
					break;
				case IDM_INSERTCAM:
					if (!count_objects(OB_CAM)) create_object(OB_CAM);
					break;
				case IDM_INSERTINTEGRATE:create_object(OB_INTEGRATE);
					break;
				case IDM_INSERTDEBOUNCE:create_object(OB_DEBOUNCE);
					break;
				case IDM_INSERTSAMPLE_HOLD:create_object(OB_SAMPLE_HOLD);
					break;
				case IDM_INSERTCONSTANT:create_object(OB_CONSTANT);
					break;
				case IDM_INSERTMATLAB:create_object(OB_MATLAB);
					break;
				case IDM_INSERTCOUNTER:create_object(OB_COUNTER);
					break;
				case IDM_INSERTSKINDIALOG:
					if (!count_objects(OB_SKINDIALOG)) create_object(OB_SKINDIALOG);
					break;
				case IDM_INSERTFILE_WRITER:create_object(OB_FILE_WRITER);
					break;
				case IDM_INSERTDEVIATION:create_object(OB_DEVIATION);
					break;
				case IDM_INSERTMCIPLAYER:create_object(OB_MCIPLAYER);
					break;
				case IDM_INSERTKEYSTRIKE:create_object(OB_KEYSTRIKE);
					break;
				case IDM_INSERTPEAKDETECT:create_object(OB_PEAKDETECT);
					break;
				case IDM_INSERTSPELLER:create_object(OB_SPELLER);
					break;
				case IDM_INSERTMARTINI:create_object(OB_MARTINI);
					break;
				case IDM_INSERTFILE_READER:create_object(OB_FILE_READER);
					break;
				case IDM_INSERTPORT_IO:create_object(OB_PORT_IO);
					break;
				case IDM_INSERTARRAY3600:create_object(OB_ARRAY3600);
					break;
				case IDM_INSERTCOMREADER:create_object(OB_COMREADER);
					break;
				case IDM_INSERTMIN:create_object(OB_MIN);
					break;
				case IDM_INSERTMAX:create_object(OB_MAX);
					break;
				case IDM_INSERTROUND:create_object(OB_ROUND);
					break;
				case IDM_INSERTDIFFERENTIATE:create_object(OB_DIFFERENTIATE);
					break;
				case IDM_INSERTDELAY:create_object(OB_DELAY);
					break;
				case IDM_INSERTLIMITER:create_object(OB_LIMITER);
					break;
				case IDM_INSERTFLOATVECTOR:
					create_object(OB_FLOATVECTOR);
					break;
				case IDM_INSERTVECTORFLOAT:
					create_object(OB_VECTORFLOAT);
					break;
				case IDM_INSERTDISPLAYVECTOR:
					create_object(OB_DISPLAYVECTOR);
					break;
				case IDM_INSERTVECTORBUFFER:
					create_object(OB_BUFFER);
					break;

				// here are th supported EED devices
				case IDM_INSERT_EEG_GENERIC8: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_RAW8BIT; create_object(OB_EEG);}
					break;
				case IDM_INSERT_EEG_GENERIC16: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_RAW; create_object(OB_EEG);}
					break;
				case IDM_INSERT_EEG_IBVA: 
					if (!count_objects(OB_EEG)) { TTY.devicetype=DEV_IBVA; create_object(OB_EEG);}  
					break;
				case IDM_INSERT_EEG_NIA: 
					if (!count_objects(OB_EEG)) { TTY.devicetype=DEV_NIA; create_object(OB_EEG);}  
					break;
				case IDM_INSERT_EEG_P21: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_MONOLITHEEG_P21; create_object(OB_EEG);} 
					break;
				case IDM_INSERT_EEG_OPENBCI8: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_OPENBCI8; create_object(OB_EEG);} 
					break;
				case IDM_INSERT_EEG_P2: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_MODEEG_P2; create_object(OB_EEG);}
					break;
				case IDM_INSERT_EEG_P3: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_MODEEG_P3; create_object(OB_EEG);}
					break;
				case IDM_INSERT_EEG_PENDANT: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_PENDANT3; create_object(OB_EEG);} 
					break;
				case IDM_INSERT_EEG_QDS: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_QDS; create_object(OB_EEG);}
					break;
				case IDM_INSERT_EEG_SBT4: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_SBT4; create_object(OB_EEG);} 
					break;
				case IDM_INSERT_EEG_SBT2: 
					if (!count_objects(OB_EEG))  { TTY.devicetype=DEV_SBT2; create_object(OB_EEG);} 
					break;
				// these devices need special care (seperate element)
				case IDM_INSERTOPTIMA:
					if ((!count_objects(OB_NEUROBIT)) && (!count_objects(OB_EEG))) create_object(OB_NEUROBIT);
					break;
				case IDM_INSERTEMOTIV:
					if ((!count_objects(OB_EMOTIV)) && (!count_objects(OB_EEG))) create_object(OB_EMOTIV);
					break;

				case IDM_COPY:
					if (actobject)
					{
						copy_object=actobject;
						if ((copy_object->type!=OB_EEG)&&(copy_object->type!=OB_WAV)&&(copy_object->type!=OB_CAM)
							&&(copy_object->type!=OB_SKINDIALOG)&&(copy_object->type!=OB_NEUROBIT))
						{
						    HANDLE hFile;
							char tmpfile[256];
							create_object(copy_object->type);

							strcpy(tmpfile,GLOBAL.resourcepath); 
							strcat(tmpfile,"tmp_copy.con");
							hFile = CreateFile(tmpfile, GENERIC_WRITE, 0, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
							if(hFile != INVALID_HANDLE_VALUE)
							{
									copy_object->save(hFile);
									save_property(hFile,"end Object",P_END,NULL);
									CloseHandle(hFile);
							}
							hFile = CreateFile(tmpfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
							if(hFile != INVALID_HANDLE_VALUE)
							{
									load_next_config_buffer(hFile);
									actobject->load(hFile);
									CloseHandle(hFile);
									DeleteFile(tmpfile);
							}
							actobject->xPos+=10; actobject->yPos+=10;
						}		
						close_toolbox();
					}
					break;
								
				default:
				   return DefWindowProc( hWnd, message, wParam, lParam );
			}
			break;

		case WM_ACTIVATE:
				{
/*				 char t[50];

				 static int cn=0;
				 cn++;
				 sprintf(t,"%d:%d,%d",cn,HIWORD(lParam),LOWORD(lParam)); //==WA_CLICKACTIVE))
				 SendDlgItemMessage(ghWndStatusbox,IDC_LIST2, LB_ADDSTRING, 0, (LPARAM) t);
				 SendDlgItemMessage(ghWndStatusbox,IDC_LIST2, LB_SETCURSEL, SendDlgItemMessage(ghWndStatusbox,IDC_LIST2, LB_GETCOUNT, 0, 0)-1, 0);
				 UpdateWindow(ghWndStatusbox);
*/
			     if ((LOWORD(lParam)==WA_CLICKACTIVE) || (HIWORD(lParam)==WA_CLICKACTIVE))
				 	SetWindowPos(ghWndMain,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
				  SetFocus(ghWndMain);
			}
			break;


		case WM_ACTIVATEAPP: 

			{
/*				 char t[50];
				 static int cn=0;
				 cn++;
				 sprintf(t,"%d:%d,%d",cn,HIWORD(lParam),LOWORD(lParam)); //==WA_CLICKACTIVE))
				 SendDlgItemMessage(ghWndStatusbox,IDC_LIST2, LB_ADDSTRING, 0, (LPARAM) t);
				 SendDlgItemMessage(ghWndStatusbox,IDC_LIST2, LB_SETCURSEL, SendDlgItemMessage(ghWndStatusbox,IDC_LIST2, LB_GETCOUNT, 0, 0)-1, 0);
				 UpdateWindow(ghWndStatusbox); */

//			     if ((LOWORD(lParam)==1828) || (LOWORD(lParam)==964))
				 	//SetWindowPos(ghWndMain,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
					SetWindowPos(ghWndMain,0,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
//				 return DefWindowProc( hWnd, message, wParam, lParam );
			}

			break;
		case WM_KEYDOWN:
		    if (lParam==KEY_DELETE )
			  SendMessage(ghWndDesign, message,wParam,lParam);
			 break;

		case WM_SIZE:
			 if (wParam== SIZE_MAXIMIZED) 
			 {
				 GLOBAL.main_maximized=lParam;
				 ShowWindow(ghWndStatusbox,TRUE);
				 GLOBAL.hidestatus=FALSE;
				 if (GLOBAL.session_length==0)
  				    SetWindowPos(ghWndStatusbox, ghWndMain, 4, HIWORD(lParam)+15, 
			                   LOWORD(lParam)-8,HIWORD(lParam), 0);
				 else SetWindowPos(ghWndStatusbox, ghWndMain, 4, HIWORD(lParam)-20, 
			                   LOWORD(lParam)-8,HIWORD(lParam), 0);
			 }
			 else if (wParam== SIZE_RESTORED) 
			 {
				WINDOWPLACEMENT  wndpl;
				GetWindowPlacement(ghWndMain, &wndpl);
				GLOBAL.top=wndpl.rcNormalPosition.top;
				GLOBAL.left=wndpl.rcNormalPosition.left;
				GLOBAL.right=wndpl.rcNormalPosition.right;
				GLOBAL.bottom=wndpl.rcNormalPosition.bottom;
				GLOBAL.main_maximized=0;
				update_status_window();

			 }
			 else if (wParam== SIZE_MINIMIZED) 
			 {
				 ShowWindow(ghWndStatusbox,FALSE);
				 GLOBAL.hidestatus=TRUE;
			 }
			break;
    	case WM_MOVE:
			{
				WINDOWPLACEMENT  wndpl;
				GetWindowPlacement(ghWndMain, &wndpl);
				GLOBAL.top=wndpl.rcNormalPosition.top;
				GLOBAL.left=wndpl.rcNormalPosition.left;
				GLOBAL.right=wndpl.rcNormalPosition.right;
				GLOBAL.bottom=wndpl.rcNormalPosition.bottom;
				update_status_window();
			}
			break;
		//case WM_PAINT:
		    //	break;
		case WM_DESTROY:
			actobject=0;
			GlobalCleanup();
			PostQuitMessage( 0 );
			break;
		case WM_INPUT:
			if ((TTY.CONNECTED) && (!GLOBAL.loading))
				ReadNIA( wParam, lParam);			// NIA Daten vorhanden: auslesen
				return(TRUE);
		default:
			return DefWindowProc( hWnd, message, wParam, lParam );
   }
   return 0;
}