How to mix two major Application Framework VCL & MFCs below C ++ Builder 3.0?

zhaozj2021-02-11  175

How to mix two major Application Framework VCL & MFCs below C Builder 3.0?

Mixing VCL and MFC is indeed a good choice, but relative, your program complexity will increase. In this first assume that you have seen this article "How to compile the MFC program in C Builder 3.0". Therefore, some basic knowledge is not repeated. In order to discuss this topic, I decided to use the examples of the way to explain: Step 1. First use the method you know to create an empty, and you can correctly compile the MFC's Project (you can refer to "How to in C Builder 3.0 compiles the program containing the MFC. "This article). In this first, it is assumed that this Project name is Project1, while MainForm is Form1, MainForm file is Unit1.cpp, which is generated by BCB 3.0 as default, so you should have the following files:

Project1.bprproject1.cppUnit1.cppunit1.hunit1.dfm

Step 2. In this example, I decided to use two MFC categories (Class) to mix C Builder's VCL, and these two categories are CFiledialog and CPOINT. OK, I know these, let's first design some things on Form use the MFC category! Put two Label components and a Button component Step 3.Thim, it is to start joining the MFC code you want, but before this, you must first use the announcement file used by the MFC to add: // --- -------------------------------------------------- ---------------------- # include #include #include But pay attention to, MFC The Header file used should be before #include ! Otherwise, you will definitely get a lot of Error when compiling! Step 4. When the Header file is set, we started to make a mix of VCL and MFC! Let's first use the cpoint category! Establish ONMOUSEMOVE for Form and add the following code: void __fastcall tform1 :: formousemove (Tobject * sender, tshiftstate shift, int x, int y) {cpoint ps; ps.x = x; ps.y = Y Label1-> CAPTION = "x:" (ANSISTRING) PS.X "Y:" (ANSISTRING) ps.y;} OK, so you can compile! However, when you compile, you will get a lot of Warning because some of the same names in MFC and BCB, so, you will get these Warning make normal! Fortunately, just warning instead of Error, otherwise it can't be compiled. After the compilation is successful, you can find that when you move the mouse, Label1 on the FROM will always show your current mouse cursor, so that using cpoint this category is successful.

You may think that you can use the X and Y I have passed directly, why bother to use the cpoint category? Hey, if you don't do this, how to express MFC and VCL mix? STEP 5. Well, then we will come to the CFILEDIALOG category to create an OnClick Event on the BCB, add the following: void __fastcall tform1 :: button1click (Tobject * sender) {cfiledialog DLG (True , "CPP", "*. CPP", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T ("C Source File (* .cpp)")))))); if (DLG.Domodal () == iDok) {label2-> caption = (ANSISTRING) Dlg.getPathname ();}}, you get a lot of Warning when compiling, but after compiling, press this button you will get the same picture as the TopEndialog class in the VCL, when you choose Form Label2 will also be replaced with the name of the file you selected, so that CFiledialog and VCL mix are also the same. In this example, you can learn MFC and VCL mix. However, some of the problems that have left will wait for solving, such as how should Warning when compile? In my habit, I won't let the compiler tell me any warning. How to solve it? Smart readers, moving brain!

转载请注明原文地址:https://www.9cbs.com/read-4903.html

New Post(0)