源代码
//****** Saved from http://seac.blogchina.com ******
// by caohai 11:11 2004-12-31
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "commctrl.h"
#define STR_MYNAME "Caohai 12/31/04"
#define NAME_LEN 15
#define SIGN_TOP 30
#define SIGN_LEFT 120
#define SIGN_WIDTH 150
#define SIGN_HEIGHT 50
#define STR_LSTVCLASS "SysListView32"
#define TIMER_DELAY 72
#define ICON_HFWIDTH 35
#define ICON_HFHEIGHT 35
#define MAX_LEN 65
#define ESP_RADIUS 150
long sqrt2(long x)
{
if(x<0)
return -1;
double dbZ = 1.0;
double dbL = 10E-2;
double dbT = 1.0 - x;
while(dbT > dbL || dbT < -dbL)
{
dbZ = dbZ - dbT /(2.0 * dbZ);
dbT = dbZ * dbZ - x;
}
return (long)dbZ;
}
// icons esacpe
int Escape(int iRadius)
{
int i, iCount;
POINT ptCur;
RECT rctLst, rctUpdate;
char ClassName[MAX_LEN];
HWND hLstView;
DWORD dwProcessId;
HANDLE hProcess;
PVOID vpt;
//get listview
GetCursorPos(&ptCur);
hLstView = WindowFromPoint(ptCur);
GetClassName(hLstView, ClassName, MAX_LEN - 1);
if(strcmp(ClassName, STR_LSTVCLASS) != 0) return 1;
//show my name, pls remain it
GetClientRect(hLstView, &rctLst);
rctUpdate = rctLst;
rctUpdate.left = rctLst.right - SIGN_WIDTH;
rctUpdate.top = rctLst.bottom - SIGN_HEIGHT;
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 - SIGN_LEFT, rctLst.bottom - SIGN_TOP , STR_MYNAME, NAME_LEN);
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);
GetWindowThreadProcessId(hLstView,&dwProcessId);
hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION, FALSE, dwProcessId);
vpt = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE);
for(i=0; i<iCount; i++)
{
POINT ptIcon, ptIC;
ListView_GetItemPosition(hLstView,i,vpt);
ReadProcessMemory(hProcess, vpt, &ptIcon, sizeof(POINT), NULL);
ptIC.x = ptIcon.x + ICON_HFWIDTH;
ptIC.y = ptIcon.y + ICON_HFHEIGHT;
long nDistance = sqrt2((ptIC.y - ptCur.y) * (ptIC.y - ptCur.y) + (ptIC.x - ptCur.x) * (ptIC.x - ptCur.x));
if(nDistance < iRadius && ptIC.x != ptCur.x && nDistance != 0)
{//move
ptIcon.x = ptCur.x + (LONG)(((iRadius + 5) * (ptIC.x - ptCur.x)) / nDistance) - ICON_HFWIDTH;
ptIcon.y = ptCur.y + (LONG)(((iRadius + 5) * (ptIC.y - ptCur.y)) / nDistance) - ICON_HFHEIGHT;
if(ptIcon.x < ICON_HFWIDTH)
ptIcon.x = rctLst.right / 2 - 4 * ICON_HFWIDTH;
else if(ptIcon.x > rctLst.right - 3 * ICON_HFWIDTH)
ptIcon.x = 2 * ICON_HFWIDTH + rctLst.right / 2;
if(ptIcon.y < ICON_HFHEIGHT)
ptIcon.y = rctLst.bottom / 2 - 4 * ICON_HFHEIGHT;
else if(ptIcon.y > rctLst.bottom - 3 * ICON_HFWIDTH)
ptIcon.y = 2 * ICON_HFHEIGHT + rctLst.bottom / 2;
ListView_SetItemPosition(hLstView, i, ptIcon.x, ptIcon.y);
}
}
VirtualFreeEx(hProcess, vpt, NULL, MEM_RELEASE);
CloseHandle(hProcess);
return 1;
}
// win main
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
if(hPrevInstance)
return 0;
while(Escape(ESP_RADIUS))
Sleep(TIMER_DELAY);
return 1;
}
在VC++7.1 windows 2000 server下调试通过。
点击浏览该文件
(seac) |