Using the 16-bit Common Controls from Visual Basic
Information in this topic can be used with Visual Basic 2, 3 and 4
Microsoft Windows for Workgroups 3.11 includes a library called COMMCTRL.DLL, and Internet Explorer 4.0/5.0 for Windows 3.1 includes one called COMCTL16.DLL, which include common controls similar to, if not the same as, the controls provided with Windows 95 and higher. It is possible to use some of these controls in Visual Basic. (The only problem with using this legally is I don't think you are allowed to distribute COMMCTRL.DLL with your program).
Using these controls from Visual Basic involves one of two methods. Some of the controls, such as the toolbar, status bar and up-down control, include routines that create themselves. The rest need to be created with the Windows API call CreateWindow. Lets go over creating controls with designated functions first.
First, start a new project. If you are using Visual Basic 2 or 3, also add a module. The Win32 API help file gives useful information on these controls, and I have converted the API calls. Lets create a status bar first. Declare the following:
Declare Function CreateStatusWindow Lib "COMMCTRL.DLL" (ByVal Style As Long, ByVal Text As String, ByVal hWndParent As Integer, ByVal wID As Integer) As Integer
Const WS_VISIBLE = &H10000000
Const WS_CHILD = &H40000000
Dim hWndStatus As Integer
The Style parameter describes the characteristics of the window. Text is the initial status text. hWndParent is the parent of the control, and wID is an identifier. The function returns the handle of the control. Putting this all together, we could create a status bar with the following code:
hWndStatus = CreateStatusWindow(WS_CHILD Or WS_VISIBLE, "Hello", hWnd, 45)
Place this in the Initalize event. WS_CHILD must be included, and WS_VISIBLE makes it visible. That's all there is to it! However, we should destroy the control afterwards, so place the following code in the Terminate event:
r = DestroyWindow(hWndStatus)
You also need the DestroyWindow declare, which is in the project. You can also use a similar routine to create a toolbar, which is described in detail in the sample project. The only thing you might have trouble with is recieving messages from the toolbar. For more information on this topic, including creating and adding buttons to toolbars, see the sample project.
You can use the IE4/5 common controls in 16-bit programs the same as you use the 32-bit ones (using the API interface and SendMessage, etc). The window class names are listed below:
|Control Type||Class Name|
|List View Control||IE_SysListView16|
|Tree View Control||IE_SysTreeView16|
|Status Bar Control||IE_StatusBar16|
|Extended Combo Box||IE_ComboBoxEx16|
|Progress Bar Control||IE_Progress16|
|Monthly Calendar Control||IE_SysMonthCal16|
|Date/Time Picker Control||IE_SysDateTimePick16|
Important! Read the warning below before trying to implement these controls in your programs.
|WARNING! I do not guarantee that these controls will work. They look the same as the Windows 9x ones, but the API may be different. You will need to initalise the control DLL with InitCommonControls(Ex). You will need to distribute WIN16X.DLL and the OLE2 DLLs with any application you use the controls with, and you MAY NOT distribute the DLLs on their own. You must distribute Internet Explorer with your product: not doing so will be a breach of the license agreement and illegal. Owen Rudge is not responsible for any damages or breaches of law caused by the use of these controls.|
I have started writing a sample C project. This includes the neccessary declares in header files and libraries. To run the project, install IE4/5 for Win 3.1 and run the included executable. It currently renders an up/down control, a status bar and a rather ugly toolbar!
I have also converted some other applications from various sources to work with these libraries. See the enclosed README.TXT for more information.