找回密码
 加入
搜索
查看: 1796|回复: 3

[系统综合] NMHDR结构中的Code参数类型为什么是INT[已解决]

[复制链接]
发表于 2016-9-9 22:30:43 | 显示全部楼层 |阅读模式
本帖最后由 haijie1223 于 2016-9-22 16:32 编辑

MSDN的官方介绍地址为:
https://msdn.microsoft.com/zh-cn/library/bb775514(v=vs.71).aspx
typedef struct tagNMHDR {
  HWND     hwndFrom;
  UINT_PTR idFrom;
  UINT     code;
} NMHDR;
其中的code元素类型官方规定是UINT,但是在AU3中如果用UINT似乎是错误的,并不能使用。经查看UDF中的定义为INT。何故如此?
测试代码如下:

#include <WindowsConstants.au3>
$hForm = GUICreate("treeview", 200, 100)
$hTree = GUICtrlCreateTreeView(0, 0, 200, 100)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case -3
                        Exit
        EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
        Local $hWndFrom, $iCode, $tNMHDR
        $tNMHDR = DllStructCreate('HWND hwndFrom;UINT_PTR idFrom;INT code;', $lParam) ;最后一个参数修改为Uint则无效。
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case GUICtrlGetHandle($hTree)
                        Switch $iCode
                                Case $NM_CLICK
                                        MsgBox(0, '$iCode=' & $iCode, '单击', 1, $hForm)
                        EndSwitch
        EndSwitch
EndFunc   ;==>WM_NOTIFY
发表于 2016-9-9 23:29:31 | 显示全部楼层
我觉得这是个 Bug
发表于 2016-9-19 15:21:55 | 显示全部楼层
感觉海大 又做了不得了的东西了。
 楼主| 发表于 2016-9-22 16:30:49 | 显示全部楼层
自问自答:
AU3中没有UINT类型,而$NM_CLICK为INT类型,所以所以如果定义为UINT类型,需要把数据转化为相同类型的INT类型再进行比较。
所以定义为UINT类型的代码如下:
#include <WindowsConstants.au3>
$hForm = GUICreate("treeview", 200, 100)
$hTree = GUICtrlCreateTreeView(0, 0, 200, 100)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case -3
                        Exit
        EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
        Local $hWndFrom, $iCode, $tNMHDR
        $tNMHDR = DllStructCreate('HWND hwndFrom;UINT_PTR idFrom;UINT code;', $lParam) ;最后一个参数修改为Uint则无效。
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        $iCode = BitAND('0x' & Hex($iCode), 0xffffffff)
        Switch $hWndFrom
                Case GUICtrlGetHandle($hTree)
                        Switch $iCode
                                Case $NM_CLICK
                                        MsgBox(0, '$iCode=' & $iCode, '单击', 1, $hForm)
                        EndSwitch
        EndSwitch
EndFunc   ;==>WM_NOTIFY
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-2 14:11 , Processed in 0.081456 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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