spacer spacer spacer spacer spacer spacer spacer spacer
Luigi Bianchi Web Site spacer
spacer Home Software Programming Others About spacer spacer
spacer spacer
spacer spacer

www.luigibianchi.com

Dfm2API UtilityC/C++ Users Jounal Cover Page

separator images

New! Dfm2API Survey!



A Borland VCL Form Converter

This page is dedicated to the Dfm2API utility that has been published in the August 2000 issue of C/C++ Users Journal. It is my desire to extend its capabilities and to fix all the tons of bugs that you’ll find over the time. So I need your feedback: suggestions, improvements, critics and even money!

·          What’s this utility for?
·          Who can benefit from it?
·          What this utility does NOT do?
·          What are the supported controls?
·          How does it work?
·          How can you contribute?
·          Example
·          Code Example
·          History
·          Downloads
·          Status

What’s this utility for?

As you probably know, Borland C++ Builder and Delphi define a resource file format (DFM) that cannot be used in non-VCL applications. Dfm2API is an extendable tool that converts a Borland DFM resource file into a standard RC (resource script) file and a CPP and HPP file. Extendable means that this conversion is not exhaustive, but that you can adapt it at our wish (you can download the code from CUJ site). Because a DFM file contains also a lot of information about controls initializations (e.g. you can specify which strings appears in a combobox without writing code), this utility extracts them and then automatically writes the required code (generally API calls) in a CPP file so that you can use some of the RAD facilities in non-VCL applications too. This utility can also extract DFM resources (i.e. menu, images, etc) from binaries (EXE, DLL). It is then possible to apply this conversion process to binary files, even if the source code is not available!
For example, if you extract the resources from BCB.EXE (C++ Builder 4.0), you can see that there is a Form whose caption text is “Delphi 4.0”. Funny, isn’t it?

Who can benefit from it?

Everybody!!!! Well, that’s not true, but I think that all the people that need a resource script file (both Delphi and C++ Builder users) or that wants to build WinAPI, MFC, or OWL applications could benefit from Dfm2Api. This tool can be also used to port your VCL forms into a Windows CE compatible format.

The main advantages are:

  • Dramatically Smaller executable size (more than one order of magnitude!);
  • Shorter compile and link time;
  • Shorter build time;
  • Compatibility with every C/C++ compiler;
  • Generated Resources are compatible with MFC, OWL, VWCL, SDK, etc..
  • No need for additional DLLs;
  • No dependence on any framework release; That means that you don't have to buy/wait for component new releases;

Actually I’m using C++ Builder for prototyping in a lot of situations, and then I use C++ programming to implement all the non-GUI aspects of the application. Then I translate the C++ Builder Forms into standard resources. This reduces considerably both executable size and compile time. I’m planning to also use Delphi for prototyping (which is very very fast) and C++ Builder or Visual C++ as WinAPI development tool. This tool is also useful for all the people that wants to extract bitmaps, menus, etc. from binaries or that wants to spy other programs forms. The extracted DFM files cannot actually be edited by Delphi/C++ Builder, because they need two more files that actually are not (yet) created. This feature, however, will be added in the next releases.

What this utility does NOT do?

It does not convert non-standard windows controls. For example all the Database controls cannot be translated with all their functionalities into Windows controls. It is still possible, anyway, to treat a specific control as another one: for example a THighlyEnhancedAndWonderfulRadioButtonWithFireWorks can be treated as a simple TRadioButton, but the HighlyEnhancedAndWonderfulFireWorks capabilities will be lost. A special configuration file is provided to perform and customize this conversion task. So, it is still possible to convert a TBDEdit into an EditBox, but in that case you’ll lose all the RAD DB facilities and you’ll have to write the code to implement the required DB queries, etc.. It does not (yet) convert TPropertyPages. This functionality will be added in one of the next releases (before 2.0).

It does not (yet) convert events such as OnClick and so on. This functionality will be probably added in release 2.0.

What are the supported controls?

Actually, you can convert the following components into one of the following controls/resources/common dialogs (red one are the latest updates):

  Component Release History
Controls
1 Animate   1.2

1.0 With data initialization 
1.2.2 Added transparent color property

