Answers to frequently asked questions during visual c ++ (including Windows API and MFC) development

Source: Internet
Author: User
Tags response code

Answers to frequently asked questions during visual c ++ (including Windows API and MFC) development

1. Briefly describe how to debug the program in vc6.
In the main menu "build", there is a start build sub-menu, which contains the go menu (shortcut: F5), after selection, the program will enter the debugging run from the current statement, until a breakpoint or program ends.
Move the cursor to the line of code to be debugged, right-click and Choose Insert/remove breakpoint, or press F9 to add a breakpoint on the line, in this case, a brown circle appears in front of the breakpoint code line, and you can clear the breakpoint again. After entering the debugging status, the Debug menu will appear in the menu bar instead of the build menu, which contains common debugging operations, such as step over, which is not tracked within the called function during one-step operation; other debugging methods include step into, step out, and stop debugging.
 
2. Briefly describe what is the role of files suffixed with. cpp,. H,. RC,. DSP,. DSW in the project created in vc6?
. Cpp is the c ++ file of the source code.
. H is the header file that contains the function declaration and variable definition.
. RC is a resource script file that defines resources.
. DSP is a project file that records information about the current project
. DSW is a workspace file. A Workspace may contain one or more projects.
 
3. It is known that there is an edit box control on a dialog box with the ID of idc_edit1, which is associated with the variable m_edit1 of the cedit type. Two methods are used, describes how to change the text inside the editing box to "hello" and write the code snippet.
Method 1: m_edit1.setsel (0,-1 );
M_edit1.replacesel ("hello ");
Method 2: setwindowtext ("hello ");
 
4. Briefly describe the structure of a basic Windows application framework written using Windows APIs.
The basic application framework written by Windows API should include at least the program entry function winmain and the window function wndproc. The main function winmain contains window class definition and registration, Window Creation and display, and message loop.
 
5. What is the data type of a message in Windows? What are its member variables and their meanings?
The data type of a message is MSG. It is a struct and its member variables mainly include hwnd, which indicates the window handle of the message; message indicates the type of the message; wparam and lparam include the additional information of the message, different messages.
 
6. What are the meanings of the long parameter lparam and the word parameter wparam for Windows mouse messages?
The low byte of the long parameter lparam of the mouse message contains the X coordinate value of the cursor position, and the high byte of lparam contains the Y coordinate value of the mouse cursor position; the wparam parameter contains values that indicate the status of various virtual keys currently pressed.
 
7. Notes about using a non-Modal Dialog Box and the Windows API functions used
When using a non-modal dialog box, be sure to include ws_visible in the style to display it normally. When creating a dialog box, use the createdialog function. In the message loop part, use isdialogmessage to filter messages. When closing the dialog box, use the destroywindow function.
 
8. Briefly describe the role of the updatedata function in the MFC application, its parameter meaning and usage.
Updatedata has only one bool type parameter. updatedata (false) is generally used to refresh the screen display of the variable value connected by the control in the dialog box; updatedata (true) is used to obtain the screen data to the variable connected by the control in the dialog box.
 
9. List the three message types that The ListBox control can accept and describe their functions
Lb_addstring is used to add a string to the list box; lb_dir is used to list the specified file in the list box; lb_gettext is used to obtain the text of the specified item.
 
10. In a dialog box, three single-choice buttons are added, so that they can be automatically mutually exclusive. What should I pay attention to? How can I operate in the VC environment?
To enable automatic mutex for a group of single-choice buttons, set the Control ID values consecutively and set the group attribute of the first single-choice button.
 
11. Briefly describe how to derive your own document class from a document class and what steps are required to achieve document access.
First, a corresponding document class is derived from cdocument for each document type. Then, a member variable is added to this document class to save the data. Finally, the serialize member function is reloaded to serialize the document data.
 
12. List the three subclasses of the View class (cview) and briefly describe their functions.
The cscrollview class provides Scroll display of views. The ceditview class supports text editing in views. The chtmlview class supports displaying and operating HTML files in views.
 
13. How does visual c ++ 6.0 go into the debugging status? In the debugging status, which debugging windows can be displayed and three debugging windows can be listed. What are the roles of these three debugging windows?
After debugging is started, some auxiliary debugging windows can be opened under the debug window sub-menu in the View menu.
Watch: display the window for viewing the variable value of the current statement and the preceding statement
Call Stack: displays the call stack display window.
Memory: display the window for viewing memory content
 
