View Full Version : Visual Table

11-11-2004, 08:13 PM
Hey I got an assignment that involves creating a 10x10 table in C then adding stuff to that table.
but instead of doing it in the console I would like to create it visually??

Can anyone help me,
Thanks alot

11-12-2004, 02:14 AM
I guess you mean you want to make a gui for it.
Well, I dunno how others would do it. But I'd just use my custom control lib for it :p.. But you don't have that luxury.

Basically, once you have created your window you need to create your custom control. Register it in the same way that you would a normal window.

You will need a struct (being just in C) that will contain the 100 values for each cell in the table.

So something like-

struct {
char *data[100];
} datstruct;
(Actually, I'm unsure of the C implementation of a struct)

Next you just handle your WM_PAINT message and using the appropriate GDI functions draw the table, moving +11 in the array for each new row of data.

Oh, and you will need to store a pointer to the struct in the window class's memory, unless of course you'd rather some sort of hash table (like MFC) or maybe just an icky global scope to the variable.

So make sure that you give it enough bytes in the window registration to hold it.

And at the beginning of your window proc just grab it out of memory, or if it's the first time through (ie WM_CREATE) then you'll actually need to allocate the pointer and SetWindowLong at that stage. Not forgetting to free the memory when you hit WM_DESTROY.

You'll have to define a message of your own for WM_USER+3000 or so, and you can handle changing of any of the data that way by accepting a string pointer in WPARAM and an index in LPARAM or maybe a struct pointer in either.

...I think you should stick to console.