1stOpt批量处理方程
1stOpt是一款世界领先的非线性曲线拟合,综合优化分析计算软件平台
但是软件读入文件和保存结果实在是太复杂了,很难做到批量处理数据
基于此,设计了一个能批量处理方程的小程序,以input.txt文本文件内容为输入,以output.txt文本内容为输出
首先用Spy++获取1stOpt的窗口信息,获得代码输入框的handle和结果显示的handle,用sendmessage的方法设置文本获取文本
HWND hWndMain,hWndPage,hWndTRzTabSheetEdit,hWndTRzTabSheetResult,hWndTEditorFormEdit,hWndTSynEditEdit,hWndTSynEditResult; CFile fileInput; if (fileInput.Open(_T("input.txt"),CFile::modeRead) ==NULL) return 1; char *buf=new char[fileInput.GetLength()+1]; memset(buf,0,fileInput.GetLength()+1); fileInput.Read(buf,fileInput.GetLength()); fileInput.Close(); hWndMain = ::FindWindow(NULL,_T("1stOpt - [Untitled1]")); if(!hWndMain) { return 1; } hWndPage = ::FindWindowEx(hWndMain,NULL,_T("TRzPageControl"),NULL); hWndTRzTabSheetEdit = ::FindWindowEx(hWndPage,NULL,_T("TRzTabSheet"),_T("代码本 1 - [Untitled1]")); hWndTEditorFormEdit = ::FindWindowEx(hWndTRzTabSheetEdit,NULL,_T("TEditorForm"),NULL); hWndTSynEditEdit = ::FindWindowEx(hWndTEditorFormEdit,NULL,_T("TSynEdit"),NULL); int iRequiredSize = ::MultiByteToWideChar(CP_ACP, NULL, buf, -1, NULL, 0); WCHAR* pwchString = new WCHAR[iRequiredSize]; ::MultiByteToWideChar(CP_ACP, NULL, buf , -1, pwchString, iRequiredSize); //CopyTheFileToEditor ::SendMessage(hWndTSynEditEdit,WM_SETTEXT,0,(LPARAM)pwchString); delete [] pwchString; delete [] buf; //F9 ::Sleep(10); ::SendMessage(hWndMain,WM_KEYDOWN,VK_F9,0); ::SendMessage(hWndMain,WM_KEYUP,VK_F9,0); WCHAR bufResult[10000]; //Sleep for a while ::Sleep(100); hWndTRzTabSheetResult = ::FindWindowEx(hWndPage,NULL,_T("TRzTabSheet"),_T(" 结 果 ")); hWndTSynEditResult = ::FindWindowEx(hWndTRzTabSheetResult,NULL,_T("TSynEdit"),NULL); while (1) { //ReadResult ::SendMessage(hWndTSynEditResult,WM_GETTEXT,10000,(LPARAM)bufResult); if (wcsstr(bufResult,_T("======")) != NULL ) break; //Sleep for a while ::Sleep(100); } CFile fileOutput; fileOutput.Open(_T("output.txt"), CFile::modeCreate | CFile::modeWrite); setlocale(LC_ALL, "chs"); UINT resultLen = wcslen(bufResult); char * pChar=new char[resultLen*2]; memset(pChar,0,resultLen*2); wcstombs(pChar,bufResult,resultLen*2); fileOutput.Write(pChar,resultLen*2); fileOutput.Close(); delete [] pChar;