Project Experience (further summary)

Source: Internet
Author: User

1. when we are working on a project, a variable is often associated with the controls used. but you know that when we associate a variable with a control. in fact, vs2003 has added an association for US (this seems like nonsense, but it is not. first)

When we modify the program again, it may be for some reason (ID conflict, re-define ID, etc ). then, modify the defined ID. when we call the program. at this time, there is no compilation Link error, and even after startup, if the current dialog box is not displayed, there will be no error. however, when we perform an operation, this dialog box is displayed with an asserted error. this asserted error is hard to locate.

In fact, because we have previously modified the ID, we cannot find the previous ID in the resource file, but in the resource. the H file does have the previous ID. this is because the dialog box resource file and. RC is consistent. resource. H is not deleted as we modify the ID. this is exactly what the compiler uses. the ID of the H file. so. difficult to troubleshoot.

2. Some errors about string processing.

1). First, we will discuss the conversion between string, cstring, char *, and Int.

I don't want to discuss it all here, but I just want to find some mistakes:

String Conversion to cstring: two methods are described here. One is to use string-based member functions. c_str () for conversion. however, if you want to convert multiple strings (or INT) to cstring, this method is powerless. here we will talk about another method: format.

When using this function, you should note that when we use % s to directly convert the string, there will be no compilation error or link error, but when running, an error occurred. this is also difficult to locate. the reason is that the % S parameter cannot be of the string type. it should be char * type.

2). The last question is about the string operator.

When processing time, we often need to process the number of seconds since January 1,. When we get this number of seconds for comparison, we often make an error. Please refer to the example:

Stringstrtime1;

Stringstrtime2;

If (strtime1> strtime2)

{

Something;

}

Else

{

Something;

}

It is often believed that the size of the two can be compared as long as such a simple judgment. In fact, it is not.

What will happen if I enter the following two values?

8

10

Obviously 10> 8, but the program cannot output normally. The main reason is that the Relational operators of string will be compared in order, regardless of the length of your string.

The easiest way to solve this problem is to compare the size. Simply convert it to int by using atoi.

During encoding, we often see how many characters a string is intercepted.

For example, string: "YSL yuan Sun Liang" I want to extract the first four characters. we cannot simply use the cstring: Left function. because there is a problem with "Yuan", what will happen when it is displayed? (That is, the output is "YSL? ")

In fact, if we know that the strings are both Chinese or English, this problem is relatively simple, but we still need some skills to mix them.

Here I will provide a function:

// Extract the STR string with nmaxlen characters.

Void interceptlenth (cstring & STR, int nmaxlen, cstring & Strout)
{

Int I = 0;
Int last = 0;

// Copy the first address to S
Char * s = Str. getbuffer (Str. getlength ());

Char * pre = s;
While (I <nmaxlen)
{
Char * Next = (char *) charnext (s); // save the next character
Int n = strlen (pre)-strlen (next );

Cstring str1;
Str1 = Str. mid (last, N );

Strout + = str1;

Last + = N;
S + = N;
Pre = next;
I ++;
}
}

 

Menu errors:

We use appendmenu to add menus to the system. When we need to operate this menu dynamically, it is inevitable that the menu will be cleared.

3. Our clearing operations are generally as follows:

Voidclearmenu ()

{

// Remove the original menu item

Int submenu1count = m_menu.getmenuitemcount ();

For (INT I = 0; I >= submenu1count-1; I ++)

{

M_menu.deletemenu (I, mf_byposition );

}

Return;

}

In this way, it seems that there is no problem. however, we did not notice that when we delete the first item, the entire menu will change. that is, the original 1 is changed to 0, and the original 2 is changed to 1. and so on. therefore, we should use the following method to delete it.

Void clearmenu ()

{

// Remove the original menu item

Int submenu1count = m_menu.getmenuitemcount ();

For (INT I = submenu1count-1; I> = 0; I --)

{

M_menu.deletemenu (I, mf_byposition );

}

Return;

}

Conclusion: When we use a loop, we usually use both the forward and backward search methods, but in some cases, the forward search will be more universal.

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.