SAMPLE: Developing a Spreadsheet Application for Windows

Last reviewed: July 22, 1997
Article ID: Q68301
3.00 3.10 WINDOWS kbprg kbfile

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

A spreadsheet, such as Microsoft Excel, is used to store and manipulate data. It has a rectangular grid 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, the predefined control types (such as list boxes and edit controls) should not be used to represent cells. These controls have limitations that preclude using them for large scale purposes.

The information below describes a more efficient alternative to using predefined controls when creating a spreadsheet type application. There is a file in the Microsoft Software Library named SPDSHEET that contains the sample code to demonstrate such an application.

MORE INFORMATION

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() 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 and 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.

Download SPDSHEET.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download SPDSHEET.EXE (size: 22345 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get SPDSHEET.EXE (size: 22345 bytes) 
    


Additional reference words: 3.00 3.10 softlib SPDSHEET.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrCtl
Keywords : kb16bitonly UsrCtl kbfile kbprg
Version : 3.00 3.10
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.