2 Bevel     1.0 1.0 Supported through WM_PAINT message
3 BitBtn    1.0 1.0 It does not exist a standard Glyph Button control. Will be substituted with an Uncommon Control
4 Button    1.0 1.0 With data initialization 
5 CheckBox  1.0 1.0 With data initialization
6 ComboBox 

1.1

1.0 With data initialization
1.1 Better "height" property handling
7 DateTimePicker 1.2.2

1.0 With data initialization (partial)  
1.2.2 Improved data initialization

8 Edit      1.0 1.0 With data initialization
9 GroupBox  1.0 1.0 With data initialization 
10 Header    1.1 1.0 With data initialization (partial)
1.1 Better "width" property handling and added "Alignment" support
11 HotKey    1.0 1.0 Only Resource Script File   
12 Image     1.2.2 1.0 With data initialization (partial)  
1.2.2 Added Stretch property (processed through WM_PAINT message)
1.2.2 Added transparencies (white color mapped to transparent)
13 ImageList 1.2

1.1 I have finally discovered how the data are stored!!! Coming soon!!!!
1.1.1 beta (build 131) Images are extracted!!
1.2 ImageLists are created and used in TreeViews! All the images are stored as 256 color images, even if they are extracted as Icons too.

14 Label     1.0 1.0 With data initialization
15 ListBox   1.1 1.0 With data initialization
1.1 Better "height" property handling
16 ListView  1.2

1.0 With data initialization (partial: columns text but not items text)
1.1 Still partial, but better "width" property handling and added "Alignment" support
1.1.1 (build 111) Added item text initialization
1.2 Added (simplified) ImageList support!!

17 Memo      1.0 1.0 With data initialization
18 MonthCalendar 1.2.2 1.0 With data initialization (partial)
1.2.2 Improved data initialization
19 PageControl 0.0 OK, sooner or later I will do it! I've received so many E-Mails asking for it, that now I know that I MUST do it.
20 Panel     1.0 1.0 With data initialization 
21 ProgressBar 1.0 1.0 With data initialization
22 RadioButton 1.0 1.0 With data initialization
23 RadioGroup 1.0 1.0 With data initialization
24 RichEdit  1.0 1.0 With data initialization
25 ScrollBar 1.2.2 1.0 With data initialization 
1.2.2 Improved data initialization (range and border)
26 SpeedButton 1.0 1.0 With data initialization 
27 SpinEdit  1.0 1.0 With data initialization
28 StatusBar 1.0 1.0 With data initialization (partial)
1.1.1 Fixed bug with "deleted" panels
29 ToolBar   1.0 1.0 Only Resource Script File 
30 TabControl 1.2.2 1.0 With data initialization (partial)
1.2 Added (simplified) ImageList support!!
1.2.2 Improved tab size
31 TrackBar  1.2.2 1.0 With data initialization
1.2.2 Improved (ThumbLength, Line and Page properties handling added)
32 TreeView  1.2

1.0 Only Resource Script File 
1.1.1 (build 111) Improved RC caps, added item text initialization
1.2 Added (simplified) ImageList support!!

33 UpDown    1.0 1.0 With data initialization (partial)
1.1.1 (build 111) New bug added!! (Fixed in next release). Will cause wrong alignment.
Menus
34 MenuItem  1.0 1.0 With "response table"
35 MainMenu  1.0 1.0 With "response table" 
36 PopupMenu 1.0 1.0 With "response table" 
Common Dialogs
37 FontDialog 1.0 1.0 With data initialization (partial)
In progress: LogFont data initialization
38 FindDialog 1.1 1.0 With data initialization (partial)
1.1 With complete data initialization
39 ReplaceDialog 1.1 1.0 With data initialization (partial)
1.1 With complete data initialization
40 ColorDialog 1.1 1.0 With data initialization (partial)
1.1 With improved data initialization
41 OpenDialog 1.1 1.0 With data initialization (partial)
1.1 With complete data initialization
42 SaveDialog 1.1 1.0 With data initialization (partial)
1.1 With complete data initialization


Note that not all the properties are converted into resources/ line of code, but I think that the most important ones are treated.

How does it work?

