FileExplorer
Overview
Left: VB6; Right: C#
FileExplorer is a desktop application that implements a simple Windows file explorer using common ActiveX controls.
The demo illustrates several techniques:
- Replacing ActiveX Controls with .NET controls
- Migrating Twips to pixels
- Overriding an AuthorText Method to introduce a custom assembly reference
- Post Editing translations with Author/Fix
The FileExplorer is organized into one VB6 project
FileExplorer.vbp -- an EXE that provides a user interface
The FileExplorer source is comprised of about 600 lines of code (LOC).
FileExplorer.vbp frmExploreLite.frm frmExploreLite.frx (contains the ImageLists' Images)
FileExplorer uses a set of controls from mscomctl.ocx (aka "Microsoft Windows Common Controls 6.0). The techniques used to migrate this library can be applied to other third-party (and in-house) OCXs as well.
The ActiveX control classes and their .NET replacements are listed below:
COMÂ Library.Class | .NET Namespace.Class |
MSComctlLib.ToolBar | System.Windows.Forms.Toolstrip |
MSComctlLib.TreeView | System.Windows.Forms.Treeview |
MSComctlLib.ListView | System.Windows.Forms.Listview |
MSComctlLib.StatusBar | System.Windows.Forms.StatusStrip |
MSComctlLib.ImageList | System.Windows.Forms.ImageList |
Scripting | System.IO |
RichTextLib | System.Windows.Forms.RichTextBox |
Note that the table above is just the "top-level" controls that are used in FileExplorer. Every one of these controls contains a collection of sub-controls. These collections and sub-controls must also be migrated. A sample of these sub-controls and their .NET replacements are listed below:
COMÂ Library.Class | .NET Namespace.Class |
MSComctlLib.Button (on a ToolBar) | ToolstripItem|ToolStripButton|ToolStripSeparator |
MSComctlLib.Node (in a TreeView) | TreeNode |
MSComctlLib.ListItem (in a ListView) | ListViewItem |
In some cases there are even sub-sub-controls; for example, a toolbar contains a collection of Buttons, and a ToolBar button can contain a collection of ButtonMenus. This three-levels-deep migration is also handled in this sample.
A pivot table of data produced by the Source GUI Scan report for FileExplorer is displayed below.
COM Dependencies
FileExplorer depends on the following external COM components that must be installed on your workstation to perform the migration successfully:
File | Description |
MSCOMCTL.OCX | Microsoft Windows Common Controls 6.0 (Statusbar, ToolBar, Treeview, ListView, ImageList) |
scrrun.dll | Microsoft Scripting Runtime |
richtx32.ocx | Microsoft Rich Textbox Control 6.0 |
Directing COM ReplacementÂ
A RefactorLibrary is a set of translation rules that tell gmStudio how to rewrite specific aspects of your code. For example, the RefactorLibrary file mscomctl.ocx.Winforms..Refactor.xml tells the translator how to migrate VB6 code that uses the classes, enums, methods, properties and events of mscomctl.ocx into .NET code that uses WinForms controls.
The RefactorLibrary has three sections:
- Rules for migrating API references in logic and .NET project files (e.g. csproj)
- Rules to directing the authoring of designer codeÂ
- Links to gmsl Scripts (if needed)
Here is an example:
<RefactorLibrary> <!-- Description: RefactorLibrary to map MSComCtlLib controls to WinForms --> <Refactor id="[mscomctl.ocx]" event="mscomctl" > <Migrate migName="System.Windows.Forms" libType="Internal" location="DoNotDeclare" axLocation="DoNotDeclare" /> <Migrate id="IVBDataObject.Files" migName="GetFileDropList()" /> ... hundreds of rules to direct migration of MSComCtl controls to WinForms controls ... <gmSL NameSpace="mscomctl" Class="Transform" Source="Mscomctl.ocx.WinForms.Transform.gmsl" /> </Refactor> </RefactorLibrary>
- The gmsl Script Mscomctl.ocx.WinForms.Transform.gmsl, implements simple gmsl routines to assist with the deeper and more dynamic aspects of the migration.
The RefactorLibary and gmSL files are placed in proj\usr.Â
Note that the managed migration of FileExplorer also loads two other RefactorLibraries: one to upgrade Scripting
to System.IO
and one to upgrade RichTextLib.RichTextBox
to Winforms.RichTextBox
. The commands used to load these custom migrations are shown below:
<Registry type="MigFile" source="richtx32.ocx" target="richtx32.ocx.WinForms.Refactor" /> <Registry type="MigFile" source="scrrun.dll" target="scrrun.dll.SystemIO.Refactor" /> <Registry type="MigFile" source="mscomctl.ocx" target="mscomctl.ocx.WinForms.Refactor" />
For additional details on custom COM replacements see this article.
You may find these RefactorLibraries and others on the gmStudio Extensions page.
Deployment
There are two versions of the FileExplorer upgrade sample:Â Â
Task | Description |
FileExplorer_csh.gmproj | FileExplorer migrated to C#.NET, all externals migrated to .NET |
FileExplorer_vbn.gmproj | FileExplorer migrated to VB.NET, all externals migrated to .NET |
The FileExplorer migrations all work on the FileExplorer source and save outputs in the FileExplorer workspace.Â
All the FileExplorer migration projects have the following deployment settings:
ProjectFolder = FileExplorer\proj_[lang] (where lang is csh or vbn for C# or VB.NET respectively) DeployFolder = %ProjFolder%\deploy
Log files showing all migration steps are created in the workspace\log folders.
%ProjFolder%\log
The .NET project files are deployed to the following folders:
%ProjFolder%\deploy\FileExplorer.