Click here to Skip to main content
15,902,789 members
Articles / Desktop Programming / MFC
Article

On The Fly Table Creator

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
9 Oct 2000 55.7K   1.4K   19   2
An MS-Word like drop down window for creating tables
  • Download source files - 14 Kb
  • Download demo project - 22 Kb
  • Sample Image - SizeDemo.gif

    Introduction

    One of my applications required the user to be able to change his view area on the fly. I was working on MS-Word at the time and it seemed that a drop down window like MS-Word has to create tables would be appropriate. So - here it is.

    This window has the following features :

    1. Requires just a couple of lines of code to be added to your application
    2. Drops down where required with an initial size of your choice
    3. Allows the user to choose the number of rows and columns he requires
    4. Allows expansion of displayed rows and columns dynamically

    Using the control

    1. Add TableWnd.cpp tp your project
    2. Create a member variable of type CTableWnd in your parent class
    3. The constructor takes 5 arguments - all of which have defaults. CTableWnd::CTableWnd(int maxx,int maxy,int nX,int nY,UINT nID) maxx and maxy are the maximum number of rows and columns the window will display.nX and nY are the initial number of rows and columns the window will display.nID is the message id that will be posted to the parent window upon the user making his/her choice. By default this is defined as TW_SETPARAMS.
    4. When you require the drop down - just call the create member function like so: m_TableWnd.Create(parentWnd,nPosX,nPosY); where parentWnd is the parent window and nPosX and nPosY are the X and Y screen coordinates where you want the drop down displayed
    5. In the DefWindowProc of your parent window, handle the message TW_SETPARAMS. The new number of rows and columns are sent as the LOWORD and HIWORD respectively in the wParam parameter.

      And well, thats about it.

    The implementation is rather straightforward. CTableWnd creates itself and calculates its size based on the displayable number of rows and columns. It also creates a static control which is used to display the current number of rows and columns. Initially, all the squares are white. If the mouse moves over the drop down, the squares above and to the left of the mouse position are assumed to be selected and are colored blue. If the user holds the mouse button down and drags, the window automatically expands until it reaches the values maxx and maxy given in the constructor.

    One last thing, when the window is closed, the class is not destroyed. The same object is reused. So, it is safe to use a static or local variable.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Web Developer
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    GeneralOn The Fly Table Creator Pin
    Marcus Carey4-Apr-04 19:08
    Marcus Carey4-Apr-04 19:08 
    Have you tried this class in Document/View application? It would be nice if the drop down window were resizable.

    Marcus Carey
    GeneralA Place to Start Pin
    4-Jan-01 20:49
    suss4-Jan-01 20:49 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.