找回密码
 加入
搜索
查看: 5150|回复: 9

[AU3基础] 多个控件的组合问题(已解决)

  [复制链接]
发表于 2010-4-15 21:33:54 | 显示全部楼层 |阅读模式
本帖最后由 gto250 于 2010-4-17 06:44 编辑

今天逛论坛的时候发现一个mac地址的udf,然后找到了最原始的代码,我打算参照他的代码也写个控件组合的代码,但是试了没有成功。

我想实现的功能是:将button按钮叠加在一个input输入框上,并且按钮可用
但是我并没有成功,代码如下
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 144, 144, 121, 21)
$h1=GUICtrlGetHandle(-1)
$Button1 = GUICtrlCreateButton("Button1", 192, 144, 75, 25)
$h2=GUICtrlGetHandle(-1)

_WinAPI_SetParent($h1, $h2)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
mac地址控件的原始代码
#include <WinAPI.au3>
#include <GUIEdit.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>

If Not IsDeclared("WM_CHAR") Then $WM_CHAR = 0x102

$hGUI = GUICreate("Test", 180, 100)

GUICtrlCreateLabel("", 20, 20, 140, 20, $SS_SUNKEN)
$hParent = GUICtrlGetHandle(-1)
GUICtrlSetBkColor(-1, 0xFFFFFF)

$hCall = DllCallbackRegister("_IptProc", "int", "hWnd;uint;wparam;lparam")
$pCall = DllCallbackGetPtr($hCall)

Dim $iPos = 0
For $i = 0 to 5
        GUICtrlCreateInput("00", $iPos, 3, 20, 17, 1, 4)
        GUICtrlSetLimit(-1, 2)
        GUICtrlSetFont(-1, 10, 800, "", "Garamond")
        _WinAPI_SetParent(GUICtrlGetHandle(-1), $hParent)
        If $i = 0 Then
                $hOldC = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), -4, $pCall)
        Else
                _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), -4, $pCall)
        EndIf
        GUICtrlCreateLabel("-", $iPos + 41, 30, 4, 2, $SS_SUNKEN)
        GUICtrlSetFont(-1, 10, 800, "", "Garamond")
        $iPos += 23
Next


GUICtrlDelete(-1)
$iBtnRead = GUICtrlCreateButton("Read", 20, 60, 140, 20)
GUISetState()
GUIRegisterMsg(0x111, "_WMCOMMAND")

Do
        $iMsg = guiGetMsg()
        Switch $iMsg
        Case $iBtnRead
                Dim $sData = ""
                For $i = 4 to 14 Step 2
                        $sData &= GUICtrlRead($i) & "-"
                Next
                Msgbox(0, '', StringTrimRight($sData, 1))
        EndSwitch
Until $iMsg = -3

Func _IptProc($hWnd, $iMsg, $wparam, $lparam)
        If $iMsg = $WM_CHAR Then
                If StringIsXDigit(Chr($wparam)) = 0 And $wparam <> 8 Then Return 0
        EndIf
        Return _WinAPI_CallWindowProc($hOldC, $hWnd, $iMsg, $wparam, $lparam)
EndFunc        ;==>_IptProc

Func _WMCOMMAND($hWnd, $iMsg, $wparam, $lparam)
        Local $nID, $iNotifyCode
        $nID = bitAND($wparam, 0xFFFF)
        $iNotifyCode = bitShift($wparam, 0x10)
        If $iNotifyCode = $EN_CHANGE Then
                If StringLen(GUICtrlRead($nID)) >= 2 Then
                        GUICtrlSetState($nID + 2, $GUI_FOCUS)
                        _GUICtrlEdit_SetSel($nID + 2, 1, 2)
                EndIf
        EndIf
EndFunc        ;==>_WMCOMMAND
谁有解决办法,伸手帮助一下

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-4-15 22:26:05 | 显示全部楼层
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 144, 144, 121, 21)
$h1=GUICtrlGetHandle(-1)
$Button1 = GUICtrlCreateButton("Button1", 192, 144, 75, 25)
$h2=GUICtrlGetHandle(-1)

_WinAPI_SetParent($h1, $h2)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                        Case $Button1
                                                MsgBox(0,"",GUICtrlRead($Input1))

        EndSwitch
WEnd

你的代码就可使用啊。 你在WHILE循环中没有加BUTTON1的事件函数,当然无效了。
发表于 2010-4-15 23:04:42 | 显示全部楼层
#include
#include
#include
#include
#include
#Region ### START Koda GUI section ### Form=
...
lanfengc 发表于 2010-4-15 22:26


汗一个 ||
发表于 2010-4-15 23:37:24 | 显示全部楼层
那个CPU超高占用,退出后进程还在……
这样行不,简单得很~
#include <StaticConstants.au3>
GUICreate('Form1', 300, 150)
GUICtrlCreateLabel('', 50, 40, 202, 22, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, 128)
$Input1 = GUICtrlCreateInput("Input1", 51, 43, 110, 20, -1, 4)
$Button1 = GUICtrlCreateButton("Button1", 160, 41, 90, 20)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $Button1
                        MsgBox(0, 0, GUICtrlRead($Input1))
        EndSwitch
WEnd

本帖子中包含更多资源

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

×
 楼主| 发表于 2010-4-16 19:38:59 | 显示全部楼层
4楼的代码很巧,但是不是我所要的,我想要的就是button和input的组合,是叠加的那种。
2楼的朋友,我发的那个代码在我自己的电脑上根本就不行,au3版本是3.3.5.3
而且运行了以后cpu占用很大
发表于 2010-4-16 19:45:19 | 显示全部楼层
之前写那个MAC控件的UDF时,用的是较早的一个AU3版本,在那个版本中测试毫无问题。现在改用3.3.5.3,发现了同样的问题,可以在退出时加一句GUIDelete($hForm)解决。
发表于 2010-4-16 21:05:38 | 显示全部楼层
我用3.3.5.6.  没出现这个问题。
发表于 2010-4-16 23:59:58 | 显示全部楼层
4楼的代码很巧,但是不是我所要的,我想要的就是button和input的组合,是叠加的那种。
2楼的朋友,我发的那 ...
gto250 发表于 2010-4-16 19:38



    呵呵,MAC 那个也并非input叠加,也是Label的背景(第10行),上面连续生成几个无叠加的input(还有代表"-"的Label)(第18-31行)。你仔细看看就知道了~
 楼主| 发表于 2010-4-17 06:43:47 | 显示全部楼层
谢谢各位!!!!
发表于 2010-4-17 07:47:38 | 显示全部楼层
高手。。。。。。。学习。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-7-8 09:00 , Processed in 0.090810 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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