|
이미 뉴스그룹에 답변과 소스가 올라와 있네요.
I wrote a program like what your talking about. I wanted something to
restore all my icons to their positions after a game running DirectX crashed
and would mess up the resolution and all the icons positions.
You need to check out the List View Control Message in the Windows SDK. The
windows desktop icons are stored in a listview. The example below just
shows how to find the list view control that has the icons in them, find out
how many icons there are, and then get their X, Y position on the screen. I
used SendMessage and Memory mapped files instead of stuff like
ListView_GetItemPosition, because the call would require pointers being
passed between different process space, and that just won't work.
You can restore the desktop with the coordinates you get, but not all the
icons will go into the right place. You may also need the names of the
icons to make sure they get back in the right place. Check out the message
LVM_GETITEMTEXT for that, the example below only gets their position since
that is what you asked for.
And I have only tried this on Win98 with BCB 5.
// Header stuff
struct ICON_DATA_STRUCT
{
int IconIndex;
POINT IconPosition;
};
typedef ICON_DATA_STRUCT IconData;
IconData Icons[1000];
HWND hDesktop;
int iIconCount;
// end header stuff
void TForm1::GetDesktopIconPositionXY()
{
hDesktop = NULL;
iIconCount = 0;
// Find the List View where the Desktop Icon info is stored.
hDesktop = FindWindow("ProgMan",NULL);
if(hDesktop == NULL)
{
ShowMessage("ProgMan Window Not Found.");
return;
}
hDesktop = FindWindowEx(hDesktop,0,"ShellDll_DefView", NULL);
if(hDesktop == NULL)
{
ShowMessage("ShellDll_DefView Window Not Found.");
return;
}
hDesktop = FindWindowEx(hDesktop,0,"SysListView32",NULL);
if(hDesktop == NULL)
{
ShowMessage("SysListView32 Window Not Found.");
return;
}
// Get the number of icons on the desktop
iIconCount = SendMessage(hDesktop, LVM_GETITEMCOUNT,0,0);
if(iIconCount == 0)
return;
Memo1->Lines->Add("Icon Count: "+IntToStr(iIconCount));
HANDLE hFile = NULL;
AnsiString sFileName;
sFileName = ExtractFilePath(Application->ExeName)+"temp.ppp";
hFile = CreateFile(sFileName.c_str(),GENERIC_READ|GENERIC_WRITE,
0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
HANDLE hMappedFile = NULL;
hMappedFile = CreateFileMapping(hFile,NULL,PAGE_READWRITE,
0,16,"MyMapping");
long pFileMap;
pFileMap = (long)MapViewOfFile(hMappedFile,FILE_MAP_WRITE,0,0,0);
POINT p;
// Get each icons X,Y coordinates
for(int i=0; i<iIconCount-1; i++)
{
SendMessage(hDesktop,LVM_GETITEMPOSITION,i,pFileMap);
CopyMemory(&p,(void*)pFileMap,8);
Memo1->Lines->Add("x: "+IntToStr(p.x)+" y: "+IntToStr(p.y));
Icons[i].IconIndex = i;
Icons[i].IconPosition = p;
}
FlushViewOfFile((void*)pFileMap,8);
UnmapViewOfFile((void*)pFileMap);
CloseHandle(hMappedFile);
CloseHandle(hFile);
}
Hope that helps.
Later,
Clayton
claytontodd@hotmail.com
이상우 님이 쓰신 글 :
: 안녕하세요.
: 바탕화면의 아이콘들이 있잖아요.
: 그 위치를 수동(마우스로 드레그)하는거 말고 위치를 바꾸고 싶은데...
: 레지스트리 뒤져도 못찾겠고..어디에 저장되어있나요..
: 위치(좌표)가....아시는분 가르쳐주세요~~~^^;;
: 어딘가에 저장이 되어있을텐데....못찾고 있습니다..
:
|