// by caohai 11:01 2004-12-31 #define WIN32_LEAN_AND_MEAN #include #include #include #include "commctrl.h" #define TIMER_ELAPSE 50 #define ICON_HFWIDTH 35 #define ICON_HFHEIGHT 35 #define MAX_LEN 65 // get currrent list view HWND GetLstView(POINT * pt /*= NULL*/) { const char * strLstVClass = "SysListView32"; char ClassName[MAX_LEN]; if(NULL == pt) return NULL; HWND hDeskView = WindowFromPoint(*pt); GetClassName(hDeskView, ClassName, 64); if(0 == strcmp(ClassName,strLstVClass)) return hDeskView; return NULL; } // get icon's position void GetItemPos(HWND hLstView, int i, POINT * ppt) { DWORD dwProcessId; GetWindowThreadProcessId(hLstView,&dwProcessId); HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION, FALSE, dwProcessId); PVOID vpt = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE); ListView_GetItemPosition(hLstView,i,vpt); ReadProcessMemory(hProcess, vpt, ppt, sizeof(POINT), NULL); VirtualFreeEx(hProcess, vpt, NULL, MEM_RELEASE); CloseHandle(hProcess); } // icons esacpe void Escape(int iRadius) { int i, iCount; POINT ptCur; RECT rctLst, rctUpdate; HWND hLstView; //get listview GetCursorPos(&ptCur); if(NULL == (hLstView = GetLstView(&ptCur))) return; //show my name, pls remain it GetClientRect(hLstView, &rctLst); rctUpdate = rctLst; rctUpdate.left = rctLst.right - 130; rctUpdate.top = rctLst.bottom - 40; InvalidateRect(hLstView, &rctUpdate,true); HDC hdc = GetDC(hLstView); COLORREF crPre = SetTextColor(hdc,RGB(0,255,0)); int iBk = SetBkMode(hdc,TRANSPARENT); TextOut(hdc, rctLst.right - 120, rctLst.bottom - 30, "Caohai 12/31/04", 15); SetTextColor(hdc,crPre); SetBkMode(hdc, iBk); ReleaseDC(hLstView,hdc); //set listview to icon style DWORD dwStyle = GetWindowLong(hLstView,GWL_STYLE); dwStyle = dwStyle & ~LVS_AUTOARRANGE & ~LVS_SMALLICON & ~LVS_LIST & ~LVS_REPORT; SetWindowLong(hLstView, GWL_STYLE, dwStyle); //escape iCount = ListView_GetItemCount(hLstView); ScreenToClient(hLstView,&ptCur); for(i=0; i 0.0) ||(fDistance < 0.0))) {//move ptIcon.x = ptCur.x + (LONG)((iRadius * (ptIC.x - ptCur.x)) / fDistance) - ICON_HFWIDTH; ptIcon.y = ptCur.y + (LONG)((iRadius * (ptIC.y - ptCur.y)) / fDistance) - ICON_HFHEIGHT; if(ptIcon.x < 2 * ICON_HFWIDTH || ptIcon.x > rctLst.right - 2 * ICON_HFWIDTH) { srand((int)ptIcon.x * i); ptIcon.x = (rand() % rctLst.right); } if(ptIcon.y < 2 * ICON_HFHEIGHT || ptIcon.y > rctLst.bottom - 2 * ICON_HFHEIGHT) { srand((int)ptIcon.y * i); ptIcon.y = (rand() % rctLst.bottom); } ListView_SetItemPosition(hLstView, i, ptIcon.x, ptIcon.y); } } } // win main int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; if(hPrevInstance != NULL) return FALSE; SetTimer(NULL,1,TIMER_ELAPSE,NULL); while(GetMessage(&msg, NULL, WM_TIMER, WM_TIMER)) Escape(100); KillTimer(NULL,1); return (int) msg.wParam; }