SysListView32拖拽文件
怎么向其他程序窗口里的SysListView32控件 发送一个拖拽文件到里面的消息
[解决办法]
如果有其他程序的源代码好解决,如果没有需要另辟蹊径。
1可以采用下面代码实现,其功能是向windows画图程序拖动文件
BOOL UseMsPaintOpenFile(CString strFilePath){ int nResult = TRUE; HWND hMain = NULL; DWORD dwBufSize = 0;//sizeof(DROPFILES) + sizeof(szFile) + 1; BYTE *pBuf = NULL; DWORD dwProcessId = 0; HANDLE hProcess = 0; LPSTR pszRemote = NULL; DROPFILES *pDrop = NULL; HINSTANCE hinstance = NULL; do { dwBufSize = sizeof(DROPFILES) + strlen(strFilePath.GetBuffer(0)) + 1; /* 是否打开画图软件 没打开先打开 */ hMain = ::FindWindow(_T("MSPaintApp"),NULL); if ( hMain == NULL) { hinstance = ::ShellExecute(NULL,NULL,_T("mspaint.exe"),strFilePath.GetBuffer(0),NULL,SW_SHOWMAXIMIZED); //再次没打开,报错返回 if ( hinstance <= (HINSTANCE)32 ) { AfxMessageBox("找不到画图程序,退出"); nResult = FALSE; break; } else break; } pBuf = new BYTE[dwBufSize]; if (pBuf == NULL) { nResult = FALSE; break; } memset(pBuf,0,dwBufSize); pDrop = (DROPFILES *)pBuf; pDrop->pFiles = sizeof(DROPFILES); strcpy((char *)(pBuf + sizeof(DROPFILES)),strFilePath.GetBuffer(0)); GetWindowThreadProcessId(hMain,&dwProcessId); if (0 == dwProcessId) { nResult = FALSE; break; } hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, dwProcessId); if (hProcess == 0) { nResult = FALSE; break; } pszRemote = (LPSTR)VirtualAllocEx(hProcess, NULL, dwBufSize, MEM_COMMIT, PAGE_READWRITE); if (NULL == pszRemote) { nResult = FALSE; break; } if(WriteProcessMemory(hProcess, pszRemote, pBuf, dwBufSize, 0)) { ::SendMessage(hMain, WM_DROPFILES, (WPARAM)pszRemote, NULL); } else { nResult = FALSE; break; } }while ( 0 ); if (pBuf) { delete [] pBuf; pBuf = NULL; } return nResult;}void CCFormViewView::OnCc() { // TODO: Add your command handler code here }