It is a grate chose to combine the VCL and MFC together.
But, this way will make you program to be more complex.
In this article, I assum that you have readed another atricle"
How to compiler the program with MFC classes in BCB 3.0 ?". So, I will not tell you something that I have told.
To discussing this topic, I try to use the way "doing it
step by step" to tell you how to do it.
Use the way you know to build a project that can compiler MFC correctly in BCB 3.0.(Use
the TApplication to be the main class) In this case, I assum that the project file was
named as "Project1.bpr" , and the MainForm was named as "Form1".
In this way, you should have these file list below :
In this example, I decide to use two classes of MFC to combine the VCL of BCB together.
These two classes are "CFileDialog" and CPoint.
First, you put something on the Form1 as "Figure. 1".
Then, you can add the MFC code here. But, you must include the MFC header file first.
There is one thing that you should know . you must include afxwin.h before vcl.h ,
otherwise you will got lots of errors from compiler.
Ok, that do it.
First, I use the CPoint. You must key in this code below in the OnMouseMove event of
void __fastcall TForm1::FormMouseMove(TObject
*Sender, TShiftState Shift,
int X, int Y)
Label1->Caption = "X :" + (AnsiString)Ps.x + " Y
:" + (AnsiString)Ps.y;
Ok, you can try to compiler this project. But you will see that there are lots of warrings
from compiler. Don't worry, because of there lots of marcos and virtual functions in MFC
are not defined so fine, so the compiler find it out.
After compiler and run this program, you will find that the Label1 will show the mouse
position when you moving the mouse. In this way, we make the MFC and VCL combine together
And then, that as use CFileDialog class of MFC in BCB.
In the "OnClick" Event of Button1, add these codes
void __fastcall TForm1::Button1Click(TObject
if( dlg.DoModal()==IDOK )
You will got lots of warrings and the CPoint example. But after running this program.
click the Button1 and you will got the same Dialog as TOpenDialog
in VCL . After chosing the file, you will find out the Lable2 of Form1will show the name
of the file you selected. In this way, we make the CFileDialog work together with VCL too.
Download the example
that you should know
In this example, you can learn how to combine MFC and VCL together. But, therer
are lots of compiler warring that we should solve it. In my opinion, I can bare that there
are lots of warrings generated from the compiler. How to solve it? Wise reader, use
your brain to find it out!