您的足迹:首页 > 我的代码 >aardio版的窗口探测器Winspy++,最新版本,加强版

aardio版的窗口探测器Winspy++,最新版本,加强版

/*  
* 窗口探测器
* 作者: lujjjh  
* -----------------------------
* modify by mikeSD on 2010/12/6
* append enlarge and  save function 加进了小十字标 
*
*/

import winex;
import win.ui; 
import win.cur; 
import mouse; 
import mouse.hook;
/*DSG{{*/
var winform = win.form(text="winspy for aardio";right=409;bottom=396;parent=...)
winform.add(
button3={cls="button";text="修改标题";left=30;top=365;right=118;bottom=389;dl=1;dr=1;dt=1;font=LOGFONT(name='SimSun');z=1};
button4={cls="button";text="最小化窗口";left=140;top=365;right=228;bottom=389;dl=1;dr=1;dt=1;font=LOGFONT(name='SimSun');z=2};
button5={cls="button";text="窗口任务栏闪烁";left=250;top=365;right=378;bottom=389;dl=1;dr=1;dt=1;font=LOGFONT(name='SimSun');z=3};
chkForeground={cls="checkbox";text="自动捕获前台窗口";left=153;top=24;right=275;bottom=39;dl=1;dr=1;dt=1;z=23};
chkTopMost={cls="checkbox";text="保持窗口最前";left=51;top=24;right=149;bottom=39;dl=1;dr=1;dt=1;z=22};
groupbox={cls="groupbox";text="当前坐标位置颜色";left=39;top=199;right=186;bottom=245;edge=1;z=32};
labColor={cls="static";left=113;top=216;right=178;bottom=235;border=1;edge=1;font=LOGFONT(name='宋体');transparent=1;z=34};
labX={cls="static";left=73;top=176;right=112;bottom=193;align="center";border=1;font=LOGFONT(name='Microsoft Sans Serif');transparent=1;z=29};
labX2={cls="static";text="X坐标";left=32;top=176;right=67;bottom=193;align="right";font=LOGFONT(name='Microsoft Sans Serif');transparent=1;z=28};
labY={cls="static";left=154;top=176;right=193;bottom=193;align="center";border=1;font=LOGFONT(name='Microsoft Sans Serif');transparent=1;z=31};
lbClass={cls="static";text="类名:";left=214;top=55;right=263;bottom=70;align="right";dl=1;dr=1;dt=1;transparent=1;z=7};
lbHwnd={cls="static";text="窗口句柄:";left=35;top=79;right=92;bottom=91;align="right";dl=1;dr=1;dt=1;transparent=1;z=4};
lbId={cls="static";text="命令ID:";left=213;top=80;right=262;bottom=95;align="right";dl=1;dr=1;dt=1;transparent=1;z=8};
lbParenHwnd={cls="static";text="父窗口句柄:";left=24;top=55;right=92;bottom=70;align="right";dl=1;dr=1;dt=1;transparent=1;z=9};
lbPid={cls="static";text="进程ID:";left=213;top=106;right=262;bottom=121;align="right";dl=1;dr=1;dt=1;transparent=1;z=12};
lbStyle={cls="static";text="基本样式:";left=32;top=103;right=92;bottom=123;align="right";dl=1;dr=1;dt=1;transparent=1;z=5};
lbStyleEx={cls="static";text="扩展样式:";left=30;top=128;right=92;bottom=143;align="right";dl=1;dr=1;dt=1;transparent=1;z=6};
lbText={cls="static";text="文本:";left=42;top=151;right=91;bottom=166;align="right";dl=1;dr=1;dt=1;transparent=1;z=10};
lbTid={cls="static";text="线程ID:";left=213;top=128;right=262;bottom=143;align="right";dl=1;dr=1;dt=1;transparent=1;z=11};
pic1={cls="picturebox";left=9;top=8;right=41;bottom=40;dl=1;dr=1;dt=1;font=LOGFONT(name='SimSun');image=$"\res\1.gif";notify=1;transparent=1;z=25};
picturebox={cls="picturebox";left=202;top=177;right=388;bottom=359;bgcolor=15780518;border=1;font=LOGFONT(name='宋体');notify=1;z=26};
richedit={cls="richedit";left=11;top=246;right=197;bottom=359;edge=1;font=LOGFONT(name='宋体');hscroll=1;multiline=1;vscroll=1;z=27};
static={cls="static";left=45;top=216;right=110;bottom=235;align="center";border=1;font=LOGFONT(name='宋体');transparent=1;z=33};
static7={cls="static";text="Y坐标";left=114;top=176;right=148;bottom=193;align="right";font=LOGFONT(name='Microsoft Sans Serif');transparent=1;z=30};
staticTip={cls="static";text='\u2190 请用鼠标拖动左侧的图标放置于目标窗口上';left=53;top=6;right=310;bottom=25;dl=1;dr=1;transparent=1;z=21};
txtClass={cls="edit";left=271;top=54;right=377;bottom=75;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=17};
txtHwnd={cls="edit";left=101;top=77;right=207;bottom=98;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=14};
txtId={cls="edit";left=271;top=77;right=377;bottom=98;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=18};
txtParenHwnd={cls="static";left=101;top=54;right=207;bottom=75;color=16711680;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(name='Microsoft Sans Serif';underline=1);notify=1;transparent=1;z=24};
txtPid={cls="edit";left=271;top=101;right=377;bottom=122;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=19};
txtStyle={cls="edit";left=101;top=100;right=207;bottom=121;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=15};
txtStyleEx={cls="edit";left=101;top=123;right=207;bottom=144;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=16};
txtText={cls="edit";left=100;top=149;right=376;bottom=172;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=13};
txtTid={cls="edit";left=270;top=125;right=376;bottom=146;dl=1;dr=1;dt=1;edge=1;multiline=1;readonly=1;z=20}
)
/*}}*/

