I've been contemplating creating a struct loader/unloader for windows dialogs:
struct dlg_memory
{
int resourcename;
char format[20];
char *dataaddress;
} =
{
IDC_STANDARDSUNITS, "%s", TempStandards.stunits,
IDC_STANDARDSCOMMENTS, "%s", TempStandards.stcomment,
IDC_STANDARDSTOL, "%f", (char *) &TempStandards.sttolerance,
??
..... etc
} Dlg_memory;
... in code...
populate_dialog(hdlg, Dlg_memory);
....... etc
void populate_dialog(HWND hdlg, struct dlg_memory *memory)
{
while(memory->resourcename != -1)
{
if(strcmp(memory->format, "STRING")==0)
upd_dlg(hdlg, memory->resourcename, "%s", memory->dataaddress);
else
upd_dlg(hdlg, memory->resourcename, memory->format, *(memory->dataaddress));
memory++;
}
}
void upd_dlg(HWND hdlg, int item, char *format, ...)
{
char vsbuffer[100];
va_list arglist;
va_start(arglist, format);
vsprintf(vsbuffer, format, arglist);
va_end(arglist);
SetDlgItemText(hdlg, item, vsbuffer);
}
What I'm not sure of is way to deal with various variable types being stored. It might need some form of union structure to hold the various data types.
I had to put it away due to time constraints but I'd like to come back to this and have something that extracts data from dialogs using the same structure. It would really help program maintenance time.