Visual C 6.0 (5.0) development tools are very powerful, but for beginners, there are many details questions. The author collects the following practical tips, I hope to help beginners. 1: When using the VC development project, this will often encounter this situation: that is, it is clear that only one file is changed, but all the projects are all re-connected. Just connected, once, and prompt to recompile the connection once, very annoying. This is because there is a future file. Workaround: Find out the debug directory under the corresponding folder, all DELETE, and then Rebuild All. (Future files are compared to system time) 2: Sometimes, the classview in Workspace shows confusing. It is as follows: (1): The added member variable or function cannot be displayed; (2): Even if the variable or function is displayed, double-click the correct location. Workaround: Delete .ncb file, rebuild all. 3: How to clean a class? 1: First remove the corresponding .h and .cpp file from the FileView in Workspace. 2. Turn off the project and remove the corresponding .h and .cpp file from the actual folder. 3. Remove the .clw file. Open the project, Rebuild All. 4: Beginners often have such doubts: Directly hope that the project file is added to a CPP original file and compile the connection. Otiend is not to find a pre-translated header solution: #include "stdafx.h" 5: How to join yourself to the project The defined class? Many ways to introduce a simple: Select the INSERT / New Class menu pop-up dialog; select Class Type for generic; enter the class name. Of course, you can also determine the base class 6: How to import multiple items in the workspace (Workspace)? After opening a project (* .dsp file), use the "Project" menu Insert Project Into Workspace Submenu Select another project file (* .dsp file) to insert another project. In the ClassView view, the right click can activate one of the items, and the workspace is inserted into multiple projects. It can be easily copied between different items, resources, etc. 7: How much is the class in the ClassView view? We can first click New Folder in the ClassView view, and drag the class with similar nature to the corresponding folder, so that the entire view looks clear. 8: How to quickly delete a project under the Debug folder? Select the corresponding item in the FileView view, right click Clean. 9: Open a large project editing operation of a source file is very slow, what should I do? Don't open the project file (* .dsp file), open the individual source file (* .h or * .cpp) to edit (* .h or * .cpp) to edit, Many. 10: If you want to copy the entire project to the floppy disk, can those files can be deleted? In addition to the project folder, the DEBUG folder can be deleted, .ncb, .clw, .opt can also be deleted, these files Rebuilt all can be re- generate.
11: How to quickly generate a new project that is exactly the existing project except for the project except? Use the File menu to generate the Custom AppWizard in a new project, select An EXISTING PROJECT, then select the project file name of the existing project (* .dsp ) Finish, after compiling, generates an appWizard that can generate the same that is the same but you can rename the name of the existing project. You can use it like MFC AppWizard. If you don't want to use it, you can delete this Wizard and .pdb file in the COMMON / MSDEV98 / TEMPLATE directory in the VC installation directory. 12: How to locate the cursor in the source file to the symmetrical {} and #IF? #ENDIF? The former uses the CTRL and "}" keys, the latter uses the Ctrl and "K" keys. 13: How do I set the header file and library file in the VC? In addition to the VC default header files and library files, if you often use a third-party header file and library files can be set in the Directories for Tools Options. If you are just this project, you can set the library file in the Project Setting-> Link Object / Library Modules. 14: If the console application supports the MFC class library? You can introduce the MFC library in the console application, but the console application is single-threaded, MFC is multi-threaded, in order to solve this contradiction, in the Project Setting-> C / C option, select Code Generation, Select Debug Multithread in the Use Run-Time Library drop-down box. 15: How to add an ODBC function for an MFC application? (1) Add the following line at the end of the file stdafx.h file: #include // MFC ODBC Database Classes (2) Edit the RC file in text mode (using the file-> open as text method) in the following procedure line (two Place #include "l.chs / afxprint.rc" // printing / print preview resources Add Next line: #include "l.chs / afxdb.rc" // Database Resources 16: How to quickly update one after the database table modification CRECORDSET recordset bound to the table? Use UpdateColoumns and Bind ALLs after selecting the record category under the MEMBER VARIABLES tab. 17: How to Chinese only if there is an executable code ?exe file? Using VC Open file in NT to open the * .exe file in the resources method, the resource file is directly modified, and then saved. 18: How can I build a wait cursor? Call the BeginWaitCursor function to start the wait cursor, call the endwaitcursor function to end the wait cursor. It is to be noted that both the two members functions are called, as shown below: AFXGetApp () -> beginwaitcursor (); // To do things AFXGetApp () -> endwaitcursor (); 19: What is colorref? What should I do? Use it? ColorRef is a 32-bit integer value, which represents a color. You can use the RGB function to initialize ColorRef.
For example: ColorRef color = RGB (0, 255, 0); RGB function receives three 0-255 values, one represents red, a representative green, one represents blue. In the above example, the red and blue values are 0, so there is no red and blue in this color. Green is a maximum of 255. So this color is green. 0,0,0 is black, 255, 255, 255 is white. 20: I am CDWORDARRAY in my program. I added approximately 10,000 integers to it, which makes it very very slow. CdwordArray is very easy to use, just because you don't specify the maximum size of the array. Therefore, when you add new elements, this class will reassign space from the heap. Unfortunately, this class reassigns space for array every time inserting new elements. If you add a lot of new elements to it, all of these assignments and replication arrays will make it slower. Solving this problem is that you can use the second parameters of the setsize function to change this reassigned frequency. For example, if you set this parameter to 500, it is reassigned and add 500 new space each time the array space is exceeded. Instead of 1. In this way, you can add another 499 elemental space without reassign, which greatly improves the running speed of the program. 21: What is the STDAFX file generated by AppWizard? It is mainly to assist in generating pre-translated headers. Usually you don't need to modify it. 22: In some parts of my program, I can call the MessageBox function to create an information dialog, such as in the view class. However, I can't, such as the document class in other parts. why? How can I create a message dialog box in my application class? The MessageBox function is from the CWND class, so you can only call it from the CWND inheritance class (such as cView). However, the MFC also provides an AFXMessageBox function that you can call it anywhere. 23: I need to set global variables in my program to enable all classes in the document to access. Which should I put it? Put the variable in Attribute in the header file of the application class. Then, in any part of the program, you can use the following method to access the variable: cmyapp * m_app = (cmyapp *) AFXGetApp (); m_app-> myglobalvariable = ...; 24: I heard that MFC can find memory Vulnerability, how do I use this feature? If you run your application if you go in the Go option in the Debug menu (not the Execute option in the Project menu), the MFC should report the memory vulnerability when the program terminates. If not, try run the MFC Tracer Toolbox (in the VC program group) and start tracking. Then return to the application. 25: How can I speak in my application to browse the already opened document? Using the getFirstDocPosition () and getNextDoc () functions in CDOCTemplate. 26: How can I get a loop in my app? Use the getFirstViewPosition () and getNextView () functions that are not disclosed in CDocument. 27: What is the virtual function precreateWindow? PrecreateWindow allows you to change the window properties before calling CREATEWINDOW.
28: How should I prevent MFC from adding a document on the window title bar? Remove the window style of the FWS_ADDTITITE flag in the PrecreateWindow function: cs.style & = ~ fws_addtotitle; 29: How should I prevent MFC from putting the document name on the window title bar Preset into the application name? Window style of the FWS_PREFIXTITLE flag in the PrecreateWindow function: cs.style & = ~ fws_prefixtitle; 30: I have a Mode dialog. How can I remove the CDIALOG object when you exit? Add "delete this" to postncdestroy. This is mainly used in applications where you need to automatically delete objects. 31: Why put "DELETE THIS" in PostncDestroy instead of OnNCDESTROY? Oncdestroy is only called by the established window. If the setup window fails (such as PreCreateWindow), there is no window to send a WM_NCDESTROY message. Postncdestroy is completely deleted in the object window, after the onNCDESTROY, even after the window is established. 32: Where did the MRU list in the File menu come from? Where is the name in the list? How can I change the maximum value in the list? In the invocation of LoadStdprofileSttings in the initInstance function of the application class. This call accepts a parameter (4) in the default. The MRU file name is called from the INI file. If you have a menu option with ID_File_MRU_FILE1, it will replace it for the transferred MRU list. If you change the value (maximum 16) passing to LoadStdprofileSettings, you change the maximum value of the file name. 33: Use Chinese VC (VC can use Chinese in Chinese platform, but after compiling, the Chinese on the dialog box is ASCII code) because VC is installed by default by default, but Chinese characters are double-byte coding, naturally not displayed correctly. Workaround: Copy the Chinese resource language module appwzchs.dll on the DEVSTUDIO / SHAREDIDE / BIN / IDE path on the VC CD to the hard disk devStudio / SharedIde / Bin / IDE path. 34: Use the bitmap button (can generate a dynamic effect) Select the button to use the bitmap (with the OK button as an example, assume its identifier as an IDOK), select the Owner DRAW option in its property (must), at this time In the dialog editor, you can see the characters originally displayed on the button disappeared. Change the CAPTION of the button to OK (must be uppercase). Open the INSERT menu, click on the Resource Option, then select Bitmap. Press the Import button again to import the desired bitmap (Project). In the Resource View window, you can change its ID (identifier) to "OKU" in the Resource View window (Note: Character must be uppercase) Double quotation marks and letters U must be indispensable. The button represented by the letter U is a bitmap displayed when the state is pressed. In addition, the suffix D, F, X, respectively indicate that the button is in an invalid state, respectively, and the button is in an invalid state, respectively. By using different bitmaps for different states of the same button, it is easy to make a button with a dynamic effect.
When you import the bitmap you want to use into the project, you should add the definition of the bitmapbutton m_ok in the class declaration file of the dialog using the bitmap button. When you use the Bitmap, add the following statement: m_btonok.autoload (IDC_BTONOK) to load the bitmap to memory and display the program at runtime. At this point, the entire step of creating a bitmap button is ending. 35: The use of the common dialog box has encountered the CFileDialog file dialog box. Its parameters make people headache. Let's take a headache in the following file dialog box. TRUE, "AVI", "*. Avi"). Subsequently, the following statement is added to the place where you need to use this dialog: m_myopendialog.domodal (); you can preview all .avi files. Their calling rules are: Function prototype: cfiledialog (Bool BopenfileDialog, lpctstr lpszfilename = null , DWORD DWFLAGS = OFN_HIDEREADONLY | OFN_OVERWRITEPR OMPT, LPCTSTER LPSZFILTER = NULL, CWND * PPARENTWND = NULL); Parameter Description: BopenFileDialog: True or False. TRUE is open file; false is saved. LPSZDefext: For the default extension. LPSZFileName: To display the file name of the edit box of the file name combo box, a general optional NULL DWFLAGS: is a dialog style, generally for OFN_HIDEREADOONLY | OFN_OVERWRITEPROMPT, that is, hidden read-only options and override existing files prompt. LPSZFILTER: Displays the file type in the drop-down list. PparentWnd: NULL is generally available. For example: To display an "executable file (* .exe)" in the editing box of the file type list box, "Video File (* .AVI), all files (*. *)" Is listed in its drop-down list box. Content, the variable is defined as follows: CFiledialog M_MYOPENDIALOG (True, "EXE", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Executable file (* .exe) | * .exe | Video file (* .bat) | * .bat | All Files (*. *) | *. * || ", NULL); Note: See if it is not *. * After || Is it effect. 36: How to add a class-free class? Turn right in ClassView NEW Class Class Type Select Generic Class, fill in Class Name. 37: How to define COBJECT-based classes? Generate new classes according to Question 4 template. Open the Properties dialog box for the new menu option.