//置顶窗口
win.setTopmost(winform.hwnd,winform.chkTopMost.checked)
winform.chkTopMost.oncommand = function(id,event){
    win.setTopmost(winform.hwnd,winform.chkTopMost.checked)  
}

//及时显色//
drawColor = function(currentcolor)begin 
    var hBrush   = CreateSolidBrush( currentcolor );
    var hdc = GetDC(winform.labColor.hwnd) 
    FillRect( hdc, winform.labColor.clientRect, hBrush );
    DeleteObject( hBrush );
    ReleaseDC(winform.labColor.hwnd,hdc);
end;

//放大//
enlarge = function(x,y)begin 
    x1=x-10;x2=x+10;y1=y-10;y2=y+10;
    nWidth=winform.picturebox.right-winform.picturebox.left
    nHeight=winform.picturebox.bottom-winform.picturebox.top
    nSrcWidth=(x2-x1)
    nSrcHeight=(y2-y1)
    var hdc1=GetDC(winform.picturebox.hwnd)
    var srchdc1=GetDC(0)
    StretchBlt(hdc1,0,0,nWidth,nHeight,srchdc1,x1,y1,nSrcWidth,nSrcHeight,0xCC0020/*_SRCCOPY*/)
    //画十字线**************************
    PatBlt (hdc1, nWidth/2, nWidth/4, 2, nHeight/2, 0xFF0062/*_WHITENESS*/) ;
    PatBlt (hdc1, nWidth/2, nWidth/4, 1, nHeight/2, 0x42/*_BLACKNESS*/) ;
    PatBlt (hdc1, nWidth/4, nHeight/2, nWidth/2, 2, 0xFF0062/*_WHITENESS*/) ;
    PatBlt (hdc1, nWidth/4, nHeight/2, nWidth/2, 1, 0x42/*_BLACKNESS*/) ;
    //**********************************
    ReleaseDC(winform.picturebox.hwnd,hdc1)
    ReleaseDC(0,srchdc1)
end; 

//绘图API 
Rectangle   = Gdi32.api("Rectangle", "int(pointer hDC, int nLeft, int nTop, int nRight, int nBottom)");
SetROP2     = Gdi32.api("SetROP2", "int(pointer hDC, int nMode)"); 

