Use the MFC class library in Win32 applications)
Forward comments
The auxiliary classes in MFC, such as cfiledialog, cfilefind, and cstring, are very convenient to use. If you use APIs to complete the corresponding work, you need to do a lot of repetitive work on your own, the auxiliary classes of MFC can save a lot of development time. The specific method is as follows: 1. add the corresponding header file
Because the SDK must contain windows. h header file, so when using the class in MFC, such as adding afx. the header file of Type H has a prompt with windows. h conflicts. The solution is to remove windows. h, and then in all. add # include "stdafx. h"
# Define vc_extralean // exclude rarely-used stuff from Windows headers # include <afxwin. h> // MFC core and standard components # include <afxext. h> // MFC extensions
# Include <afxdisp. h> // MFC automation classes
# Include <afxdtctl. h> // MFC support for Internet Explorer 4 common controls # ifndef _ afx_no_afxcmn_support
# Include <afxcen. h> // MFC support for Windows Common controls # endif // _ afx_no_afxcmn_support
Note that you must add these lines before all header files, but it is recommended that you do not change the order, otherwise there will be a large number of error messages. 2. Change compilation settings
Choose use MFC in a shared DLL or use MFC in static library from project> setting> General, change the use runing-time library in project-> setting-> C/C ++ from single-threaded to multithreaded.
\
Method 2:
How to enable Win32 applications to support the MFC class library
15:03:06 | category: programming column | Tag: Win32 application MFC class library Configuration | font size subscription
When we call a console program, there is always a black DOS box flashing. Many times we don't want the black box to appear, because it makes people feel particularly bad, however, if it is a console program, it cannot be avoided. Isn't it possible? Of course not. We can choose to create a Win32 Application in vs. Although it is a window program, however, we can hide the window instead of blinking, but
Win32 applications cannot use the MFC class library, which causes inconvenience to programming. Next I will teach you how to support the MFC class library in Win32 applications. Let's get started!
First, add the following header file statement to the file: # ifndef vc_extralean
# Define vc_extralean // exclude rarely used information from the Windows header # endif
# Include <afx. h>
# Include <afxwin. h> // MFC Core Components and standard components # include <afxext. h> // MFC extension
The above code can be placed in the pre-compiled header file stdafx. H. You can set the position.
And then add it at the beginning of _ twinmain.
If (! Afxwininit (hinstance, null, lpcmdline, 0 )){
MessageBox (null, _ T ("MFC init error! "), _ T (" error! "), Mb_ OK); Return 0 ;}
Select "Project-> properties-> Configuration properties-> General-> Use of MFC" from the menu and select "use MFC in shared DLL ";
Then select "Project-> properties-> Configuration properties-> linker-> General-> additional library directory" in the menu to add "kernel32.lib user32.lib gdi32.lib ", separated by spaces. If the following error occurs during compilation:
Fatal error c1189: # error: Windows. h already supported ded. MFC APPs must not # include <windows. h>
In the pre-compiled header file stdafx. H, delete or comment out "# include <windows. h>". Now everything is OK, and you can use the MFC class.
Note: although we can create an MFC application and then hide the window to solve this problem, the size of the generated EXE file is larger than that of the previous two files, because it loads a lot of resources that we don't need, resulting in waste.