本帖最后由 lanfengc 于 2012-5-5 21:58 编辑
我在更新我写的那个验证码识别程序,准备做成能够让人调用的UDF或者EXE 带参数运行, 写字库生成程序的时候遇到一个问题。 窗体上超多的lable在左移 右移 上移 下移 的时候,超级慢。 我是用循环移动每个控件来完成的。 请问有什么好的办法吗? 如下图示。
源代码如下:
#include <file.au3>
#Include <Misc.au3>
#include <array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $lable[40][120] , $dll=DllOpen("User32.dll") , $posarray[40][120] ,$File="" ,$iLeft=0,$iRight=0,$iTop=0,$iBottom=0
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form = GUICreate("点阵创建工具", 120*9, 40*13+72, 192, 114)
GUISetBkColor(0xA6CAF0)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
$inputpath = GUICtrlCreateInput("", 134, 5, 617, 21)
$Label1 = GUICtrlCreateLabel("选择编码过的文本文件", 8, 8, 124, 17)
$btnselect = GUICtrlCreateButton("SelectFile", 768, 4, 75, 21)
GUICtrlSetOnEvent(-1, "btnselectClick")
$btnMoveLeft = GUICtrlCreateButton("左移4像素", 8, 40, 75, 18)
GUICtrlSetOnEvent(-1, "btnMoveLeftClick")
$btnMoveRight = GUICtrlCreateButton("右移4像素", 93, 41, 75, 18)
GUICtrlSetOnEvent(-1, "btnMoveRightClick")
$btnMoveBottom = GUICtrlCreateButton("下移2像素", 271, 43, 75, 18)
GUICtrlSetOnEvent(-1, "btnMoveBottomClick")
$btnMoveTop = GUICtrlCreateButton("上移2像素", 186, 42, 75, 18)
GUICtrlSetOnEvent(-1, "btnMoveTopClick")
;~ $Group1 = GUICtrlCreateGroup("", 0,64,120*9, 40*13+72)
For $i=0 To 39
For $j=0 To 119
$lable[$i][$j] = GUICtrlCreateLabel("", 1+$j*9, 72+$i*13, 8, 12 , $WS_BORDER)
Next
Next
;~ GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(10)
If _IsPressed(0x01,$dll) And WinActive($Form) Then
Local $MouseInfo=GUIGetCursorInfo($Form)
;~ MsgBox(0,$MouseInfo[0]&"|"&$MouseInfo[1],$MouseInfo[2]&"|"&$MouseInfo[3]&"|"&$MouseInfo[4])
;~ MsgBox(0,Floor(($MouseInfo[4]-6)/120),Mod($MouseInfo[4]-6,120))
If $MouseInfo[4]>9 And GUICtrlRead($MouseInfo[4])<>" " Then
GUICtrlSetBkColor($MouseInfo[4],0XFF0000)
ToolTip(Floor(($MouseInfo[4]-10)/120)-$iTop&"|"&Mod($MouseInfo[4]-10,120)-$iLeft)
ElseIf $MouseInfo[4]=$btnselect Then
GUICtrlSetState($btnselect,$GUI_DISABLE)
btnselectClick()
GUICtrlSetState($btnselect,$GUI_ENABLE)
EndIf
ElseIf _IsPressed(0x02,$dll) Then
Local $MouseInfo=GUIGetCursorInfo($Form)
;~ MsgBox(0,$MouseInfo[0]&"|"&$MouseInfo[1],$MouseInfo[2]&"|"&$MouseInfo[3]&"|"&$MouseInfo[4]-5)
;~ MsgBox(0,Floor(($MouseInfo[4]-6)/120),Mod($MouseInfo[4]-6,120))
If $MouseInfo[4]>9 And GUICtrlRead($MouseInfo[4])<>" " Then GUICtrlSetBkColor($MouseInfo[4],0xA6CAF0)
EndIf
WEnd
Func btnselectClick()
$File=FileOpenDialog("选择生成的点阵文件",@ScriptDir,"文本文件(*.txt)")
If $File="" Then Return
GUICtrlSetData($inputpath,$File)
Local $array
_FileReadToArray($File,$array)
For $i=0 To $array[0]-1
$temp=StringSplit($array[$i+1],"")
For $j=0 To $temp[0]-2
$posarray[$i][$j]=$temp[$j+1]
GUICtrlSetData($lable[$i][$j],$posarray[$i][$j])
Next
Next
EndFunc
Func btnMoveRightClick()
$iRight+=4
$iLeft-=4
For $i=0 To 39
For $j=0 To 119
ControlMove($Form,"",$lable[$i][$j],$j*9+1+$iRight*9,Default)
Next
Next
EndFunc
Func btnMoveLeftClick()
$iLeft+=4
$iRight-=4
For $i=0 To 39
For $j=0 To 119
ControlMove($Form,"",$lable[$i][$j],$j*9+1-$iLeft*9,Default)
Next
Next
EndFunc
Func btnMoveBottomClick()
$iBottom+=2
$iTop-=2
For $i=0 To 39
For $j=0 To 119
ControlMove($Form,"",$lable[$i][$j],Default,72+($i+$iBottom)*13)
Next
Next
EndFunc
Func btnMoveTopClick()
$iTop+=2
$iBottom-=2
For $i=0 To 39
For $j=0 To 119
ControlMove($Form,"",$lable[$i][$j],Default,72+($i-$iTop)*13)
Next
Next
EndFunc
Func FormClose()
Exit
EndFunc
随便发个点阵文件
00 00000 00
00 0000 00
0 00000 000 000000
00 00000 00000 00000000000
0000000 00000 00000 000000000000000000000
0000000000 00000 00000 0000 0000000000000000
000000000000000000000000 00 00000000000000000
0000000000000000000000000 0 0000000 000000
0000000000000000 000000000 00 000000 00000
000000 0000000 00000000 00 000000 00000
000000 00000 0000000 00 000000 00000
00000 000000 000000 00000 00 000000 00000
00000 00000 00000 000000000 00000000000000000 000000 00000
00000 00000 00000 000000000000 00 0000000000000 000000 00000
00 00000 0000000000000000000 00 0000000000000000 0000000 00000
0 00000 0000000000000000000 00 00000000000000000 0000000 000000
00 00000000 000000000 0000000000 000000000000000000 00000000 0000000
0 0000000 00000000 0000000 00000000 00000000 0000000000000000
0 00000000 00000000 0000000 0000000 000000 000000000000000
0 000000000 000000000 0000000 000000 000000 0000000000000000
0 0000000000 000000000 0000000 0000000 000000 000000000000000000
00 000000 0000000000 000000 000000 0000000 00000000000000000000
0 000000 0000000000 000000 0000000 0000000 00000000000 0000000
00 000000 0000000000 000000 00000000000000000000000 00000000 000000
0 00000 000000 000000 0000 000000 00000000000000000000000 000000000 00000
0 00000 000000 000000 0000 000000 00000000000000000000000 00000000 000000
00 00000 000000 000000 000 000000 00000000000000000000000 00000000 000000
0 00000 000000 000000 0000 000000 000000 000000000 000000
0 00000 0000000 000000 0000 000000 000000 000000000 000000
00 000000 000000 000000 0000 000000 000000 0000000 000000
0 0000000000000000 000000 000 0000000 000000 00000000 00000
00 000000000000000 000000 0000 0000000 000000 000000 00000000 00000
0 00000000000000 000000 0000 0000000 0000000 000000 000000000 000000
0 00000000000 000000 0000 000000 0000000000000000000 000000000 0000000
0 00000000 000000 0000 000000 00000000000000000 000000000000000000000
0 00000 0000 000000 0000000000000000 0000000000000000000
00 0000 0000000000000 00000000000000000
0 0000 0000000 000000000000000
0000 0000000000
0000 0
解决的办法是 水木子 发出来的,在本帖后面有。 我现在把发到顶楼来,便于别人查阅。
#include <Constants.au3>
#include <WindowsConstants.au3>
Global $aButton[1000] ;总数
Global $iNumber = 100 ;每行数量
Global $iSpacingX = 9, $iSpacingY = 9 ;垂直、水平,间距
Global $iY = 0
Opt('GUIOnEventMode', 1)
$Form1 = GUICreate('', 298, 91)
GUISetOnEvent(-3, '_Events')
GUISetState()
$Form2 = GUICreate('', 910, 200, 0, 10, $WS_CHILD, $WS_EX_ACCEPTFILES, $Form1)
For $i = 0 To UBound($aButton) - 1
$aButton[$i] = GUICtrlCreateLabel('', $iSpacingX * Mod($i, $iNumber), $iSpacingY * Floor($i / $iNumber), 10, 10, $WS_BORDER)
If Random(1, 5, 1) = 1 Then GUICtrlSetBkColor(-1, 0xFF0000)
Next
GUISetState()
While 1
WinMove($Form2, '', $iY, 0)
$iY -= 9
Sleep(100)
WEnd
Func _Events()
Switch @GUI_CtrlId
Case -3
Exit
EndSwitch
EndFunc ;==>_Events
|