//加载自定义的鼠标指针
var hCursor = win.cur.loadfile("\res\spy.cur") 

//防卡
winform.wndproc = function(hwnd,message,wparam,lparam){ 
    if( message = 0xA1/*_WM_NCLBUTTONDOWN*/ ){
        if( wparam == 20/*_HTCLOSE*/ ){ 
            hk.close()
        }
    }
    else if(message == 0x10/*_WM_CLOSE*/ )
        hk.close() 
} 

//主窗体回调函数
winform.pic1.wndproc = function (hwndSpy, uMsg, wParam, lParam){
    select (uMsg){
        case 0x201/*_WM_LBUTTONDOWN*/{
            winform.pic1.image = $"\res\2.gif";
            winform.pic1.capture = true; //捕获全局鼠标消息
            win.cur.beginCur();//持续设定鼠标指针
        }
        case 0x202/*_WM_LBUTTONUP*/{ 
            winform.pic1.image = $"\res\1.gif";
            winform.pic1.capture = false; //释放鼠标
            win.cur.endCur(); //恢复正常鼠标指针
        } 
    }
}

//显示窗口信息
function showWindowInfo(hwnd){
    winform.txtParenHwnd.text = string.format("%X",win.getParent(hwnd) )
    winform.txtHwnd.text = string.format("%X",hwnd )
    winform.txtClass.text = win.getClass(hwnd) 
    winform.txtId.text = win.getId(hwnd);
    var str = win.getText(hwnd,50) ;
    if(str){
        winform.txtText.text = string.replace(str,"[\r\n]","")
    } 
    winform.txtStyle.text = tostring(::GetWindowLong(hwnd, 0xFFFFFFF0/*_GWL_STYLE*/) );
    winform.txtStyleEx.text = tostring(::GetWindowLong(hwnd, 0xFFFFFFEC/*_GWL_EXSTYLE*/) );
    winform.txtTid.text,winform.txtPid.text = win.getThreadProcessId(hwnd)
}

//点击父窗口句柄时显示父窗口信息
winform.txtParenHwnd.oncommand = function(id,event){
    var hwnd = tonumber(  winform.txtParenHwnd.text,16)
    if(hwnd)
        showWindowInfo(hwnd);
}

import process
hk = mouse.hook();
hk.proc = function(msg,x,y){ 
    tm=time.now() //取得时间 //
    select(msg) { 

        case 0x201/*_WM_LBUTTONDOWN*/{//tm=time.now()//
            winform.richedit.setsel(-1,-1)
            winform.richedit.selText = string.format('(%.2d:%02d:%.2d)mouse.down(%d,%d,true)RGB=[%06s]\n',tm.hour,tm.minute,tm.second,x,y,rgbcolor )
        }

        case 0x200/*_WM_MOUSEMOVE*/{
            x,y=mouse.getPos();//得到光标的坐标//
            currentcolor=gdi.getPixel(x,y)  //得到光标处的色彩//
            t=string.format("%.6X", currentcolor) //色彩转换为6位十六进制(BGR)//
            rgbcolor="#"++string.pack(t[5],t[6],t[3],t[4],t[1],t[2])
            /*  t = string.split(bgrcolor,''); //按单个字符开始拆分成数组           
            rgbcolor=t[5]++t[6]++t[3]++t[4]++t[1]++t[2] //倒序成RGB  */
            winform.static.text=rgbcolor
            winform.labX.text=x;//显示当前X坐标//
            winform.labY.text=y;//显示当前Y坐标// 
            enlarge(x,y)
            drawColor(currentcolor );
        }    
        case 0x204/*_WM_RBUTTONDOWN*/{ //点击鼠标右键将记录的鼠标颜色追加保存到文件//
            file = assert(io.open(".\mousecolor.txt", "a") ) //以追加方式打开或创建文件//
            var hang=winform.richedit.lineCount
            tm=time.now()
            for(i=-1;hang;1){
                var text=winform.richedit.lineText(i)   
                file.write("第",i+2,"行",text,'\r\n') //将记录的鼠标颜色按行追加写入文件//
            }
            file.close() //关闭文件//
        }
    }  
}

