我正在编写一个自定义模块来使用专有软件。(该软件已经停产,我没有它的源代码。)我的模块将作为一个单独的进程运行。它的目标是通过这个专有软件使操作自动化。为此,我需要能够模拟保存该软件的输出。我可以通过模拟工具栏按钮单击来调出其另存为对话框:
然后我尝试将“另存为类型”组合框更改为所需的文件类型,添加要保存到的文件路径,并模拟单击“保存”按钮。我想出了以下代码来做到这一点:
//All I have to work with are the following window handles:
//HWND hWndFileName = file name window handle
//HWND hWndSaveAsType = save as type window handle
//HWND hWndSaveBtn = Save button handle
DWORD dwComboIDSaveAsType = ::GetWindowLong(hWndSaveAsType, GWL_ID);
HWND hParWnd = ::GetParent(hWndSaveAsType);
//Select index for file type
int nSaveAsIndex = 3;
::SendMessage(hWndSaveAsType, CB_SETCURSEL, nSaveAsIndex, 0);
::SendMessage(hParWnd, WM_COMMAND,
(dwComboIDSaveAsType & 0xffff) | ((((DWORD)CBN_SELCHANGE) << 16) & 0xFFFF0000),
(LPARAM)hWndSaveAsType);
//Set path to save
::SendMessage(hWndFileName, WM_SETTEXT, NULL,
(LPARAM)L"C:\\Test\\test file");
//Simulate Save button click
::SendMessage(hWndSaveBtn, BM_CLICK, 0, 0);
有趣的是,上面的代码实现了目标(通过直观地更改“另存为类型”组合框)但是当文件被保存时,它仍然具有旧的或最初选择的类型,即“快速报告文件(.QRP)”。
知道如何解决这个问题吗?