15,979
社区成员
发帖
与我相关
我的任务
分享
DWORD g_nCmdProcessID = -1;
HWND g_hwndCmdProcess = NULL;
BOOL CALLBACK EnumCMDProcess(HWND hwnd, LPARAM lParam)
{
CWindow myWindow;
myWindow.Attach(hwnd);
if(g_nCmdProcessID == myWindow.GetWindowProcessID())
{
g_hwndCmdProcess = hwnd;
}
return TRUE;
}
void CDlgFileString::OnStringRunincommandwindow()
{
// TODO: Add your command handler code here
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
TCHAR wszCmdLine[100] = _T("cmd");
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
wszCmdLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
return;
}
g_nCmdProcessID = pi.dwProcessId;
g_hwndCmdProcess = NULL;
for(int nWaitCmdWndTimes = 0; nWaitCmdWndTimes < 3; nWaitCmdWndTimes++)
{
if(g_hwndCmdProcess == NULL)
{
EnumWindows(EnumCMDProcess, 0);
if(g_hwndCmdProcess != NULL)
{
CFrameWnd * pFrameWnd = ((CMainFrame *)AfxGetMainWnd())->GetActiveFrame();
if(pFrameWnd != NULL && (pFrameWnd->GetActiveView() != NULL))
{
CString sFileName = ((CCodeLogicDoc *)(pFrameWnd->GetActiveView()->GetDocument()))->GetDocID();
int nStartIndex = 0;
for(int i = 0; i < sFileName.GetLength() - 1; i++)
{
if(sFileName.GetAt(i) == _T('/') || sFileName.GetAt(i) == _T('\\'))
{
nStartIndex = i + 1;
}
}
CString sPathName = sFileName.Left(nStartIndex - 1);
CString sFileNameFull = sFileName.Right(sFileName.GetLength() - nStartIndex);
sFileName = sFileNameFull;
nStartIndex = 0;
for(int i = 0; i < sFileName.GetLength() - 1; i++)
{
if(sFileName.GetAt(i) == _T('.') || sFileName.GetAt(i) == _T('.'))
{
nStartIndex = i + 1;
}
}
if(nStartIndex > 0)
{
sPathName = sFileName.Right(sFileName.GetLength() - nStartIndex);
}
CString sValue;
CString sValueAfter;
int nCategoryIndex = this->m_comboCatalog.GetCurSel();
if(CDlgStringTableManager::m_ptrArrayName.GetSize() > nCategoryIndex)
{
CWordArray * pstringArrayCursorPos = (CWordArray *)CDlgStringTableManager::m_ptrArrayCursorPos.GetAt(nCategoryIndex);
CStringArray * pstringArrayValue = (CStringArray *)CDlgStringTableManager::m_ptrArrayValue.GetAt(nCategoryIndex);
CStringArray * pstringArrayInsertAfter = (CStringArray *)CDlgStringTableManager::m_ptrArrayInsertAfter.GetAt(nCategoryIndex);
int nListIndex = m_listString.GetCurSel();
if(pstringArrayValue->GetSize() > nListIndex)
{
unsigned int nCursorPos = pstringArrayCursorPos->GetAt(nListIndex);
BOOL bRemoveSelection = nCursorPos > 0 ? TRUE : FALSE;
sValue = pstringArrayValue->GetAt(nListIndex);
sValueAfter = pstringArrayInsertAfter->GetAt(nListIndex);
}
}
_snwprintf_s(CGlobalComponent::m_wszTempBuffer, LENGTH_MAX_BUFF, LENGTH_MAX_BUFF, _T("set cp = %s\r\nset cf = %s\r\nset cffull = %s\r\n%s"), sPathName, sFileName, sFileNameFull, sValue);
for(int i = 0; i < (int)wcslen(CGlobalComponent::m_wszTempBuffer); i++)
{
LRESULT lResult = ::SendMessage(g_hwndCmdProcess, WM_CHAR, CGlobalComponent::m_wszTempBuffer[i], 1);
TRACE(_T("\n%d"), lResult);
}
}
break;
}
}
Sleep(200);
}
}
char *src="我爱你LZ,快把分给我";
for(int i=0;i<strlen(src);i++)
SendMessage(Handle,WM_IME_CHAR,src[i],0);
PostMessage(Handle,WM_CHAR,(WPARAM)(0xBD),0);