找回密码
 加入
搜索
查看: 1781|回复: 7

记录一些参考贴

[复制链接]
发表于 2017-7-1 16:11:37 | 显示全部楼层 |阅读模式
本帖最后由 joint 于 2017-7-1 17:07 编辑

动态创建并响应按钮
http://www.autoitx.com/forum.php ... &from=favorites
Opt("GUIOnEventMode", 1);启用EventMode

$GUI = GUICreate("动态创建并响应按钮", 720, 350)
GUISetOnEvent(-3, "main")
Dim $Button[1];按钮数组
Dim $posx = 0, $posy = 1
Dim $t = 109;需要创建的按钮总数
GUISetState()

For $i = 0 To $t
        ReDim $Button[$i + 1]
        If Mod($i, 11) = 0 And $i <> 0 Then
                $posx += 1
                $posy = 1
        EndIf
        $Button[$i] = GUICtrlCreateButton("Button" & $i, 15 + $posx * 70, 30 * $posy - 15, 60, 25, 0)
        GUICtrlSetOnEvent($Button[$i], "main")
        $posy += 1
Next

While 1
        Sleep(120000)
WEnd

Func main()
        For $i = 0 To $t
                Switch @GUI_CtrlId
                        Case -3
                                Exit
                        Case $Button[$i]
                                MsgBox(0, "第 " & $i & " 个按钮", "我是按钮 " & $i & " 号!", 0, $GUI)
                EndSwitch
        Next
EndFunc
这位“298311657”也是像水木子那样水平高人品又好的大神啊,只是看日期有一个多月没出现了,不知怎么回事。
 楼主| 发表于 2017-7-1 16:14:35 | 显示全部楼层
一个漂亮的分页标签(控件子类化实现)
http://www.autoitx.com/forum.php ... 2874&highlight=
 楼主| 发表于 2017-7-1 17:14:24 | 显示全部楼层
本帖最后由 joint 于 2017-7-1 17:35 编辑
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
 
Local $hGUI = GUICreate("Funkey's BitBtn-Example", 1060, 270)
Local $IcoPath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "", 0, -1)) & "Icons\au3.ico"
 
$BitBtn1 = _GUICtrlCreateBitBtn("Explorer", 10, 10, 200, 25, "shell32.dll", 5)
$BitBtn2 = _GUICtrlCreateBitBtn("Button2", 10, 40, 200, 35, "shell32.dll", 7)
$BitBtn3 = _GUICtrlCreateBitBtn("Button3", 10, 80, 200, 55, "shell32.dll", 10, 20)
$BitBtn4 = _GUICtrlCreateBitBtn("Button4", 10, 140, 200, 55, $IcoPath, 20)
$BitBtn5 = _GUICtrlCreateBitBtn("Papierkorb", 10, 200, 200, 55, "shell32.dll", 32, 30, 20, 0, 20)
 
$BitBtn6 = _GUICtrlCreateBitBtn("Explorer", 220, 10, 200, 25, "shell32.dll", 5, -1, 0, 1)
$BitBtn7 = _GUICtrlCreateBitBtn("Button7", 220, 40, 200, 35, "shell32.dll", 7, -1, 0, 1)
$BitBtn8 = _GUICtrlCreateBitBtn("Button8", 220, 80, 200, 55, "shell32.dll", 10, 20, 0, 1)
$BitBtn9 = _GUICtrlCreateBitBtn("Button9", 220, 140, 200, 55, $IcoPath, 20, -1, 0, 1)
$BitBtn10= _GUICtrlCreateBitBtn("Papierkorb", 220, 200, 200, 55, "shell32.dll", 32, 30, 20, 1, 20)
 
$BitBtn11 = _GUICtrlCreateBitBtn("Explorer", 430, 10, 200, 25, "shell32.dll", 5, -1, 0, 2)
$BitBtn12 = _GUICtrlCreateBitBtn("Button12", 430, 40, 200, 35, "shell32.dll", 7, -1, 0, 2)
$BitBtn13 = _GUICtrlCreateBitBtn(@CR & @CR & "Button13", 430, 80, 200, 55, "shell32.dll", 10, 20, 0, 2)
$BitBtn14 = _GUICtrlCreateBitBtn(@CR & @CR & "Button14", 430, 140, 200, 55, $IcoPath, 20, 30, 0, 2, 10)
$BitBtn15 = _GUICtrlCreateBitBtn(@CR & "Papierkorb", 430, 200, 200, 55, "shell32.dll", 32, 20, 20, 2, 15)
 
