簡體   English   中英

EM_SETSEL 在.docx(word 文檔)中不起作用

[英]EM_SETSEL not working in .docx (word document)

我正在開發一個將 WM_COPY 發送到 open.docx 文件(word 文檔)的簡單程序。 我在其他應用程序上測試了我的代碼,它似乎一切正常。 但是,每當我嘗試在打開的 Word 文檔上使用我的代碼時,它都會在SendMessage(hwndChild, EM_SETSEL, 0, -1)處返回 false。

我嘗試了幾件事:

  • 在記事本(非富文本)和便箋(富文本)上使用代碼,它與下面的代碼完美配合。

  • 刪除SendMessage(hwndChild, EM_SETSEL, 0, -1)行,然后手動突出顯示 word 文檔中的文本並運行程序。 它在 WM_COPY 的幫助下成功並將內容復制到剪貼板。

有誰知道為什么EM_SETSEL在 word 文檔中不起作用?


int main() {
    HWND app = FindWindowEx(0, 0, "OpusApp", 0); 
    EnumChildWindows(app, EnumChildProc, (LPARAM) NULL);

    return 0;
}


BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) {
    uint8_t max_path_length = 255;
    char *str = new char[max_path_length];
    memset(str, 0, max_path_length);
    GetClassName(hwndChild, str, max_path_length);

    /// Execute when edit handle is obtained
    if(strcmpi(str, "_WwG") == 0) {
        if(SendMessage(hwndChild, EM_SETSEL, 0, -1)) {
            SendMessage(hwndChild, WM_COPY, 0, 0);
        } else {
            MessageBox(0, "Can't select all!", "Report", MB_OK);
        }
    }

    str = NULL;
    delete [] str;
    return TRUE;
}

EM_SETSEL僅適用於編輯控件。 我懷疑 Word 使用標准控件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM