import win.ui;
import winex
import gdip
import com.picture
import mouse
import winex.mouse
/*DSG{{*/
var winform = ..win.form( bottom=539;parent=...;text="QQ找茬助手";right=542 )
winform.add(
button={ bottom=517;right=96;left=33;top=483;z=1;text="看答案";cls="button" };
picturebox={ bottom=287;right=381;left=0;top=0;z=2;notify=1;cls="picturebox" };
static={ bottom=517;right=531;left=120;notify=1;top=475;z=3;transparent=1;text="介绍:采用图像对比方法,不读内存,不会被游戏检测\r
使用方法:2张图出现后,点击“看答案”按钮,软件图像控件就显示找茬绿块,\r
在本软件界面点击绿块即可。";cls="static" }
)
/*}}*/

var gameHwmd;
var config = {
{
leftX = 10;
width = 381;
height = 287;
rightX = 403;
top = 185;
};//大家来找茬配置
{
leftX = 8;
width = 498;
height = 448;
rightX = 517;//516
top = 192;
};//美女找茬配置

}

var gameConfig
winform.button.oncommand = function(id,event){
gameHwmd = winex.find("\#\d+","大家来找茬" )
if(!gameHwmd){
winform.msgbox("没启动游戏呢")
return ;
}
x,y,cx,cy = win.getPos(gameHwmd);
if(cy<703){
gameConfig = config[1];
}
else {
gameConfig = config[2];
}
winform.picturebox.right = gameConfig.width;
winform.picturebox.bottom = gameConfig.height;
winform.picturebox.redraw();
win.setPos( gameHwmd,0,0 );
win.delay(100)
var left_pic = com.picture.snap(gameHwmd,gameConfig.leftX,gameConfig.top,gameConfig.width,gameConfig.height);
//left_pic.Save("\left.bmp");

var right_pic = com.picture.snap(gameHwmd,gameConfig.rightX,gameConfig.top,gameConfig.width,gameConfig.height)
// right_pic.Save("\right.bmp")
win.setForeground(winform.hwnd)
var left_bmp = gdip.bitmap(left_pic.CopyHandle())
var right_bmp = gdip.bitmap( right_pic.CopyHandle())
var left_bmpdata = left_bmp.lockdata();
var right_bmpdata = right_bmp.lockdata();
for(h=1;left_bmp.height){
for(w=1;left_bmp.width){
if( left_bmpdata.bits.array[h].array[w] != right_bmpdata.bits.array[h].array[w]){
left_bmpdata.bits.array[h].array[w] = 32768
}
}
}
left_bmp.unlockdata(left_bmpdata);
right_bmp.unlockdata(right_bmpdata)
winform.picturebox.setImage( left_bmp.copyHandle() )
}

winform.picturebox.oncommand = function(id,event){
if(gameHwmd){
var x,y = mouse.getPos();
x,y = win.toClient(winform.picturebox.hwnd,x,y);
winex.mouse.click( gameHwmd,x+gameConfig.leftX,y+gameConfig.top )
}
}

winform.show()
win.loopMessage();