Code:
struct node
{
double x; /* DLO coordinate. */
double y; /* DLO coordinate. */
double GlassBite; /* Allows custom glass bite per side of polygon. */
node *next;
node *prev;
}InputData; /* GLOBAL, All geometric data entered by user. */
INT_PTR CALLBACK GetCoordsProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int nLen = '\0';
static int counter = 1;
LPTSTR pUserInput;
bool bFloat = true;
char StaticTxt[20], TempTxt[30];
int RetValue = 0;
if(root == 0)
{
CreateNextNode();
counter = 1;
}
switch (message)
{
case WM_INITDIALOG:
{
/* Set static text in dialog box on the fly. */
switch (counter)
{
case 1:
sprintf(StaticTxt, "%s", TEXT("1st Coord. Pair"));
if(bEdit && conductor != 0)
{
/* Update user data in edit fields. */
hctrl = GetDlgItem(hdlg, IDC_EDITX1);
RetValue = sprintf(TempTxt,"%f",conductor->x);
SetWindowText(hctrl, TempTxt);
hctrl = GetDlgItem(hdlg, IDC_EDITY1);
RetValue =sprintf(TempTxt,"%f",conductor->y);
SetWindowText(hctrl, TempTxt);
}
break;
case 2:
sprintf(StaticTxt, "%s", TEXT("2nd Coord. Pair"));
if(bEdit && conductor != 0)
{
/* Update user data in edit fields. */
hctrl = GetDlgItem(hdlg, IDC_EDITX1);
RetValue = sprintf(TempTxt,"%f",conductor->x);
SetWindowText(hctrl, TempTxt);
hctrl = GetDlgItem(hdlg, IDC_EDITY1);
RetValue = sprintf(TempTxt,"%f",conductor->y);
SetWindowText(hctrl, TempTxt);
}
break;
case 3:
sprintf(StaticTxt, "%s", TEXT("3rd Coord. Pair"));
if(bEdit && conductor != 0)
{
/* Update user data in edit fields. */
hctrl = GetDlgItem(hdlg, IDC_EDITX1);
RetValue = sprintf(TempTxt,"%f",conductor->x);
SetWindowText(hctrl, TempTxt);
hctrl = GetDlgItem(hdlg, IDC_EDITY1);
RetValue = sprintf(TempTxt,"%f",conductor->y);
SetWindowText(hctrl, TempTxt);
}
break;
default:
sprintf(StaticTxt, "%dth Coord. Pair", counter);
if(bEdit && conductor != 0)
{
/* Update user data in edit fields. */
hctrl = GetDlgItem(hdlg, IDC_EDITX1);
sprintf(TempTxt,"%f",conductor->x);
SetWindowText(hctrl, TempTxt);
hctrl = GetDlgItem(hdlg, IDC_EDITY1);
sprintf(TempTxt,"%f",conductor->y);
SetWindowText(hctrl, TempTxt);
}
break;
}
/* Get handles to static control to update as it is initialized */
hctrl = GetDlgItem(hdlg, IDC_STATIC1);
SetWindowText(hctrl, StaticTxt);
}
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDBACK:
{
if(1 == counter) /* Can't go lower than 1 so beep. */
{
MessageBeep (0) ;
}
else
{
if(conductor->prev != NULL && bEdit) // Check (root->prev = 0 always) && (first time through bEdit is false)
{
conductor = conductor->prev;
MessageBox(hdlg, "This should change conductor to previous node.", "Previous node.", MB_OK);
/*************************************************************************/
// breakpoint here shows that conductor now equals prev node like I want!!!
/*************************************************************************/
}
bEdit = true;
counter-=1; // This is used to make changes to the static control in the dialog box.
EndDialog(hdlg, IDBACK);
}
}
break;
case IDDONE:
bEdit = false;
/* Need to verify that first and last points are equal. **
** Also need to verify that line segments do not cross. */
/* Want it to fall through. */
case IDNEXT:
{
/* xcoord 1 */
hctrl = GetDlgItem(hdlg, IDC_EDITX1); //(hOwner, hDialogEditField)
nLen = GetWindowTextLength(hctrl);
if(nLen > 0) /* If nLen=0 then there is no reason to do the following block! */
{
if(0 == conductor->next && counter > 1) /* If the next node is null and not root */
{
CreateNextNode();
}
if(pUserInput = (LPTSTR)malloc(nLen + 1)) //if((LPTSTR)pUserInput = (LPTSTR)new char(nLen + 1))
{
int test = GetDlgItemText(hdlg, IDC_EDITX1, pUserInput, nLen+1);
if(bFloat = ValidateFloat(pUserInput, nLen+1))
{
conductor->x = strtod(pUserInput, NULL);
}
free(pUserInput);//delete(pUserInput);
}
}
/* ycoord 1 */
hctrl = GetDlgItem(hdlg, IDC_EDITY1);
nLen = GetWindowTextLength(hctrl);
if(nLen > 0) /* If nLen=0 then there is no reason to do the following block! */
{
if(pUserInput = (LPTSTR)malloc(nLen + 1))
{
int test = GetDlgItemText(hdlg, IDC_EDITY1, pUserInput, nLen+1);
if(bFloat) /* If previous was a float check this one. */
{
if(bFloat = ValidateFloat(pUserInput, nLen+1))
{
conductor->y = strtod(pUserInput, NULL);
conductor->next = 0;
}
}
free(pUserInput);
}
}
if(!bFloat)
{
MessageBox(hwnd,"Enter a floating point number!", "Error!",MB_OK);
break;
}
else //(bFloat)
{
bFileNeedsSaved = true;
EndDialog(hwnd, IDOK);
}
counter+=1;
if( (LOWORD(wParam))== IDDONE ) /* check to see if user selected 'Done' */
{
/* Need to verify that first and last points are equal. **
** Also need to verify that line segments do not cross. */
//MessageBox(hwnd, "IDDONE", "it works", MB_OK);
//Translate();
CalcMinMax();
EndDialog(hdlg, IDDONE);
break;
}
bFileNeedsSaved = true;
EndDialog(hdlg, IDNEXT);
}
break;
case IDCANCEL:
{
MessageBeep (0) ;
EndDialog(hdlg, IDCANCEL);
}
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
void CreateNextNode()
{
if(0 == root)
{
root = new node;
CountNew +=1;
//counter = 1;
conductor = root;
conductor->prev = 0;
}
if(0 == conductor->next)
{
temp = conductor;
/* Allocate space for variables. */
conductor->next = new node;
CountNew +=1;
conductor = conductor->next;
conductor->prev = temp;
}
conductor->next = 0; /* Set next node to null so nasty ........ doesn't happen. */
conductor->x = '\0';
conductor->y = '\0';
conductor->GlassBite = '\0';
return ;
}