static LRESULT CALLBACK AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
static LRESULT CALLBACK ReslogDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
SetWindowPos(hDlg,HWND_TOP,GetSystemMetrics(SM_CXVIRTUALSCREEN)-460,464,-42,-42,SWP_NOSIZE);
hlist_log=GetDlgItem(hDlg,ID_L_RESLOGLIST);
PrintLogEx(PL_I_COMMAND,"Log started.");
return TRUE;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDOK:
case IDCANCEL:
case ID_B_RESLOGCLOSE:
hlist_log=NULL;
CheckMenuItem(hmenu,IDM_LOGWIN,MF_BYCOMMAND|MF_UNCHECKED);
EndDialog(hDlg, TRUE);
return TRUE;
case ID_B_RESLOGCLEAR:
ListBox_ResetContent(hlist_log);
return TRUE;
}
break;
case WM_CLOSE:
hlist_log=NULL;
CheckMenuItem(hmenu,IDM_LOGWIN,MF_BYCOMMAND|MF_UNCHECKED);
EndDialog(hDlg, TRUE);
return TRUE;
}
return FALSE;
}
static LRESULT CALLBACK SettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char dummy[100];
double dummyf,dummyf1,dummyf2;
double tmpzoom[8];
double prevz=1;
int i,j;
switch (uMsg)
{
case WM_INITDIALOG:
{
if(MoveFn[MF_LEFT_FOCUS])
CheckDlgButton(hDlg,ID_C_LEFT_FOCUS,BST_CHECKED);
if(MoveFn[MF_MIDDLE_FOCUS])
CheckDlgButton(hDlg,ID_C_MIDDLE_FOCUS,BST_CHECKED);
if(MoveFn[MF_RIGHT_FOCUS])
CheckDlgButton(hDlg,ID_C_RIGHT_FOCUS,BST_CHECKED);
if(MoveFn[MF_LEFT_PAN])
CheckDlgButton(hDlg,ID_C_LEFT_PAN,BST_CHECKED);
if(MoveFn[MF_WHEEL_ZOOM])
CheckDlgButton(hDlg,ID_C_WHEEL_ZOOM,BST_CHECKED);
if(MoveFn[MF_RIGHT_Z])
CheckDlgButton(hDlg,ID_C_RIGHT_Z,BST_CHECKED);
SetDlgItemInt(hDlg,ID_E_DELAY_FOCUS,delayf,FALSE);
if(fastscan==FV_XYREP)
CheckRadioButton(hDlg,ID_C_FASTXY,ID_C_FASTX4,ID_C_FASTXY);
else if(fastscan==FV_FOCUSX2)
CheckRadioButton(hDlg,ID_C_FASTXY,ID_C_FASTX4,ID_C_FASTX2);
else if(fastscan==FV_FOCUSX4)
CheckRadioButton(hDlg,ID_C_FASTXY,ID_C_FASTX4,ID_C_FASTX4);
sprintf(dummy,"%.1f",zooms[0]);
if(zooms[0])
SetDlgItemText(hDlg,ID_E_ZOOM1,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM1,"--");
sprintf(dummy,"%.1f",zooms[1]);
if(zooms[1])
SetDlgItemText(hDlg,ID_E_ZOOM2,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM2,"--");
sprintf(dummy,"%.1f",zooms[2]);
if(zooms[2])
SetDlgItemText(hDlg,ID_E_ZOOM3,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM3,"--");
sprintf(dummy,"%.1f",zooms[3]);
if(zooms[3])
SetDlgItemText(hDlg,ID_E_ZOOM4,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM4,"--");
sprintf(dummy,"%.1f",zooms[4]);
if(zooms[4])
SetDlgItemText(hDlg,ID_E_ZOOM5,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM5,"--");
sprintf(dummy,"%.1f",zooms[5]);
if(zooms[5])
SetDlgItemText(hDlg,ID_E_ZOOM6,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM6,"--");
sprintf(dummy,"%.1f",zooms[6]);
if(zooms[6])
SetDlgItemText(hDlg,ID_E_ZOOM7,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM7,"--");
if(zooms[6])
SetDlgItemText(hDlg,ID_E_ZOOM7,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM7,"--");
if(zooms[7])
SetDlgItemText(hDlg,ID_E_ZOOM8,dummy);
else
SetDlgItemText(hDlg,ID_E_ZOOM8,"--");
sprintf(dummy,"%.3f",panfactor);
SetDlgItemText(hDlg,ID_E_PANFACTOR,dummy);
SetDlgItemInt(hDlg,ID_E_ZFACTOR,zfactor,FALSE);
sprintf(dummy,"%.2f",zhigh);
SetDlgItemText(hDlg,ID_E_ZHIGH,dummy);
sprintf(dummy,"%.2f",zlow);
SetDlgItemText(hDlg,ID_E_ZLOW,dummy);
return TRUE;
}
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case ID_B_GETZHIGH:
{
dummyf=GetZpos();
sprintf(dummy,"%.2f",dummyf);
SetDlgItemText(hDlg,ID_E_ZHIGH,dummy);
return TRUE;
}
case ID_B_GETZLOW:
{
dummyf=GetZpos();
sprintf(dummy,"%.2f",dummyf);
SetDlgItemText(hDlg,ID_E_ZLOW,dummy);
return TRUE;
}
case ID_B_SETZERO:
{
SendMessage(fv10h[FV_ZSETZERO],BM_CLICK,0,0);
return TRUE;
}
case ID_B_ZDIVIDE:
{
GetDlgItemText(hDlg,ID_E_ZLOW,dummy,100);
sscanf(dummy,"%lf%",&dummyf1);
GetDlgItemText(hDlg,ID_E_ZHIGH,dummy,100);
sscanf(dummy,"%lf%",&dummyf2);
zfactor=GetDlgItemInt(hDlg,ID_E_ZFACTOR,NULL,FALSE);
if(zfactor<2 || zfactor>30)
zfactor=5;
SetDlgItemInt(hDlg,ID_E_ZFACTOR,zfactor,FALSE);
dummyf=(dummyf2-dummyf1)/zfactor;
SetZstep(dummyf);
GetDlgItemText(hDlg,ID_E_ZLOW,dummy,100);
sscanf(dummy,"%lf%",&dummyf1);
GetDlgItemText(hDlg,ID_E_ZHIGH,dummy,100);
sscanf(dummy,"%lf%",&dummyf2);
dummyf=GetZpos();
if(dummyf1<=dummyf*1.01&dummyf1<dummyf2)
zlow=dummyf1;
if(dummyf2>=dummyf*.99&dummyf1<dummyf2)
zhigh=dummyf2;
return TRUE;
}
case IDOK:
//moving functions
{
if(IsDlgButtonChecked(hDlg,ID_C_LEFT_FOCUS))
MoveFn[MF_LEFT_FOCUS]=1;
else
MoveFn[MF_LEFT_FOCUS]=0;
if(IsDlgButtonChecked(hDlg,ID_C_MIDDLE_FOCUS))
MoveFn[MF_MIDDLE_FOCUS]=1;
else
MoveFn[MF_MIDDLE_FOCUS]=0;
if(IsDlgButtonChecked(hDlg,ID_C_RIGHT_FOCUS))
MoveFn[MF_RIGHT_FOCUS]=1;
else
MoveFn[MF_RIGHT_FOCUS]=0;
if(IsDlgButtonChecked(hDlg,ID_C_LEFT_PAN))
MoveFn[MF_LEFT_PAN]=1;
else
MoveFn[MF_LEFT_PAN]=0;
if(IsDlgButtonChecked(hDlg,ID_C_WHEEL_ZOOM))
MoveFn[MF_WHEEL_ZOOM]=1;
else
MoveFn[MF_WHEEL_ZOOM]=0;
if(IsDlgButtonChecked(hDlg,ID_C_RIGHT_Z))
MoveFn[MF_RIGHT_Z]=1;
else
MoveFn[MF_RIGHT_Z]=0;
delayf=GetDlgItemInt(hDlg,ID_E_DELAY_FOCUS,NULL,FALSE);
if(IsDlgButtonChecked(hDlg,ID_C_FASTXY))
fastscan=FV_XYREP;
else if(IsDlgButtonChecked(hDlg,ID_C_FASTX2))
fastscan=FV_FOCUSX2;
else if(IsDlgButtonChecked(hDlg,ID_C_FASTX4))
fastscan=FV_FOCUSX4;
}
//zooms
{
GetDlgItemText(hDlg,ID_E_ZOOM1,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[0]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM2,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[1]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM3,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[2]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM4,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[3]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM5,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[4]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM6,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[5]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM7,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[6]=dummyf;
GetDlgItemText(hDlg,ID_E_ZOOM8,dummy,100);
dummyf=0;
sscanf(dummy,"%lf%",&dummyf);
tmpzoom[7]=dummyf;
for(i=0,j=0;i<8;i++)
{
if(tmpzoom[i]>=prevz)
prevz=zooms[j++]=tmpzoom[i];
}
for(i=j;i<8;i++)
zooms[i]=0;
zoommax=j-1;
}
//factors, Z
{
GetDlgItemText(hDlg,ID_E_PANFACTOR,dummy,100);
sscanf(dummy,"%lf%",&dummyf);
if(dummyf>0)
panfactor=dummyf;
zfactor=GetDlgItemInt(hDlg,ID_E_ZFACTOR,NULL,FALSE);
if(zfactor<2 || zfactor>30)
zfactor=5;
GetDlgItemText(hDlg,ID_E_ZLOW,dummy,100);
sscanf(dummy,"%lf%",&dummyf1);
GetDlgItemText(hDlg,ID_E_ZHIGH,dummy,100);
sscanf(dummy,"%lf%",&dummyf2);
dummyf=GetZpos();
if(dummyf1<=dummyf*1.01&dummyf1<dummyf2)
zlow=dummyf1;
if(dummyf2>=dummyf*.99&dummyf1<dummyf2)
zhigh=dummyf2;
}
case IDCANCEL:
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
static LRESULT CALLBACK ShowvalDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static int refresh=1000;
int ref;
char dummy[100];
double res;
switch (uMsg)
{
case WM_INITDIALOG:
SetDlgItemInt(hDlg,ID_E_REFRESH_SHOW,refresh,FALSE);
SetTimer(hDlg,TM_REFRESH,refresh,NULL);
return TRUE;
case WM_TIMER:
if(wParam==TM_REFRESH)
{
KillTimer(hDlg,TM_REFRESH);
sprintf(dummy,"%.1f",GetZoom());
SetDlgItemText(hDlg,ID_E_SHOWZOOM,dummy);
SetDlgItemInt(hDlg,ID_E_SHOWPANX,GetPanx(),TRUE);
SetDlgItemInt(hDlg,ID_E_SHOWPANY,GetPany(),TRUE);
GetDlgItemText(hDlg,ID_E_SHOWEQ1,dummy,100);
if(strlen(dummy)>0)
{
res=Calc(dummy);
if(calcerror)
{
TranslateError(calcerror,dummy);
SetDlgItemText(hDlg,ID_E_SHOWRES1,dummy);
}
else
{
sprintf(dummy,"%.3f",res);
SetDlgItemText(hDlg,ID_E_SHOWRES1,dummy);
}
}
GetDlgItemText(hDlg,ID_E_SHOWEQ2,dummy,100);
if(strlen(dummy)>0)
{
res=Calc(dummy);
if(calcerror)
{
TranslateError(calcerror,dummy);
SetDlgItemText(hDlg,ID_E_SHOWRES2,dummy);
}
else
{
sprintf(dummy,"%.3f",res);
SetDlgItemText(hDlg,ID_E_SHOWRES2,dummy);
}
}
GetDlgItemText(hDlg,ID_E_SHOWEQ3,dummy,100);
if(strlen(dummy)>0)
{
res=Calc(dummy);
if(calcerror)
{
TranslateError(calcerror,dummy);
SetDlgItemText(hDlg,ID_E_SHOWRES3,dummy);
}
else
{
sprintf(dummy,"%.3f",res);
SetDlgItemText(hDlg,ID_E_SHOWRES3,dummy);
}
}
SetTimer(hDlg,TM_REFRESH,refresh,NULL);
return TRUE;
}
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case ID_B_REFRESH_SHOW: // a.k.a Set
ref=GetDlgItemInt(hDlg,ID_E_REFRESH_SHOW,NULL,FALSE);
if(ref>9)
{
KillTimer(hDlg,TM_REFRESH);
refresh=ref;
SetTimer(hDlg,TM_REFRESH,refresh,NULL);
}
return TRUE;
case IDOK:
case IDCANCEL:
KillTimer(hDlg,TM_REFRESH);
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
#define RM_IDLE 0
#define RM_RUN 1
#define RM_PAUSE 2
static LRESULT CALLBACK RunmacroDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static int command;
static int status;
char dummy[100];
FILE *fp;
OPENFILENAME ofndata;
static char macrofilename[1000];
int err;
long i;
switch (uMsg)
{
case WM_INITDIALOG:
if(cmdlist!=NULL)
{
EndDialog(hDlg, TRUE);
PrintLogEx(PL_W_COMMAND,"Macro window was open!!");
return TRUE;
}
PrintLogEx(PL_I_COMMAND,"Opening Macro window");
rmspeed=rmfast;
command=0;
maxgoto=20;
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_CMDNUM,"-/-");
cmdlist=GetDlgItem(hDlg,ID_L_MACROS);
ListBox_AddString(cmdlist,"# Load a macro to run");
return TRUE;
case WM_TIMER:
if(wParam==TM_RUNMACRO)
{
if(command>=ListBox_GetCount(cmdlist))
{
KillTimer(hDlg,TM_RUNMACRO);
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_STATUS,"idle");
ListBox_SetCurSel(cmdlist,-1);
sprintf(dummy,"%d/%d",ListBox_GetCount(cmdlist),ListBox_GetCount(cmdlist));
SetDlgItemText(hDlg,ID_S_CMDNUM,dummy);
return TRUE;
}
sprintf(dummy,"%d/%d",command,ListBox_GetCount(cmdlist));
SetDlgItemText(hDlg,ID_S_CMDNUM,dummy);
ListBox_SetCurSel(cmdlist,command+2);
ListBox_SetCurSel(cmdlist,command);
ListBox_GetText(cmdlist,command++,dummy);
KillTimer(hDlg,TM_RUNMACRO);
if(dummy[0]=='D')
{
char dstr1[100],dstr2[100];
dstr1[0]='\0';
dstr2[0]='\0';
sscanf(dummy,"D %s %d",dstr1,&i);
if(!strcmp(dstr1,"end"))
{
PrintLog(&(dummy[6]));
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_STATUS,"idle");
ListBox_SetCurSel(cmdlist,command);
return TRUE;
}
else if(!strcmp(dstr1,"quit"))
{
PrintLog(&(dummy[7]));
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_STATUS,"idle");
ListBox_SetCurSel(cmdlist,command);
return TRUE;
}
else if(!strcmp(dstr1,"resetjump"))
{
countgoto=0;
}
else if(!strcmp(dstr1,"setmaxjump"))
{
if(i>0 & i<1000)
maxgoto=i;
}
else if(!strcmp(dstr1,"label"))
{
;
}
else if(!strcmp(dstr1,"gotonum"))
{
if(i>=0 & i<ListBox_GetCount(cmdlist) & ++countgoto<maxgoto)
{
command=i;
sprintf(dummy,"gotocount/max: %d/%d",countgoto,maxgoto);
PrintLogEx(PL_I_COMMAND,dummy);
}
}
else if(!strcmp(dstr1,"gotolabel"))
{
sscanf(dummy,"D gotolabel %s",dstr1);
for(i=0;i<ListBox_GetCount(cmdlist);i++)
{
ListBox_GetText(cmdlist,i,dummy);
sscanf(dummy,"D label %s",dstr2);
if(!strcmp(dstr1,dstr2))
{
if(++countgoto<maxgoto)
{
command=i;
sprintf(dummy,"gotocount/max: %d/%d",countgoto,maxgoto);
PrintLogEx(PL_I_COMMAND,dummy);
}
break;
}
}
}
else if(!strcmp(dstr1,"gosub"))
{
sscanf(dummy,"D gosub %s",dstr1);
for(i=0;i<ListBox_GetCount(cmdlist);i++)
{
ListBox_GetText(cmdlist,i,dummy);
sscanf(dummy,"D label %s",dstr2);
if(!strcmp(dstr1,dstr2)&gosublevel<MAXGOSUB-1)
{
gosub[++gosublevel]=command;
command=i;
break;
}
}
}
else if(!strcmp(dstr1,"return"))
{
if(gosublevel>-1)
command=gosub[gosublevel--];
else
PrintLogEx(PL_E_COMMAND,"Return without gosub");
}
else if(!strcmp(dstr1,"pause"))
{
status=RM_PAUSE;
SetDlgItemText(hDlg,ID_S_STATUS,"Pause");
ListBox_SetCurSel(cmdlist,command+2);
ListBox_SetCurSel(cmdlist,command);
return TRUE;
}
else
{
PrintLogEx(PL_E_COMMAND,"Unknown D command!!");
}
SetTimer(hDlg,TM_RUNMACRO,100,NULL);
return TRUE;
}//directives
i=MacroCommand(dummy);
if(i==FN_MACROQUIT)
{
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_STATUS,"idle");
ListBox_SetCurSel(cmdlist,command);
return TRUE;
}
else if(i<FN_OK)
{
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_STATUS,"!!!Error!!!");
return TRUE;
}
SetTimer(hDlg,TM_RUNMACRO,i,NULL);
return TRUE;
}
return TRUE;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case ID_C_TESTMODE:
{
if(IsDlgButtonChecked(hDlg,ID_C_TESTMODE))
rmspeed=rmslow;
else
rmspeed=rmfast;
return TRUE;
}
case ID_B_RUN:
{
if(status==RM_RUN)
return TRUE;
command=0;
countgoto=0;
gosublevel=-1;
currtile=0;
status=RM_RUN;
SetDlgItemText(hDlg,ID_S_STATUS,"Running...");
SetTimer(hDlg,TM_RUNMACRO,10,NULL); //az elso utasitas elott nem varunk
return TRUE;
}
case ID_B_RUNFROM:
{
if(status==RM_RUN)
return TRUE;
if((i=ListBox_GetCurSel(cmdlist))==LB_ERR)
return TRUE;
command=i;
countgoto=0;
gosublevel=-1;
currtile=0;
status=RM_RUN;
SetDlgItemText(hDlg,ID_S_STATUS,"Running...");
SetTimer(hDlg,TM_RUNMACRO,10,NULL); //az elso utasitas elott nem varunk
return TRUE;
}
case ID_B_PAUSE:
{
if(status==RM_RUN)
{
status=RM_PAUSE;
SetDlgItemText(hDlg,ID_S_STATUS,"Pause");
ListBox_SetCurSel(cmdlist,command+2);
ListBox_SetCurSel(cmdlist,command);
KillTimer(hDlg,TM_RUNMACRO);
}
else if(status==RM_PAUSE)
{
status=RM_RUN;
SetDlgItemText(hDlg,ID_S_STATUS,"Running...");
SetTimer(hDlg,TM_RUNMACRO,10,NULL);
}
return TRUE;
}
case ID_B_STOP:
{
if(status==RM_IDLE)
return TRUE;
KillTimer(hDlg,TM_RUNMACRO);
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_STATUS,"idle");
return TRUE;
}
case ID_B_RESET:
{
if(status==RM_RUN)
return TRUE;
ListBox_ResetContent(cmdlist);
rmspeed=rmfast;
command=0;
maxgoto=20;
status=RM_IDLE;
SetDlgItemText(hDlg,ID_S_CMDNUM,"-/-");
ListBox_AddString(cmdlist,"# Load a macro to run");
return TRUE;
}
case ID_B_DELITEM:
{
if(status==RM_RUN)
return TRUE;
if((i=ListBox_GetCurSel(cmdlist))==LB_ERR)
return TRUE;
ListBox_DeleteString(cmdlist,i);
if(i<command)
command--;
sprintf(dummy,"%d/%d",command,ListBox_GetCount(cmdlist));
SetDlgItemText(hDlg,ID_S_CMDNUM,dummy);
ListBox_SetCurSel(cmdlist,i);
return TRUE;
}
case ID_B_GETITEM:
{
if(status==RM_RUN)
return TRUE;
if((i=ListBox_GetCurSel(cmdlist))==LB_ERR)
return TRUE;
ListBox_GetText(cmdlist,i,dummy);
SetDlgItemText(hDlg,ID_E_EDITITEM,dummy);
return TRUE;
}
case ID_B_PUTITEM:
{
if(status==RM_RUN)
return TRUE;
GetDlgItemText(hDlg,ID_E_EDITITEM,dummy,100);
i=ListBox_GetCurSel(cmdlist);
ListBox_InsertItemData(cmdlist,i,dummy);
if(i<command&i>0)
command++;
sprintf(dummy,"%d/%d",command,ListBox_GetCount(cmdlist));
SetDlgItemText(hDlg,ID_S_CMDNUM,dummy);
if(i==LB_ERR)
ListBox_SetCurSel(cmdlist,ListBox_GetCount(cmdlist)-1);
else
ListBox_SetCurSel(cmdlist,i);
return TRUE;
}
case ID_B_OWITEM:
{
if(status==RM_RUN)
return TRUE;
GetDlgItemText(hDlg,ID_E_EDITITEM,dummy,100);
i=ListBox_GetCurSel(cmdlist);
ListBox_InsertItemData(cmdlist,i,dummy);
ListBox_DeleteString(cmdlist,i+1);
ListBox_SetCurSel(cmdlist,i);
return TRUE;
}
case ID_B_ADDITEM:
{
if(status==RM_RUN)
return TRUE;
GetDlgItemText(hDlg,ID_E_EDITITEM,dummy,100);
i=ListBox_GetCurSel(cmdlist);
ListBox_AddString(cmdlist,dummy);
ListBox_SetCurSel(cmdlist,i);
return TRUE;
}
case ID_B_LOAD:
{
ZeroMemory(&ofndata,sizeof(ofndata));
ofndata.lStructSize=sizeof (OPENFILENAME);
ofndata.hInstance=NULL;
ofndata.hwndOwner=hDlg;
ofndata.lpstrFilter="Text files (*.txt)\0*.txt\0All files(*.*)\0*.*\0\0";
ofndata.nFilterIndex=1;
ofndata.lpstrCustomFilter=NULL;
ofndata.nMaxCustFilter=0;
ofndata.lpstrFile=macrofilename;
ofndata.lpstrFile[0]='\0';
ofndata.nMaxFile=1000;
ofndata.lpstrFileTitle=NULL;
ofndata.nMaxFileTitle=0;
ofndata.lpstrInitialDir=NULL;
ofndata.lpstrTitle="Open macro file";
ofndata.nFileOffset=0;
ofndata.nFileExtension=0;
ofndata.lpstrDefExt=NULL;
ofndata.lCustData=(LPARAM)0;
ofndata.FlagsEx=0*OFN_EX_NOPLACESBAR;
ofndata.Flags=0*OFN_ALLOWMULTISELECT| // csak egyet
0*OFN_CREATEPROMPT|
OFN_DONTADDTORECENT|
0*OFN_ENABLESIZING|
0*OFN_NONETWORKBUTTON|
OFN_EXPLORER|
OFN_HIDEREADONLY|
OFN_PATHMUSTEXIST|
OFN_FILEMUSTEXIST;
err=GetOpenFileName(&ofndata);
if(err==FALSE)
{
err=CommDlgExtendedError();
if(err==FALSE)
{
PrintLogEx(PL_T_COMMAND,"Loading macro cancelled");
}
else
{
sprintf(dummy,"CDB error code: %d",err);
MessageBox(hDlg,dummy,"Open macro file",MB_OK|MB_ICONERROR);
}
}
else
{
sprintf(dummy,"Loading %s",macrofilename);
PrintLogEx(PL_I_COMMAND,dummy);
if((fp=fopen(macrofilename,"rt"))==NULL)
{
MessageBox(hDlg,"WTF?!","Open macro file",MB_OK|MB_ICONERROR);
return TRUE;
}
while(1)
{
if(feof(fp))
break;
fgets(dummy, 100, fp);
if(dummy[0]=='\n' || dummy[0]=='\r')
continue;
if(dummy[strlen(dummy)-1]=='\n')
dummy[strlen(dummy)-1]='\0';
if(dummy[strlen(dummy)-1]=='\r')
dummy[strlen(dummy)-1]='\0';
ListBox_AddString(cmdlist,dummy);
}
fclose(fp);
ListBox_SetCurSel(cmdlist,0);
sprintf(dummy,"%d/%d",0,ListBox_GetCount(cmdlist));
SetDlgItemText(hDlg,ID_S_CMDNUM,dummy);
for (i=strlen(macrofilename); i>0; i--)
if (macrofilename[i] == '\\')
break;
sprintf(dummy,"Run macro - %s",&(macrofilename[i+1]));
SetWindowText(hDlg,dummy);
}
return TRUE;
}
case ID_B_SAVE:
{
ZeroMemory(&ofndata,sizeof(ofndata));
ofndata.lStructSize=sizeof (OPENFILENAME);
ofndata.hInstance=NULL;
ofndata.hwndOwner=hDlg;
ofndata.lpstrFilter="Text files (*.txt)\0*.txt\0All files(*.*)\0*.*\0\0";
ofndata.nFilterIndex=1;
ofndata.lpstrCustomFilter=NULL;
ofndata.nMaxCustFilter=0;
ofndata.lpstrFile=macrofilename;
ofndata.lpstrFile[0]='\0';
ofndata.nMaxFile=1000;
ofndata.lpstrFileTitle=NULL;
ofndata.nMaxFileTitle=0;
ofndata.lpstrInitialDir=NULL;
ofndata.lpstrTitle="Save macro file";
ofndata.nFileOffset=0;
ofndata.nFileExtension=0;
ofndata.lpstrDefExt=NULL;
ofndata.lCustData=(LPARAM)0;
ofndata.FlagsEx=0*OFN_EX_NOPLACESBAR;
ofndata.Flags=0*OFN_ALLOWMULTISELECT|
0*OFN_CREATEPROMPT|
OFN_DONTADDTORECENT|
OFN_ENABLESIZING|
OFN_NONETWORKBUTTON|
OFN_EXPLORER|
OFN_OVERWRITEPROMPT| // okosan visszakerdez
OFN_PATHMUSTEXIST|
OFN_FILEMUSTEXIST; // OK vsz.
err=GetSaveFileName(&ofndata);
if(err==FALSE)
{
err=CommDlgExtendedError();
if(err==FALSE)
{
PrintLogEx(PL_T_COMMAND,"Saving macro cancelled");
}
else
{
sprintf(dummy,"CDB error code: %d",err);
MessageBox(hDlg,dummy,"Save macro file",MB_OK|MB_ICONERROR);
}
}
else
{
sprintf(dummy,"Saving %s",macrofilename);
PrintLogEx(PL_I_COMMAND,dummy);
if((fp=fopen(macrofilename,"wt"))==NULL)
{
MessageBox(hDlg,"WTF?!","Save macro file",MB_OK|MB_ICONERROR);
return TRUE;
}
for(i=0;i<ListBox_GetCount(cmdlist);i++)
{
ListBox_GetText(cmdlist,i,dummy);
if(!strcmp(dummy,"# Load a macro to run"))
continue;
fputs(dummy,fp);
fputc('\n',fp);
}
fclose(fp);
for (i=strlen(macrofilename); i>0; i--)
if (macrofilename[i] == '\\')
break;
sprintf(dummy,"Run macro - %s",&(macrofilename[i+1]));
SetWindowText(hDlg,dummy);
}
return TRUE;
}
case IDOK:
case IDCANCEL:
{
KillTimer(hDlg,TM_RUNMACRO);
cmdlist=NULL;
EndDialog(hDlg, TRUE);
return TRUE;
}
}
break;
}
return FALSE;
}
static LRESULT CALLBACK DevmodeDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
SetDlgItemText(hDlg,ID_E_DEVMODE,devstring);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
GetDlgItemText(hDlg,ID_E_DEVMODE,devstring,100);
case IDCANCEL:
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
static LRESULT CALLBACK ConnectDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char dummy[100];
char ports[31][10]={"--",
"\\\\.\\COM30","\\\\.\\COM29","\\\\.\\COM28","\\\\.\\COM27","\\\\.\\COM26","\\\\.\\COM25","\\\\.\\COM24","\\\\.\\COM23","\\\\.\\COM22","\\\\.\\COM21",
"\\\\.\\COM20","\\\\.\\COM19","\\\\.\\COM18","\\\\.\\COM17","\\\\.\\COM16","\\\\.\\COM15","\\\\.\\COM14","\\\\.\\COM13","\\\\.\\COM12","\\\\.\\COM11",
"\\\\.\\COM10","\\\\.\\COM9","\\\\.\\COM8","\\\\.\\COM7","\\\\.\\COM6","\\\\.\\COM5"
//,"\\\\.\\COM4","\\\\.\\COM3","\\\\.\\COM2","\\\\.\\COM1"
};
int maxports=30-4;
static int currport;
static int timerstat;
unsigned long int length;
switch (uMsg)
{
case WM_INITDIALOG:
SetDlgItemText(hDlg,ID_S_CONSTAT,"Looking for MC unit...");
timerstat=1;
currport=0;
SetTimer(hDlg,42,INITTIM,NULL);
return TRUE;
case WM_TIMER:
if(wParam==4242){
EndDialog(hDlg, TRUE);
return TRUE;
}
KillTimer(hDlg,42);
if(timerstat==1) //determine and open port
{
if(currport<maxports)
currport++;
else {
SendMessage(GetDlgItem(hDlg,ID_PB_CONSTAT), PBM_SETPOS , 0, 0);
SetDlgItemText(hDlg,ID_S_CONSTAT,"No connention found - check driver/wiring!");
handlePort=INVALID_HANDLE_VALUE;
return TRUE;
}
if(TESTMEASURE){
sprintf(dummy,"Opening %s port", &(ports[currport][4]));
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
}
SendMessage(GetDlgItem(hDlg,ID_PB_CONSTAT), PBM_SETPOS , currport*100/maxports, 0);
handlePort=CreateFile(ports[currport],
GENERIC_READ | GENERIC_WRITE, // Specify mode that open device.
0, // the devide isn't shared.
NULL, // the object gets a default security.
OPEN_EXISTING, // Specify which action to take on file.
0, // default.
NULL); // default.
if(handlePort==INVALID_HANDLE_VALUE){
timerstat=1;
SetTimer(hDlg,42,INITTIM,NULL);
return TRUE;
}
sprintf(dummy,"%s port opened", &(ports[currport][4]));
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
setarduino(handlePort);
SendMessage(GetDlgItem(hDlg,ID_PB_CONSTAT), PBM_SETPOS , 100, 0);
while(1) {
if (ReadFile(handlePort, // handle of file to read
dummy, // buffer to read
100, // number of bytes to read
&length, // pointer to number of bytes read
NULL) == 0) {
sprintf(dummy,"Reading from MC unit failed, error: %d",GetLastError());
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
return TRUE;
}
else if(length) {
sprintf(dummy,"Resetting MC unit...");
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
}
else
break;
}
if (WriteFile(handlePort,
"Who are you?",
12,
&length,NULL)==0) {
sprintf(dummy,"Communication with MC unit failed, error: %d",GetLastError());
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
return TRUE;
}
timerstat=2;
SetTimer(hDlg,42,INITTIM,NULL);
return TRUE;
}
else if(timerstat==8) {
if (WriteFile(handlePort,
"Who are you?",
12,
&length,NULL)==0) {
sprintf(dummy,"Communication with MC unit failed, error: %d",GetLastError());
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
return TRUE;
}
timerstat++;
SetTimer(hDlg,42,INITTIM,NULL);
}
else if(timerstat>=2 & timerstat<=10) //reading answer
{
sprintf(dummy,"Reading header... #%xF%dAA", (timerstat-1)*23,timerstat-1);
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
SendMessage(GetDlgItem(hDlg,ID_PB_CONSTAT), PBM_SETPOS , (timerstat-1)*10, 0);
if (ReadFile(handlePort, // handle of file to read
dummy, // buffer to read
10, // number of bytes to read
&length, // pointer to number of bytes read
NULL) == 0) {
sprintf(dummy,"Reading from MC unit failed, error: %d",GetLastError());
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
return TRUE;
}
else if(length) {
dummy[length]=0;
if(!strcmp("Arduino",dummy)) {
SendMessage(GetDlgItem(hDlg,ID_PB_CONSTAT), PBM_SETPOS , 100, 0);
//sprintf(dummy,"Connection established on %s",&(ports[currport][4]));
sprintf(dummy,"Connection established");
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
SetWindowText(GetDlgItem(hDlg,IDCANCEL),"Close");
SetTimer(hDlg,4242,3000,NULL);
return TRUE;
}// arduino
else {
Beep(440,300);
SendMessage(GetDlgItem(hDlg,ID_PB_CONSTAT), PBM_SETPOS , 0, 0);
if(CloseHandle(handlePort) == 0) {
sprintf(dummy,"Closing failed, error: %d",GetLastError());
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
return TRUE;
}
timerstat=1;
SetTimer(hDlg,42,INITTIM,NULL);
return TRUE;
}// other device
}
else
; //Beep(1440,300);
timerstat++;
SetTimer(hDlg,42,INITTIM,NULL);
return TRUE;
}
else if( timerstat>10) //no answer
{
if(CloseHandle(handlePort) == 0) {
sprintf(dummy,"Closing failed, error: %d",GetLastError());
SetDlgItemText(hDlg,ID_S_CONSTAT,dummy);
return TRUE;
}
timerstat=1;
SetTimer(hDlg,42,INITTIM,NULL);
return TRUE;
}
return TRUE;
case WM_COMMAND:
switch (wParam)
{
//case IDOK:
case IDCANCEL:
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}