找回密码
 加入
搜索
查看: 12593|回复: 27

[效率算法] 窗体控件移动类---超多控件整体高效移动[已解决]

 火.. [复制链接]
发表于 2012-5-5 20:01:49 | 显示全部楼层 |阅读模式
本帖最后由 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2012-5-5 20:13:55 | 显示全部楼层

如上图所示,我需要将字符点阵移动成这样的,然后点击某个0位置的lable,提示该点的坐标并写入到字库, 左键点写入,右键点删除。
如何能让移动的时候效率点?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-5-5 20:15:09 | 显示全部楼层
如果是整体移动Label,可以内嵌个创建所有Label的子窗体,移动时移动子窗体
 楼主| 发表于 2012-5-5 20:17:37 | 显示全部楼层
回复 3# afan


    子窗体移动的时候,超出边界的lable不会消失。
发表于 2012-5-5 20:18:45 | 显示全部楼层
lable颜色构成的,多得有点吓人,呵呵,怎么不直接表示有颜色部分呢?
发表于 2012-5-5 20:19:55 | 显示全部楼层
本帖最后由 afan 于 2012-5-5 20:21 编辑

回复 4# lanfengc


    内嵌的,不是分层的,超出边界的lable怎么会不消失呢?
一眨眼上代码了…
 楼主| 发表于 2012-5-5 20:43:23 | 显示全部楼层
回复 6# afan


    内嵌子窗体 移动的时候,内部LABLE的坐标就不对了吧。
发表于 2012-5-5 20:44:53 | 显示全部楼层
回复 7# lanfengc


    重新计算下应该不麻烦
发表于 2012-5-5 20:54:42 | 显示全部楼层
回复 1# lanfengc


    这也是前段时间我也问过的一个问题:用au3建了很多控件后,就会闪的问题
我也一直没有找到好的办法
http://www.autoitx.com/forum.php ... ighlight=%2Bhappytc
发表于 2012-5-5 20:56:50 | 显示全部楼层
学习了  。长见识了
 楼主| 发表于 2012-5-5 20:59:51 | 显示全部楼层
回复 8# afan


    给个例子? 我不知道如何创建子窗体。
发表于 2012-5-5 21:05:05 | 显示全部楼层
本帖最后由 hzxymkb 于 2012-5-5 21:08 编辑

回复 10# haijie1223


     NND,你又隐身了?我看不见你上线?
发表于 2012-5-5 21:08:49 | 显示全部楼层
回复 11# lanfengc


    用TAB行吗?
 楼主| 发表于 2012-5-5 21:11:03 | 显示全部楼层
回复 13# hzxymkb


    将所有的Lable创建到一个TAB页中,然后移动吗?
发表于 2012-5-5 21:26:27 | 显示全部楼层
回复 14# lanfengc


    是的
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-13 03:27 , Processed in 0.102487 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表