绿色风's Blog
专注AutoIT(Au3)
  • 首页
  • 流●年
  • 笔●记
    • 学习随记
    • 源码示例
  • 脚●本
    • UDF(收集)
    • 工作室UDF
    • 工具●教程
    • 教程之GDI
  • 作●品
  • 下●载
  • 情怀ExcelTip
8月82022

[推荐]控件的各事件的绑定

作者:绿色风   发布:2022-8-8 12:35 Monday   分类:学习随记   阅读:4402次   评论:0条  

控件事件
AutoIt 的 Win32 控件事件处理程序

特征
便于使用。
高性能。
语法如 Javascript。
许多事件,如鼠标、键盘、拖放文件、滚动等。
事件处理程序
注册事件处理程序以通过其句柄进行控制。

$event = CtrlEvent_Reg($handle)
    ; IsDllSctruct($event) == 1 ; -> succeed, 0 is failed
    ; $event == 0 ; -> failed

取消注册事件处理程序以通过其句柄进行控制。

$result = CtrlEvent_UnReg($handle)
    ; -> 1 : succeed
    ; -> 0 : failed

鼠标事件
当控件与鼠标交互时调用。

$event.onMouse = '__onMouse'

func __onMouse($e)
    $e.x      ; -> mouse x pos on control.
    $e.y      ; -> mouse y pos on control.
    $e.state  ; -> state of mouse
              ;    +> 0 : left.
              ;    +> 1 : just hovered.
              ;    +> 2 : pressed.
              ;    +> 3 : clicked and just release.
    $e.isOver ; -> is mouse over on control.
endfunc

键盘事件
键盘打开时调用。

$event.onKey = '__onKeyEvent'

func __onKeyEvent($e)
    $e.type     ; -> state of key
                ;    +> 0 : key is down.
                ;    +> 1 : key is up.
    $e.which    ; -> virtual key code.
    $e.key      ; -> char of key.
    $e.isHotkey ; -> key pressed is a hotkey ($e.type be down).
    $e.ctrlKey  ; -> ctrl key is pressed.
    $e.altKey   ; -> alt key is pressed.
    $e.shiftKey ; -> shift key is pressed.
endfunc

Drog 文件事件
当文件被控制时调用。
控件必须具有$WS_EX_ACCEPTFILES( 0x00000010 ) 扩展样式才能使用此事件处理程序。

$event.onDrop = '__onDrop'

func __onDrop($e)
    $e.count ; -> number of files.
    $e.files ; -> list of file name, splitted by semicolon for multiple files
             ;    e.g: 
             ;        count = 3
             ;        files = 'file_1.txt;file_2.exe;file_3.img'
endfunc

焦点事件
当控制处于焦点或丢失时调用。

$event.onFucus = '__onFocus'

func __onFocus($e)
    $e.type   ; -> type of focus
              ;    +> 0 : control was lost focus.
              ;    +> 1 : control being focus on.
    $e.handle ; -> handle (hwnd) of last control was lost/being focus.
endfunc

滚动事件
当控件滚动时调用。

$event.onScroll = '__onScroll'

func __onScroll($e)
    $e.min    ; -> minimium position.
    $e.max    ; -> maximium position.
    $e.page   ; -> range page of scrolling.
    $e.pos    ; -> position of scrolling.
    $e.type   ; -> type of scrollbar
              ;    +> 0 : horizontal scrollbar.
              ;    +> 1 : vertical scrollbar.    
    $e.action ; -> user's action on scrollbar
              ;    +> 0 : scrolls left/top by one unit.
              ;    +> 1 : scrolls right/down by one unit.
              ;    +> 2 : scrolls left/top by the width/height of the window.
              ;    +> 3 : scrolls right/down by the width/height of the window.
              ;    +> 4 : the user has dragged the scroll box (thumb) and released the mouse button
              ;    +> 5 : the user is dragging the scroll box; 
              ;        this message is sent repeatedly until the user releases the mouse button.
              ;    +> 6 : scrolls to the upper left/top.
              ;    +> 7 : scrolls to the upper right/bottom.
              ;    +> 8 : ends scroll.
