Download source files - 14 KbDownload demo project - 22 Kb
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 :
- Requires just a couple of lines of code to be added to your application
- Drops down where required with an initial size of your choice
- Allows the user to choose the number of rows and columns he requires
- Allows expansion of displayed rows and columns dynamically
Using the control
- Add TableWnd.cpp tp your project
- Create a member variable of type
CTableWnd
in your parent class
- 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
.
- 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
- 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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.