Position von Desktop Icon, und Position verändern



  • Ich möchte ein Programm schreiben das icons auf dem desktop aufspüren kann und sie dann woanders hinbewegt.

    beispiel:

    die X sind icons

    o-------------------------o
    | X X X                   |
    |                         |
    | X   X                   |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    o-------------------------o
    
    Von da
    o-------------------------o
    | X X X                   |
    |                         |
    | X>> X <<                |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    o-------------------------o
    
    Nach da
    o-------------------------o
    | X X X                   |
    |                         |
    | X                       |
    |                         |
    |                         |
    |                         |
    |               << X >>   |
    |                         |
    o-------------------------o
    

    Ist das möglich, oder will ich ein Ding der Unmöglichkeit
    Hab schon ein bischen gegoogelt aber nichts gescheites gefunden, weis nichtmal sorecht nach was ich suchen soll.

    Hoffe ihr könnt mir helfen.



  • unter welchen Betriebssystem soll das ganze laufen? Windows oder Unix? Am besten, ist es wenn du den Beitrag in das entsprechende Forum verschiebst, also WinAPI für Windows oder Linux/Unix.

    mfg liggi



  • Oh Sorry, ganz vergessen.
    Das Programm soll unter Windows laufen.
    Hab es unter Spiele gepostet weil es so eine art Spiel werden soll.
    Eine Figur die auf dem Desktop umhermarschiert und Icons sammelt und wo anders hin (bringt/schiebt/beamt/wass auch immer) das ganze soll ein geschenk werden.

    PS: Kann den Thread bitte jemand ins richtige Forum verschieben danke.

    Hab jetzt selber was gefunden
    wenns interesiert wies geht hier der code

    #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], subitem[512];
    		char *_item, *_subitem;
    		unsigned long pid;
    		HANDLE process;
    
    		GetWindowThreadProcessId(hIconList, &pid);
    		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);
    		_subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT,
    											 PAGE_READWRITE);
    		lvi.cchTextMax=512;
    
    		for (int index = 0; index < anzahl; index++)
    		{
    			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);
    
    			//printf("%s - %s\n", item, subitem);
    			cout<<"Element"<<index<<": "<<item<<endl;
    
    		}
    
    		VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
    		VirtualFreeEx(process, _item, 0, MEM_RELEASE);
    		VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
    
    		anzahl = 0;
    	} 
    	system("PAUSE");
    	return 0;
    }
    

    PS: Hab ein neues problem wie kann ich elemente auf dem desktop auschneiden allos, das sie veschwinden und nacher an einer anderen position wider erscheinen
    am besten wäre es wenn ich irgendwie alle daten auslesen könnte, dann löschen und woanders neu erstellen.



  • 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;
    }
    

Anmelden zum Antworten