简单介绍Application.Exit()函数和Environment.Exit()函数
一般情况下这两个函数都可以结束程序运行,不过 一般情况下,都使用前者,或者说使用前者来退出程序更习惯顺手些。至少我是这么觉得。
其实要是深入理解这两个函数。
msdn里面是这么说的:Application.Exit(); 通知所有消息泵必须终止,并且在处理了消息以后关闭所有应用程序窗口。
Environment.Exit(); 终止此进程并为基础操作系统提供指定的退出代码。
自己理解:Application.Exit(); 并不能立刻退出程序,只是通知程序用到的所有消息终止。
Environment.Exit(); 立刻结束程序运行
当然,在使用了Application.Exit()之后要是没有创建进程或者线程,那么,其实不就是和Environment.exit()的效果一样吗?也就是说在外在看来就好像是立刻结束了程序运行。
但是要是,在使用了Application.Exit();之后,又创建了线程或者进程的话。即使执行了Application.Exit();还是会执行后面的代码(这里说的代码是创建了线程或者进程的代码),然后创建完之后再退出程序。
也不知道说明白了没有。或者这么说:true=(Environment.Exit() == return);
false=(Application.Exit() == return);
希望对大家有一定的帮助。
未提供头文件情况下,C++中使用COM
前面用CPP测试COM时,需要使用MIDL生成的_i.c与*.h文件。本文示范无这些文件的情况下,用CPP使用COM的方法。
测试工程必须是MFC工程(创建MFC工程过程省略)。
1.添加TypeLib类:
2.添加测试代码:
void CMFCClientDlg::OnBnClickedOk() { CFirstCoClx t; IID id; //CLSID可以从/Fo中的*.tlh中获取,详细信息参考MSDN index - #import directive CLSIDFromString(L"{a6f67b5b-f33e-40fd-8821-0118bfcb214f}", &id); t.CreateDispatch( id ); long a, b, c; a = b = c = 3; t.AddFn(a, b, &c); t.put_num( 45 ); a = t.get_num(); CDialogEx::OnOK(); }
//具体使用方法:下载“按键精灵”,新建脚本,复制以下程序部分,粘贴,保存,(启动键自己设置哦~)
//打开QQ连连看,进入游戏,游戏开始后,启动脚本便可
//注意:必须在这两种情况下再启动脚本:1.游戏开始后全屏,或者2.游戏开始后把游戏窗口与屏幕左上角对齐
//呵呵,上边这个注意,大家有时间就优化一下吧,优化后不要吝啬贴上来
//(QQ:15668392,地址http://user.qzone.qq.com/15668392/)
//另外,程序有很多思路可以更加优化,,如有兴趣,可以一起玩啊......
//程序中放置了几处 delay,,,可以去掉
For 10
//定义第一点坐标
VBS FirstCubeLeft = 14
VBS FirstCubeTop = 181
//VBS FirstCubeLeft = 19
//VBS FirstCubeTop = 232
//一个方块恒量
VBS CubeWidth = 31
VBS CubeHeight = 35
//连连看行11数和列数19
//背景颜色704C30
bgColor = "704C30"
//定义所有方块中心点颜色二维数组
//建立容器,盛放非重复颜色值,有多少存多少
Dim arrDistinctColor()
//容器长度
DistinctColorCount = -1
//非重复颜色值数组长度动态改变,此处这样做,只是为了下边不用每次循环都判断容器为null,应该可以提高效率
//Redim Preserve arrDistinctColor(DistinctColorCount)
//Dim arrCenterColor(208)
//赋值所有方块中心点颜色二维数组
For i = 0 To 10
For j = 0 To 18
screenX = FirstCubeLeft + CubeWidth / 2 + 0.5 + CubeWidth * j
screenY = FirstCubeTop + CubeHeight / 2 + 0.5 + CubeHeight * i
//MessageBox screenX &","& screenY
centerColor = GetPixelColor(screenX - 3, screenY - 2)
//MoveTo screenX - 3, screenY - 2
//LeftClick 1
//如果有方块才保存
If centerColor <> "704C30" then
//arrCenterColor(i* 19 + j) = centerColor//收录所有颜色
//遍历非重复颜色集合arrDistinctColor
For m = 0 To DistinctColorCount
//如果已经存在该颜色,则 1.非重复颜色集合不重复收录该颜色
//MessageBox arrDistinctColor(m)(0)
If arrDistinctColor(m)(0) = centerColor Then
//找到位置数组
LocationArray = arrDistinctColor(m)(1)
VBS CubeCount =UBound(LocationArray)//这个颜色的方块已经有的个数(-1)
Redim Preserve LocationArray(CubeCount + 1)
LocationArray(CubeCount + 1) = i * 19 + j
//MessageBox i * 19 + j
arrDistinctColor(m)(1) = LocationArray
Goto ExitCompareDistinctColor//跳出循环
End If
Next
DistinctColorCount = DistinctColorCount + 1
Redim Preserve arrDistinctColor(DistinctColorCount)//非重复颜色值数组长度动态改变
//1.收录该颜色
VBS Dim ColorContainer(1)
ColorContainer(0) = centerColor
VBS Dim CubeLocation()
Redim Preserve CubeLocation(0)
CubeLocation(0) = i * 19 + j
//MessageBox i * 19 + j
ColorContainer(1) = CubeLocation
arrDistinctColor(DistinctColorCount) = ColorContainer//收录非重复颜色(该颜色用一个一维二项数组表示为{颜色值,[(location1),(location2)...]})
Rem ExitCompareDistinctColor//退出循环比较非重复颜色
End if
Next
Next
//MessageBox UBound(arrDistinctColor)
/*
For i = 0 To UBound(arrDistinctColor)
CubeCount = UBound(arrDistinctColor(i)(1))
//顺时针跑一次A-B A-B-C-D A-B-C-D-E-F
For j=0 To CubeCount
screenX = (arrDistinctColor(i)(1)(j) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY = (Int(arrDistinctColor(i)(1)(j) / 19) +1) * CubeHeight + FirstCubeTop - CubeHeight / 2
MoveTo screenX, screenY
LeftClick 1
Next
//如果有4个方块,则A-C B-D
Next
*/
//MessageBox "DistinctColorCount" & DistinctColorCount & "UBound(arrDistinctColor)" & UBound(arrDistinctColor)
If DistinctColorCount = - 1 Then
Goto ExitApplication//退出循环
End If
//MessageBox UBound(arrDistinctColor)
For i = 0 To UBound(arrDistinctColor)
CubeCount = UBound(arrDistinctColor(i)(1))
//顺时针跑一次A-B
screenX1 = (arrDistinctColor(i)(1)(0) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY1 = (Int(arrDistinctColor(i)(1)(0) / 19) +1) * CubeHeight + FirstCubeTop - CubeHeight / 2
screenX2 = (arrDistinctColor(i)(1)(1) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY2 = (Int(arrDistinctColor(i)(1)(1) / 19) +1) * CubeHeight + FirstCubeTop - CubeHeight / 2
screenX3 = (arrDistinctColor(i)(1)(2) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY3 = (Int(arrDistinctColor(i)(1)(2) / 19) +1) * CubeHeight + FirstCubeTop - CubeHeight / 2
screenX4 = (arrDistinctColor(i)(1)(3) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY4 = (Int(arrDistinctColor(i)(1)(3) / 19) + 1) * CubeHeight + FirstCubeTop - CubeHeight / 2
screenX5 = (arrDistinctColor(i)(1)(4) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY5 = (Int(arrDistinctColor(i)(1)(4) / 19) +1) * CubeHeight + FirstCubeTop - CubeHeight / 2
screenX6 = (arrDistinctColor(i)(1)(5) mod 19 +1) * CubeWidth + FirstCubeLeft - CubeWidth / 2
screenY6 = (Int(arrDistinctColor(i)(1)(5) / 19) + 1) * CubeHeight + FirstCubeTop - CubeHeight / 2
If CubeCount = 1 Then //如果只有两个方块A,B,则A-B
MoveTo screenX1, screenY1
LeftClick 1
MoveTo screenX2, screenY2
LeftClick 1
ElseIf CubeCount = 3 Then//如果有4个方块A,B,C,D则A-B-C-D-A-C B-D
MoveTo screenX1, screenY1
LeftClick 1
MoveTo screenX2, screenY2
LeftClick 1
MoveTo screenX3, screenY3
LeftClick 1
MoveTo screenX4, screenY4
LeftClick 1
MoveTo screenX1, screenY1
LeftClick 1
MoveTo screenX3, screenY3
LeftClick 1
Delay 100
MoveTo screenX2, screenY2
LeftClick 1
MoveTo screenX4, screenY4
LeftClick 1
ElseIf CubeCount >= 5 Then//如果有6个方块A,B,C,D,E,F则A-B-C-D-E-F-A-C-E-A-D-F-B-D B-E C-F
MoveTo screenX1, screenY1
LeftClick 1
MoveTo screenX2, screenY2
LeftClick 1
MoveTo screenX3, screenY3
LeftClick 1
MoveTo screenX4, screenY4
LeftClick 1
MoveTo screenX5, screenY5
LeftClick 1
MoveTo screenX6, screenY6
LeftClick 1
MoveTo screenX1, screenY1
LeftClick 1
MoveTo screenX3, screenY3
LeftClick 1
MoveTo screenX5, screenY5
LeftClick 1
MoveTo screenX1, screenY1
LeftClick 1
MoveTo screenX4, screenY4
LeftClick 1
MoveTo screenX6, screenY6
LeftClick 1
MoveTo screenX2, screenY2
LeftClick 1
MoveTo screenX6, screenY6
LeftClick 1
Delay 100
MoveTo screenX2, screenY2
LeftClick 1
MoveTo screenX5, screenY5
LeftClick 1
Delay 100
MoveTo screenX3, screenY3
LeftClick 1
MoveTo screenX6, screenY6
LeftClick 1
End If
Next
MoveTo 0,0
Delay 1500
Next
Rem ExitApplication//退出程序