NO

Author Topic: Load resource from struct  (Read 2912 times)

Offline daniel_bingamon

  • Member
  • *
  • Posts: 22
Load resource from struct
« on: March 30, 2015, 04:01:27 PM »
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.