$BitBtn16 = _GUICtrlCreateBitBtn("Explorer", 640, 10, 200, 25, "shell32.dll", 5, -1, 0, 3)
$BitBtn17 = _GUICtrlCreateBitBtn("Button17", 640, 40, 200, 35, "shell32.dll", 7, -1, 0, 3)
$BitBtn18 = _GUICtrlCreateBitBtn("Button18", 640, 80, 200, 55, "shell32.dll", 10, 20, 0, 3, 15)
$BitBtn19 = _GUICtrlCreateBitBtn("Button19", 640, 140, 200, 55, $IcoPath, 20, 35, 0, 3)
$BitBtn20 = _GUICtrlCreateBitBtn("Papierkorb", 640, 200, 200, 55, "shell32.dll", 32, -1, 20, 3, 20)
 
$BitBtn21 = _GUICtrlCreateBitBtn("", 850, 10, 200, 25, "shell32.dll", 5, -1, 0, 4)
$BitBtn22 = _GUICtrlCreateBitBtn("", 850, 40, 200, 35, "shell32.dll", 7, -1, 0, 4)
$BitBtn23 = _GUICtrlCreateBitBtn("", 850, 80, 200, 55, "shell32.dll", 10, 20, 0, 4)
$BitBtn24 = _GUICtrlCreateBitBtn("", 850, 140, 200, 55, $IcoPath, 20, -1, 0, 4)
$BitBtn25 = _GUICtrlCreateBitBtn("Papierkorb", 850, 200, 200, 55, "shell32.dll", 32, -1, 20, 4, 20)
 
GUISetState()
 
Local $msg
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    For $i = 1 To 25
        If $msg = Eval("BitBtn" & $i) Then ConsoleWrite("$BitBtn"&$i& ": " & _BitBtnClick(Eval("BitBtn" & $i)) & @CR)
    Next
    Sleep(10)
WEnd
 
Func _GUICtrlCreateBitBtn($sText, $iLeft, $iTop, $iWidth, $iHeight, $sImg, $iIndex = 0, $iMaxIconHeight = -1, $iDist = 0, $nAllign = 0, $iFontSize = 8.5, $iFontWeight = Default)
    ;funkey 16.12.2009
    Local $iOffsetX, $iOffsetY, $LabelStyle = 0x201
    Local $a = _GetTextSize("a  a", $iFontSize)
    Local $b = _GetTextSize("aa", $iFontSize)
    Local $SpaceLen = ($a[0] - $b[0]) / 5
    Local $aSize = _GetTextSize($sText, $iFontSize)
    Local $iIconHeight = $iMaxIconHeight
    If $iMaxIconHeight = -1 Or $iMaxIconHeight >  $iHeight - 8 Then
        $iIconHeight = $iHeight - 8
    EndIf
    Local $iSpaces = Ceiling(($iIconHeight + $iDist) / $SpaceLen)
    Switch $nAllign
        Case 0  ;Icon is left
            $iOffsetX = $iWidth / 2 - $aSize[0] / 2 - $iIconHeight / 2 - $iDist / 2
            $iOffsetY = ($iHeight - $iIconHeight) / 2
            $sText = StringFormat("%" & $iSpaces + StringLen($sText) & "s", $sText)
        Case 1  ;Icon is right
            $iOffsetX = $iWidth / 2 + $aSize[0] / 2 - $iIconHeight / 2 + $iDist / 2
            $iOffsetY = ($iHeight - $iIconHeight) / 2
            $sText = StringFormat("%" & -$iSpaces - StringLen($sText) & "s", $sText)
        Case 2  ;Icon is on the top
            $iOffsetX = $iWidth / 2 - $iIconHeight / 2
            $iOffsetY = 4
            $LabelStyle = 0x1
        Case 3  ;Icon is on the bottom
            $iOffsetX = $iWidth / 2 - $iIconHeight / 2
            $iOffsetY = $iHeight - $iIconHeight -4
            $LabelStyle = 0x1
        Case 4 ;Icon is in the middle
            $iOffsetX = $iWidth /2 - $iIconHeight / 2 + $iDist / 2
            $iOffsetY = ($iHeight - $iIconHeight) / 2
    EndSwitch
    Local $hBtn = GUICtrlCreateLabel("", $iLeft, $iTop, $iWidth, $iHeight)
    GUICtrlCreateIcon($sImg, $iIndex, $iLeft + $iOffsetX, $iTop + $iOffsetY, $iIconHeight, $iIconHeight, 0)
    GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, $LabelStyle, 0x200)
    GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
    GUICtrlSetFont(-1, $iFontSize, $iFontWeight)
    GUICtrlSetState(-1, 32) ;$GUI_HIDE
    GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, $LabelStyle, 0x001)
    GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
    GUICtrlSetFont(-1, $iFontSize, $iFontWeight)
    Return $hBtn
