目前共有22篇帖子。
今天,我把C語言課本上第211頁的那個程序改成了Windows窗口程序的版本
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);
這是在窗口程序啟動後默認在兩個文本框中顯示的內容。

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
 
 
©2010-2025 Arslanbar [手機版] [桌面版]
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。