 |
1樓
巨大八爪鱼
2015-11-28 14:07
运行结果: 
|
 |
2樓
巨大八爪鱼
2015-11-28 14:07
|
 |
3樓
巨大八爪鱼
2015-11-28 14:08
点击OK按钮后出结果: 
|
 |
4樓
巨大八爪鱼
2015-11-28 14:30
 还能支持汉字(因为wchar_t字符数组支持汉字字符)
|
 |
5樓
巨大八爪鱼
2015-11-28 14:31
|
 |
6樓
巨大八爪鱼
2015-11-28 14:32
生成的程序文件: 
|
 |
7樓
巨大八爪鱼
2015-11-28 14:33
|
 |
8樓
巨大八爪鱼
2015-11-28 14:33
 详细信息
|
 |
9樓
巨大八爪鱼
2015-11-28 14:35
程序核心代码:(鼠标点击OK按钮后执行的内容) void CInsertStrDlg::OnBnClickedOk() { // TODO: Add your control notification handler code here //CDialogEx::OnOK(); int len1, len2, i, pos; UpdateData(); len1 = mString1.GetLength(); len2 = mString2.GetLength();
/* Find the position */ for (pos = 0; pos < len1; pos++) { if (mString1.GetAt(pos) == mString2.GetAt(0)) break; // found; } // When not found, pos == len1
/* Move */ mResult = mString1 + CString(' ', len2 + 1); // lengthen the string if (pos != len1) { for (i = len1; i >= pos - 1 && i >= 0; i--) { // At first when i == len1, the character is '\0' // and then '\0' will be moved to the end mResult.SetAt(i + len2 - 1, mString1.GetAt(i)); } }
/* Copy chars from s2 to s1 */ // copy the first character of s2 if (pos == len1) mResult.SetAt(len1 + len2, '\0'); // when not found, the moving wasn't executed, so '\0' was not copied for (i = 0; i < len2; i++) mResult.SetAt(pos + i, mString2.GetAt(i));
UpdateData(false); }
其中mString1绑定的是第一个文本框,mString2是第二个文本框,mResult是第三个只读的文本框。
|
 |
10樓
巨大八爪鱼
2015-11-28 14:36
初始化函数(BOOL CInsertStrDlg::OnInitDialog())中的初始化代码: // TODO: Add extra initialization here mString1 = "abcdef"; mString2 = "d45"; UpdateData(false); 这是在窗口程序启动后默认在两个文本框中显示的内容。
|