EndFunc   ;==>_GUICtrlCreateBitBtn
 
Func _BitBtnClick($IdBtn)
    ;funkey 16.12.2009
    Local $aInfo, $aInfoLast
    GUICtrlSetState($IdBtn + 3, 32) ;$GUI_HIDE
    GUICtrlSetState($IdBtn + 2, 16) ;$GUI_SHOW
    $aInfoLast = GUIGetCursorInfo()
    Do
        Sleep(10)
        $aInfo = GUIGetCursorInfo()
        If @error Then Return 0
        If $aInfo[4] <> $aInfoLast[4] Then ;if changing the hover-control
            If $aInfo[4] < $IdBtn Or $aInfo[4] > $IdBtn + 3 Then ;if not hovering the BitBtn
                GUICtrlSetState($IdBtn + 2, 32) ;$GUI_HIDE
                GUICtrlSetState($IdBtn + 3, 16) ;$GUI_SHOW
            Else
                GUICtrlSetState($IdBtn + 3, 32) ;$GUI_HIDE
                GUICtrlSetState($IdBtn + 2, 16) ;$GUI_SHOW
            EndIf
        EndIf
        $aInfoLast = $aInfo
    Until Not $aInfo[2]
    GUICtrlSetState($IdBtn + 2, 32) ;$GUI_HIDE
    GUICtrlSetState($IdBtn + 3, 16) ;$GUI_SHOW
    If $aInfo[4] <> $IdBtn + 2 And $aInfo[4] <> $IdBtn + 1 Then Return 0
    Return 1
EndFunc   ;==>_BitBtnClick
 
Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
 ;Author: Bugfix
 ;Modified: funkey
 If $nText = '' Then Return
 _GDIPlus_Startup()
 Local $hFormat = _GDIPlus_StringFormatCreate(0)
 Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
 Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
 Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
 Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0)
 Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
 Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
 Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
 _GDIPlus_StringFormatDispose($hFormat)
 _GDIPlus_FontDispose($hFont)
 _GDIPlus_FontFamilyDispose($hFamily)
 _GDIPlus_GraphicsDispose($hGraphic)
 _GDIPlus_Shutdown()
 Local $aSize[2] = [$iWidth, $iHeight]
 Return $aSize
EndFunc   ;==>_GetTextSize

本帖子中包含更多资源

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

×
发表于 2017-7-1 19:48:51 | 显示全部楼层
很好,学习学习
发表于 2017-7-13 12:57:37 | 显示全部楼层
很好,学习学习。没钱
发表于 2017-7-14 07:46:03 | 显示全部楼层
下载太︿( ̄︶ ̄)︿需要金钱了
发表于 2017-7-14 07:47:32 | 显示全部楼层
来点钱,花钱如流水
发表于 2017-8-6 19:51:14 | 显示全部楼层
一楼的位置好啊..












专业代发帖子,发帖宣传,论坛发帖,网络推广,外链代发。
联系QQ:188662616   微信号:188662616

1. 论坛:发帖·顶贴·盖楼·维护·回复·评论·沉帖·负面压制·新闻评论·置顶加精等等~
2. 微博:加粉·直发·转发·评论·转评·话题·阅读量·投票·收藏·点赞·等等~
3. 微信:加粉·转发·点赞·阅读量·分享·投票·等等~
4. 点击:帖子点击率·视频点击率·博客点击率·网站IP·等等~
5. 视频:评论·点赞·等等~
6. sns :转发·评论·等等~
7. 问答:百度知道·360问答·搜搜问答·等等~
8. 投票:各种网络评选投票·等等~
9. 博客:博客发帖·评论·高等级博客发帖
10.qq群:各类群发
11.贴吧 :加关注·包月签到·包年签到·提高贴吧排名

承接各类网络任务!人手多,老手多,多年执行经验,全年无休假。
联系QQ:188662616  微信号:188662616

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

本版积分规则

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

GMT+8, 2024-3-29 17:34 , Processed in 0.075728 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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