Imagine that you need to design a DialogBox for a MFC, OWL or WinAPI application. What you have to do is simply to design it as a VCL Form, and then convert it with the Dfm2API utility. You’ll obtain an .RC file, that’s (more or less) exactly what you need (a resource script file, defined at the OS level), and a .CPP and .HPP file. The .RC file contains all the statements that are required to generate a .RES file that can be linked to a Win32 module, while the .CPP and .HPP files are responsible to create the proper DIALOGPROC and to initialize the controls that populates the DialogBox (this second steps is done for WinAPI applications). You can see an example here.

How can you contribute?

These are some suggestions:

1) Buy C/C++ Users Journal August 2000 issue, for several reasons:
      a.  There is an explanation of the code that you can download from http://www.cuj.com/
      b.  It is important to read papers that treats VCL
      c.  You make me happy

2) Submit some code (that you just can download from CUJ site

3) Find bugs

4) Send me a lot of money

5) Go to the survey page

Example

If you design a form like the following one (click over the image to see it at full size):

VCL Original Form


and then you convert it with Dfm2API (release 1.2.1), you’ll obtain the following DialogBox (click over the image to see it at full size):

API Converted Form

As you can see, even if there are small differences, they are quite similar. Also a lot of controls are initialized, with no need to write code, because Dfm2API did it for you. The main differences are:

  1. No text AND glyphs on buttons (see for example Ok and Cancel Buttons). This is due to the fact that there is no equivalent standard control. I'm confident to partially fix this in release 1.5 with an Uncommon Control.
  2. No border around scrollbars. Is it relevant?
  3. No bitmap stretch. This has been fixed in 1.2.2
  4. Different StatusBar behavior.
  5. SpinEdit control different alignment (left/right). But this is intentional because I do prefear right alignment!

The jumping red animal is an Animation control captured in a different frame with respect to the previous one. So, the behaviour is correct!

Despite these differences (some of them are already fixed or will be soon), I think that this tool does much more than one could expect. I've received so many E-Mails that I'll surely continue to develop and update it (also because I'm using it everyday, also with different releases, such as the VCL2OWL one!). Anyway, I haven't received any code proposal, and for this reason I don't think that I'll release the sources any more.

Code Example

Click here to give a look at the automatically generated source code file from the proviously described Form (release 1.0).

History

Version
Build
Date
Description
1.2.2
164
28 September 2001
Partially updated the engine to support more features. Improved Animate, Image, DateTimePicker and MonthCalendar controls. Fixed Form automatic resizing. It's a minor release, but I wanted to give the idea that I'm still working on it. As I've done some changes to the engine, let's consider it a release candidate (more than a beta). There are some menu items that are disabled because I'm still working on them. Anyway, there are some interesting new features that someone asked me, so I decided to release it.
1.2.1
160
10 May 2001
Fixed minor bugs, improved (not completed) compatibility with VisualC and Windows CE. Improved UNICODE support.
1.2.0
153
17 January 2001
Fixed minor bugs, support for ImageLists in TreeViews, ListViews and TabControls.
Improved ListView and TreeView behavior. Fixed minor bug with TStatusBar.
New user interface (it's just the beginning). Added preview window for some controls.
Improved Form automatic resizing options
1.1
65
28 December 2000
Added support for C++ Builder 5 and Delphi 5. Improved support for Common Dialogs. Minor changes. I'm actually debugging a major upgrade. I hope to have time to release it in late January.
1.0 
1
1 August 2000

Released with source code to C/C++ Users Journal.

Downloads

The project with the source code relative to release 1.0 is available at CUJ site.
You can download the main releases here.

Status

I've almost fixed the overall Form resizing: the default one generates DialogBoxes whose size differs from the original Form by less than 0.4%. As you probably know VCL Forms use a different sizing approach with respect to SDK DialogBoxes. I think I have understood the reason of the few remaining pixels. You can, of course, adapt the resizing feature at your wish, thus getting the best results. Actually I've improved VisualC compatibility and UNICODE and Windows CE support (since 1.2.1). I'm also working on the automatic generation of simple example programs for BCB, VC and GCC and more aspects related to UI.
I'm also working at PropertyPages and PageControls. (~1.5.0)

 

 

© Copyright (2000), Luigi Bianchi
Last Update: September 28, 2001