SAMPLE: Spdsheet.exe - Developing a Spreadsheet App for Windows (68301)



The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) 3.0
  • Microsoft Windows Software Development Kit (SDK) 3.1

This article was previously published under Q68301

SUMMARY

A spreadsheet, such as Microsoft Excel, is used to store and manipulate data. It has a rectangular grid that is arranged in columns and rows. The intersection of each column and row is a cell, the basic unit of a spreadsheet in which the application stores data.

To develop a spreadsheet application, do not use the predefined control types (such as list boxes and edit controls) to represent cells. These controls have limitations that preclude using them for large scale purposes.

The "More Information" section describes a more efficient alternative to using predefined controls when creating a spreadsheet type application. There is a file in the Microsoft Download Center named Spdsheet.exe that contains the sample code to demonstrate such an application.

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
DownloadDownload the Spdsheet.exe package now. For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
The main technique used to develop a spreadsheet application for Windows is to draw vertical and horizontal lines on a window to represent the cells of a spreadsheet. Mouse hit-testing is then done to track the currently active spreadsheet cell. To enter the spreadsheet data, only one edit control is used. The most recent data is painted simultaneously on the current cell as it is entered by the user. To store the spreadsheet data internally, an array of the desired data type is created.

All the spreadsheet data and other visual information is repainted on the main window whenever the application gets a WM_PAINT message.

The SPDSHEET sample application uses Windows API function calls to paint the spreadsheet cells:
  • It draws all of the solid lines using MoveTo() functions and LineTo() functions.
  • The vertical dotted lines are drawn by calling LineDDA(), which in turn calls a callback function that draws pixels.
  • The application uses DrawText() to display column letters and row numbers.
  • The highlight on the current cell is achieved by inverting the bits on all four sides of the cell.
Since this is a simplified version of a spreadsheet, the sample application creates an array of 100 strings to represent spreadsheet data. The developers of a spreadsheet application can choose to use their own data type.

The SPDSHEET example also creates two other windows on the upper side of its client area:
  • One is a static window to display the position of the current selected cell.
  • The other is an edit control that is used to enter spreadsheet data. As the data is entered to the edit control, it is also drawn to the current selected cell using DrawText().
Upon receiving a WM_LBUTTONDOWN message, the application removes the highlight from the currently selected cell and calculates the location of the newly selected cell. The application highlights the newly selected cell and copies the cell's contents to the edit control. The static window is also updated to display the location of the newly selected cell.

The information corresponding to each cell's location is not stored by SPDSHEET because the cell size is constant and the location can be calculated. If, on the other hand, the cells were of variable sizes, some location information would have to be stored and managed by the application.

When the application receives a WM_PAINT message, it repaints its entire client area, including the whole entire array of spreadsheet data. To make this process more efficient, the application can make use of the invalid region information sent by Windows through the PAINTSTRUCT structure.

Modification Type:MinorLast Reviewed:8/4/2004
Keywords:kb16bitonly kbCtrl kbfile kbSample KB68301 kbAudDeveloper