Sunday, February 3, 2008

Control arrays

So I'm now trying to convert my sudoku solver into a windows application. I created a new MFC and put a bunch of controls on the form and "explored" whatever I could do with them without touching the code itself.
Then I started converting the console code into a windosapp code. The first thing I ran into is that I can't create a control array as easily as in Visual Basic. The default naming of the controls doesn't give me such options, whatever I tried. As I need to get data from the cells the whole thing would look like.
CEdit *pEdit1 = reinterpret_cast(this->GetDlgItem(IDC_EDIT1));
CEdit *pEdit2 = reinterpret_cast(this->GetDlgItem(IDC_EDIT2));
...
pEdit1->SetWindowText(_T(""));
pEdit2->SetWindowText(_T(""));
...

That's what happens when put the event handler for my Clear button. (Haven't started with the Solve one yet) So what I run into is that I have to write 81*2=162(!) lines of code just for this little event! So I want to make a loop for that, but the problem is that I can't make an array of pointers, because the object the pointers point to is not an array. And I couldn't find the declaration of the CEdit class, as it is probably a default one and it's hiding somewhere I can't reach. I'm now trying to create a new array of the CEdit class, so that I can put them all in an array and maybe even use the same one pointer for each of them. The problem is I can't display my new class array objects on the form, I can't put them on the control panel and just "draw", because they are not default. So it's kind of complicated. I'll do some more research on that.
At least I got how the whole windowsapp thing works.

3 comments:

Zhanar said...

I was also wondering what the member variables were for. Maybe they could help me here. I didn't get them to work yet, but I created a member variable in class wizard for one of my CEdit IDCs (type int) and it seems to do something. I'm not really sure what exactly though

GeekTeach said...

You are on a complex road and I am amazed that you have plowed through so quickly. If you have installed the MS product, see if there are updates to grab as well. There is a MSDN help menu that comes on two disks to get started, and that has updates also. The help files take up 1Gb of space on a computer, so it's fairly extensive. If you want I can find the disks, too.

I will be your cheerleader on the side..

~Richard.

GeekTeach said...

Your presentation was really clean and clear. I can't believe I took a phone call during your explanation of the most important functions! Oh well.. I did get the rest sorted out.

~Richard.