Summary of common problems in MFC

Source: Internet
Author: User

4. For cedit, clist, and other classes, you can drag and drop them to the window in the resource view. You can also add them dynamically in the Code. The create () function must be called dynamically,
Then, use the movewindow () or setwindowpos () function and showwindow () function to display or not display the function, or enablewindow () to compile or gray the function.

5. For a tab page, the Dialogue attribute of the tab page must be: style-> child, border-> none. If the style attribute is not child, the form will not
But outside.
Sat. In the combox control, if movewindow or setwindowpos is used, the height is large, indicating the maximum length of the drop-down box when you click. When it is small, there is no drop-down box.

7. The tab order of the control is related to the movewindow or setwindowpos order of the Call (you can also use ctrl-DTO adjust the order in the resource, but dynamic creation is not acceptable), movewindow
The call sequence is the same as the call sequence, while the setwindowpos sequence is the opposite (that is, the reverse order)

8. In the combox drop-down box control, the onsize () function of the form must be dynamically adjusted using the movewindow function, as shown below:
M_cmbtemp.movewindow (rcctl. Left, rcctl. Top, rcctl. Width (), ncmbdropheight, false)
// Ncmbdropheight determines the length (not the width) of the drop-down list. If it is set to a small value, the drop-down list cannot be displayed.

9. The skin file can restrict the form. If the title bar of the form is incomplete, it may also be the cause of the skin file...

10. Function for converting cstring to BSTR: allocsysstring ()

11. Use \ r \ n instead of \ n for line feed in cedit.

12th. When hhc.exeis used to compile a .chm file, the link. txt file is out of order. The code may be a line break using \ n. Try \ r \ n. Maybe this is the problem.

13th. In the drop-down box, it is best not to use index to judge and set it, but to use the value obtained by windowtext.

Fourteen. How to intercept the win + d key in Windows:

Bool cmydilog: pretranslatemessage (MSG * PMSG)
If (PMSG-> message = wm_keydown)
Switch (PMSG-> wparam)
Case vk_escape:
Setfocus ();
Return true;
Case 'D ':
If (: getkeystate (vk_lwin) <0)
MessageBox ("hello ");
Return true;

Return cdialog: pretranslatemessage (PMSG );

If (: getkeystate (vk_lwin) <0)
Qdebug () <"wm_keydown = MSG-> message: getkeystate (vk_lwin): True 234234 ";
If (: getkeystate ('D') <0)
Qdebug () <"wm_keydown = MSG-> message: getkeystate ('D') <0 ";

Return true;

* Function name: cstring2char
* Parameter 1: cstring STR string to be converted
* Parameter 2: location to be stored after char ch [] Conversion
* Convert the cstring in Unicode to char *

Void cstring2char (cstring STR, char ch [])
Int I;
Char * tmpch;
Int WLEN = widechartomultibyte (cp_acp, 0, STR,-1, null, 0, null, null); // get the char Length
Tmpch = new char [WLEN + 1]; // assign the address size of the Variable
Widechartomultibyte (cp_acp, 0, STR,-1, tmpch, WLEN, null, null); // convert cstring to char *
For (I = 0; tmpch [I]! = '\ 0'; I ++) CH [I] = tmpch [I];
Ch [I] = '\ 0 ';

The function for converting cstring to int is:

If you want to use Unicode characters, you should use _ ttoi ()

Use of the mfcgridctrl control:
1. Add the. cpp (6) and. H (8) files involved in the control to the project.
2. Drag custom control from the toolbox, right-click the control property, and set the class item to mfcgridctrl.
3. In the project header file, # include "gridctrl. H" and define the variable cgridctrl m_ctrlgrid;
4. In the project definition file, add ddx_gridcontrol (PDX, idc_custom1, m_ctrlgrid) to the dodataexchange function (assuming that the Control ID is idc_custom1)
5. Use the table control where you need it. For example: m_ctrlgrid.setrowcount (10 );
M_ctrlgrid.setcolumncount (3 );

Difference between cstring. tokenize and afxexactsubstring: the former is ignored when multiple consecutive delimiters are encountered, and the latter is separated into null strings.

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: 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.