Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to access a structure in a GUI?

MikeDMikeD Member Posts: 22
Hi All,

I have a structure,

struct {
UWord16 reserved0[32]; //0xF000--0xF01F
s_emi emi; //0xF020-0xF03F
s_timer tmra0; //0xF040-0xF04F
s_timer tmra1; //0xF050-0xF05F
s_timer tmra2; //0xF060-0xF06F
s_timer tmra3; //0xF070-0xF07F
}s_io;

struct {
UWord16 cmp1; //0
UWord16 cmp2; //1
UWord16 cap; //2
UWord16 load; //3
UWord16 hold; //4
UWord16 cntr; //5
UWord16 ctrl; //6
UWord16 scr; //7
UWord16 cmpld1; //8
UWord16 cmpld2; //9
UWord16 comscr; //A
UWord16 reserved[5];//B-F
} s_timer;

struct {
UWord16 csbar[8]; //0-7
UWord16 csor[8]; //8-F
UWord16 cstc[8]; //10-17
UWord16 bcr; //18
UWord16 reserved[7]; //19-1F
} s_emi;

I can access the member of s_io by following way.

s_io *psio;
addr =&psio->tmra0;

In C++/MFC GUI, I can use a combo box (m_cmbPeripheral)to display s_io to let user to select which member he/she want to access. From combo box we can get curser index of elements. If user selected 'tmra0', how do I display
sturct s_timer in another combo box(m_cmbOffset)? I have to define a CString array

CString s_timer[8]= {
"CMP1",
"CMP2",
"CAP",
"LOAD",
"HOLD",
"CNTR",
"CTRL",
"SCR"
};

then adding it to m_cmbOffset. But this is tedious work to define lot s of arrays, if the s_io is quite complex sturct, isn't it?
Do we have a better way to do it?

For example, convert struct to an array?

Thanks.

Mike

Comments

  • LundinLundin Member Posts: 3,711
    All you want is the index, as I understand it. Still, you must present something that makes sense to the user. Those look like hardware registers to a timer, you'd want to display the name of the register (CMP1, CMP2 etc) rather than the value of it, right? In that case, you must have some sort of string array.
  • MikeDMikeD Member Posts: 22
    Thanks, Lundin:

    This is a question that touches the core of C/C++, I thought.
    Think about it this way please:
    When you declared a struct, you telled compiler
    1. a certain mount of memory.
    2. a number of elements.
    3. each element's 'sturct'.
    4. each element name.

    in another word, you telled compiler
    1st element and its size,
    2nd element and its size,
    ...
    nth element and its size.
    here we can see a 'index'.

    or we can say the compiler knew the relationship between index and elements. I hope I can access element by index not traditional way
    (p->element ).

    Did someone can explain it?

Sign In or Register to comment.