K
hi
hab mal dein prog ein bischen erweitert...
kA ob du es bis jetzt gelöst hast oder überhaupt noch brauchst...
#include <iostream>
#include <windows.h>
#include <COMMCTRL.H>
#include <commctrl.h>
using namespace std;
HWND GetDesktopListView()
{
HWND hWnd = FindWindow( "Progman" , "Program Manager" );
if ( hWnd ) {
hWnd = FindWindowEx( hWnd, NULL,"SHELLDLL_DefView" , NULL );
if ( hWnd )
hWnd = FindWindowEx( hWnd, NULL, "SysListView32" , "FolderView" );
}
return hWnd;
}
int main(int argc, char* argv[])
{
HWND hIconList = GetDesktopListView();
if ( hIconList )
{
cout<<"Anzahl Icons auf Desktop: "<<ListView_GetItemCount(hIconList)<<endl;
int anzahl =ListView_GetItemCount(hIconList);
LVITEM lvi, *_lvi;
char item[512];
char *_item;
unsigned long pid;
HANDLE process;
int i = 0;
POINT pXY, *_pXY;
SIZE_T transferedData;
GetWindowThreadProcessId(hIconList, &pid);
cout << "WindowId: " << pid << endl;
process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
_item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
lvi.cchTextMax=512;
_pXY=(POINT*)VirtualAllocEx(process, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE);
for (int index = 0; index < anzahl; index++)
{
// FIRST: We get the name of the icon
lvi.iSubItem=0;
lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(hIconList, LVM_GETITEMTEXT, (WPARAM)index, (LPARAM)_lvi);
ReadProcessMemory(process, _item, item, 512, NULL);
cout<<"Element"<<index<<": "<<item<<endl;
// SECOND: We get the position of the icon
WriteProcessMemory(process, _pXY, &pXY, sizeof(POINT), &transferedData);
SendMessage(hIconList, LVM_GETITEMPOSITION, (WPARAM)index, (LPARAM)_pXY);
ReadProcessMemory(process, _pXY, &pXY, sizeof(POINT), &transferedData);
cout << "Position: " << pXY.x << "/" << pXY.y << endl;
/*
// Get the name and position of a listview item.
// Wär ne kürzere Variante aber da stimmen irgendwie
// die Parameter noch nicht
ListView_GetItemText(hIconList, index, 0, item, sizeof(item)/sizeof(item[0]));
ListView_GetItemPosition(hIconList, index, &pXY);
cout<<"Element"<<index<<": "<<item<< " ";
cout << "Position: " << pXY.x << "/" << pXY.y << endl;
*/
// Icon verschieben
if(!strncmp(item, "test.txt", 512)) {
// Koords-Vorher: 782/257 (x/y)
//pXY.x = 900;
//pXY.y = 257;
//ListView_SetItemPosition(hIconList, index, pXY.x, pXY.y);
}
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
anzahl = 0;
}
system("PAUSE");
return 0;
}