14. describes the steps for creating and displaying bitmap resources, and provides the corresponding Windows API function name.
First, define the bitmap handle hbitmap; second, use loadbitmap to load the bitmap; third, call createcompatibledc to apply for the Environment handle of the memory device to the system, and call the SelectObject function to select the bitmap into the memory device environment; step 4: Call the bitblt function to output the bitmap from the memory device environment to the specified window device environment to display the bitmap.
 
15. How to obtain the font handle to output the font and provide the corresponding Windows API function name.
First, define the font handle variable hfont HF. Then call the getstockobject function to obtain the font handle of the system, or call createfont to obtain the Custom font handle. Finally, call SelectObject to select the font handle to the device environment.
 
16. List the three button types, and describe the differences between their functions and the creation method.
Common buttons include common buttons, single-choice buttons, check boxes, and group boxes. The common button is used to help the user trigger a specified action. The single-choice button usually has Mutual Exclusion between options. The check box is used to display a set of options for the user to choose from. There is no mutual exclusion between options; the group box is used to divide controls into different groups and describe them.
 
17. What should I pay attention to when a static control displays a bitmap and accepts user input.
To make the static control display bitmap, you must set its style to include ss_bitmap, and specify and load the bitmap when creating the static control window, that is, when calling createwindow. To enable the static control to receive user input, the style must be set to ss_policy.
 
18. List the four types of action identifiers of the scroll bar control and describe their occurrence scenarios.
The action identifiers of common scroll bar controls include (for vertical scroll bars): sb_lineup indicates rolling up a row; sb_linedown indicates rolling down a row; sb_pageup indicates rolling up a page; sb_pagedown indicates rolling down a page.
 
19. describes how to use the system timer message (wm_timer) and the Windows API functions used
The method of using the timer message is: first call the settimer function to define the timer message, including the time interval of message generation, and then add the timer message response code in the corresponding wm_timer message processing; finally, killtimer is called to release the timer.
 
20. The MFC Application Wizard can create those types of application frameworks, which adopt the document/view structure.
The MFC Application Wizard can be used to create a single document (SDI)-based multi-document (MDI) and dialog box-based application framework. The first two types use the document/view structure.
 
21. List the five controls to describe their functions and the corresponding class names of the MFC.
Cstatic is a static text control window, which is used to label, separate dialog boxes, or other controls in the window. cbutton is a button control window, provides a general class for buttons, single-choice buttons, and multiple-choice buttons in a dialog box or window. cscrollbar is a scroll bar control window that provides the scroll bar function and is used as a control in a dialog box or window, it locates in a certain range. clistbox is the list box control window, and the list box is used to display a group of list items. You can observe and select it. cprogressctrl is the progress bar control window, indicates the progress of an operation.
 
22. In the documentation/View Structure of MFC, how does the View class access the document class? How does the document class notify the View class to update and provide the member method name?
In the document/View Structure of MFC, The View class obtains the pointer of the corresponding document class through its member method getdocument to access the data of the document class. The document class notifies all views through its member method updateallviews, the document has been modified and the view should be repainted.
 
23. briefly add an edit box in a dialog box-based MFC Application Framework (the control ID of the edit box is idc_edit1, and the variable m_edit1 has been connected to it ), the current time must be dynamically displayed in the format of "HH: mm: SS", such as "15:20:16". The code snippet is displayed for how to implement the refresh every second. (Tip: Use the timer settimer)
Implementation Method: implement the timer, send the wm_timer message every second, and add the Code Update edit box content to the corresponding function of the message.
Step 1: add the code settimer (1,100, null) to the Message response function oninitdialog of wm_initdialog in the dialog box );
Step 2: add the ontimer function for the message of wm_timer in the dialog box, and add the code in it:
Ctime tnow;
Tnow = ctime: getcurrenttime ();
Cstring snow = tnow. Format ("% I: % m: % s ");
M_edit1.setsel (0,-1 );
M_edit1.replacesel (Snow );
Step 2: add the code killtimer (1) to the Message response function ondestroy of wm_destryoy in the dialog box );

(Original yanqlv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.