您引用的文章有一些問題。如果您在文章後面查看討論帖子,您會注意到一些評論指出了放置CEdit控件的問題。特別是,請查找「CEdit放置錯誤」。更重要的是,如果您查看發佈的代碼,您會看到對命令SetWindowPos進行了硬編碼調整。硬編碼調整從來都不是一個好主意。如果可能,應始終動態計算它們。
我成功地通過添加一行代碼並刪除硬編碼調整來解決定位問題。看到我的代碼如下。
RECT rect1, rect2;
// this macro is used to retrieve the Rectanle
// of the selected SubItem
ListView_GetSubItemRect(hWnd1, temp->iItem,
temp->iSubItem, LVIR_BOUNDS, &rect);
::MapWindowPoints(hWnd1, m_hWnd, reinterpret_cast<LPPOINT>(&rect), 2);
//Get the Rectange of the listControl
::GetWindowRect(temp->hdr.hwndFrom, &rect1);
//Get the Rectange of the Dialog
::GetWindowRect(m_hWnd, &rect2);
int x = rect1.left - rect2.left;
int y = rect1.top - rect2.top;
if (nItem != -1)
::SetWindowPos(::GetDlgItem(m_hWnd, IDC_EDIT1),
HWND_TOP, rect.left, rect.top,
rect.right - rect.left,
rect.bottom - rect.top, NULL);
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_SHOW);
::SetFocus(::GetDlgItem(m_hWnd, IDC_EDIT1));
//Draw a Rectangle around the SubItem
//::Rectangle(::GetDC(temp->hdr.hwndFrom),
// rect.left, rect.top, rect.right, rect.bottom);
//Set the listItem text in the EditBox
::SetWindowText(::GetDlgItem(m_hWnd, IDC_EDIT1), str);
我添加的行是MapWindowPoints到列表控制項的座標轉換爲對話框的座標空間。我也評論過在編輯框周圍繪製矩形,因爲它似乎沒有增加任何值。
聽起來像你有多個問題。您最關心的是什麼,並且可以顯示您正在使用的相關代碼? – rrirower
我的目標是讓列表能夠複製/粘貼數據和編輯單元格,我已經複製了文章中的所有代碼,但它的工作原理很奇怪,正如我所說的。也許我只是在錯誤的方向前進,但沒有太多有用的文章,我發現谷歌。 –