var hwndSpy;// 用来保存探测到的窗口句柄
tmid = winform.addtimer(
    100/*毫秒*/, 
    function(hwnd,msg,id,tick){
        // 定时执行代码
        // 如果鼠标指针是探测状态
        if ( win.cur.beginning ){
            hwndSpy = winex.fromPointReal( mouse.getPos() );
            var lpRect = ::RECT();
            re, lpRect = ::GetWindowRect(hwndSpy, lpRect);
            showWindowInfo(hwndSpy);
            if (hwndSpy){
                var hDC = ::GetWindowDC(0);
                /** 防止溢出 Start **/
                if (lpRect.left < 0)
                    lpRect.left = 0;
                if (lpRect.top < 0)
                    lpRect.top = 0;
                if (lpRect.right > ::GetSystemMetrics(0x0/*_SM_CXSCREEN*/))
                    lpRect.right = ::GetSystemMetrics(0x0/*_SM_CXSCREEN*/);
                if (lpRect.bottom > ::GetSystemMetrics(0x1/*_SM_CYSCREEN*/))
                    lpRect.bottom = ::GetSystemMetrics(0x1/*_SM_CYSCREEN*/);
                /** 防止溢出 End **/
                var hPen = CreatePen(0x0/*_PS_SOLID*/, 3, 0);
                var hOldPen = ::SelectObject(hDC, hPen);
                var oldROP2 = SetROP2(hDC, 0xA/*_R2_NOTXORPEN*/);
                Rectangle(hDC, lpRect.left, lpRect.top, lpRect.right, lpRect.bottom);
                sleep(10);
                Rectangle(hDC, lpRect.left, lpRect.top, lpRect.right, lpRect.bottom);
                SetROP2(hDC, oldROP2);
                ::SelectObject(hDC, hOldPen);
                ::DeleteObject(hPen);
                ::ReleaseDC(hwndSpy, hDC);
            }
        }
        elseif( winform.chkForeground.checked ){
            showWindowInfo( win.getForeground() );
        }
sleep(10)   
    }
);

winform.button3.oncommand = function(id, event){
    if (win.msgboxTest("是否用 SendMessage 方式?否则用 SetWindowText", "标题"))
        User32.api("SendMessage", "int(int hwndSpy, int uMsg, int wParam, 
            string lParam)")(hwndSpy, 0xC/*_WM_SETTEXT*/, 0, "我是新的标题");
    else
        ::SetWindowText(hwndSpy, "我是新的标题");
}

winform.button4.oncommand = function(id, event){
    select(winform.button4.text){ 
        case "最小化窗口"
        {PostMessage(hwndSpy, 0x112/*_WM_SYSCOMMAND*/,0xF020/*_SC_MINIMIZE*/, 0); 

            //User32.api("CloseWindow","int(int hwndSpy)")(hwndSpy)
            winform.button4.text = "最大化窗口"
        }
        case "最大化窗口"
        {PostMessage(hwndSpy, 0x112/*_WM_SYSCOMMAND*/, 0xF030/*_SC_MAXIMIZE*/,0);

            //User32.api("OpenIcon","int(int hwndSpy)")(hwndSpy)
            winform.button4.text="最小化窗口"
        }
    }
}

winform.button5.oncommand = function(id, event){
    User32.api("FlashWindow", "int(int hwndSpy, int bInvert)")(
        hwndSpy, win.msgboxTest("是否仅闪烁一次?否则持续闪烁") ? 1 : 0);
}

winform.show(true);
win.loopMessage(); 
return winform;

 

本博客所有文章如无特别注明均为原创。作者:恶猫复制或转载请以超链接形式注明转自 恶猫的博客
原文地址《aardio版的窗口探测器Winspy++,最新版本,加强版

相关推荐

分享本文至:

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)

恶猫的博客 -记录自己日常,代码,美图,电影,音乐,新闻,只是个人博客而已

浙ICP备15011757号-4 网站地图 联系我