endfunc

移动事件
当控制位置刚刚移动时调用。

$event.onMove = '__onMove'

func __onMove($e)
    $e.x ; -> x offset (coord on parent client).
    $e.y ; -> y offset (coord on parent client).
endfunc

大小事件
当控件大小刚刚改变时调用。

$event.onSize = '__onSize'

func __onSize($e)
    $e.type   ; -> type of resize
              ;    +> 0 : the window has been restored.
              ;    +> 1 : the window has been minimized.
              ;    +> 2 : the window has been maximized.
              ;    +> 3 : message is sent to all pop-up windows when 
              ;           some other window has been restored to its former size.
              ;    +> 4 : the window has been maximized.
    $e.width  ; -> width.
    $e.height ; -> height.
endfunc

例子

#include 'CtrlEvent.au3'

GUICreate('Test')

local $Btn = GUICtrlCreateButton('text', 20, 20, 100, 35, -1, 0x00000010)
local $hBtn = GUICtrlGetHandle($Btn)

local $Btn_event = CtrlEvent_Reg($hBtn)
$Btn_event.onKey = 'Btn_onKey'
$Btn_event.onMouse = 'Btn_onMouse'
$Btn_event.onDrop = 'Btn_onDrop'

GUISetState()

while 1
    switch GUIGetMsg()
        case -3
            CtrlEvent_UnReg($hBtn)
            exit

        case $Btn ; cannot use this

    endswitch
wend

func Btn_onKey($e)
    ConsoleWrite('type: ' & $e.type & ', which: ' & $e.which & ', key: ' & $e.key & _
        ', ctrl: ' & $e.ctrlKey & ', alt: ' & $e.altKey & ', shift: ' & $e.shiftKey & @crlf)
endfunc

func Btn_onMouse($e)
    ConsoleWrite('mouse state: ' & $e.state & ', isOver: ' & $e.isOver & ', position: ' & $e.x & ' - '& $e.y & @crlf)
endfunc

func Btn_onDrop($e)
    ConsoleWrite('file counted: ' & $e.count & ', name: ' & $e.files & @crlf)
endfunc

项目来源地址:https://github.com/small-autoit/mb





本文固定链接: http://www.jianyiit.com/post-410.html

blogger
该日志由 绿色风 于2022-8-8 12:35 Monday发表在 学习随记 分类下。
版权所有:《绿色风's Blog》 → 《[推荐]控件的各事件的绑定》;
除特别标注,本博客很多文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:

扫描二维码,在手机上阅读
上一篇::996MIR引擎,特效图集,拆分转成正坐标图片
下一篇:[分享]PNG图片图像压缩命令

热门文章

相关文章

  • Windows消息代码
  • AU3能清除IE7以上临时文件、Cookie、历史记录、表单数据等内容
  • ListView 单元格实时编辑
  • 检测当前网页,并加载返回JQuery
  • 什么是双缓冲绘图,防止闪烁[收集AU3]
取消回复

发表评论

亲,头像对么?

80 + 42 =

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


    站点统计
    • 运行时间: 20254 天
    • 日志总数: 365 篇
    • 评论数量: 7221 条
    • 微语数量: 6 条
    • 附件总量: 388 件
  • 逝出的青春

  • 打赏"绿色风"



      扫码关注本站公众号 可搜本站内容

  • Autoit V3 脚本交流群

      常驻群1:905774875
      常驻群2:40672266


  • 链接

    • AU3中文论坛
    • Excel资料库
    • 完美者博客
    • 顺网小哥'S Blog
    • 猛牛哥的博客
    • 网吧系统下载
  • 分类

    • 流●年(66)
    • 笔●记(0)
    • 脚●本(0)
    • 作品(21)
    • 学习随记(51)
    • 源码示例(68)
    • UDF(收集)(26)
    • 工作室UDF(30)
    • 工具●教程(62)
    • 教程之GDI(24)
Copyright © 2013 绿色风's Blog. Powered by emlog. Theme by 射雕天龙. 鄂ICP备2021011689号-1 鄂公网安备42102302000078号 sitemap