Representation of data is one the central aspects of any application. Tabular representation of data is the most common method of representing given data. Each language/framework provides its own technique, in the form of controls, to present data in tabular format. MFC (Microsoft Foundation Classes) is no exception. One of the controls that it provides is the MSFlexGrid control.
GetTextGrid(); //This function is called from here to get the //multiple digit inputs from the grid
Next we need to set up the part of the program that saves the entered data. In the handler for the OK button of the dialog box, provide the following code:
// TODO: Add extra validation here
int k = m_grid.count;
int f = m_grid.i;
int g = m_grid.j;
int a , b;
a = 0;
b = 0;
fp = fopen("dat.txt", "w");
for(int q = 0; q < f; q++)
inpx[a] = m_grid.inputx[q];
fprintf(fp, " a=%d %dn",a,atoi(inpx[a]) );
for(int m = 0;m < g; m++)
inpy[b] = m_grid.inputy[m];
fprintf(fp, " b=%d %dn",b,atoi(inpy[b]));
The first step is to declare the arrays to hold values of the two columns. Here the arrays are named inpx and inpy. Then the total count of the cells, the count of two columns, is retrieved.
The next step is to open the file to write out the input values. To do so, the example makes use of conventional File I/O API. Then the arrays (inpx and inpy) are populated with the values of the two columns. The arrays are populated by iterating over the values of the instance level arrays containing the values entered by the user. Finally, each value is converted to an integer and saved in the file.
That completes the small application that makes use of FlexGrid. However, this leaves a question regarding the serialization of the values in MFC. The answer is there is an API to do so. That will be discussed in the future. Till then...
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.