找回密码
 加入
搜索
楼主: jscpu

[图形处理] 。。。。。。。。。。。。。。。。。。。。。。。。

 火.. [复制链接]
 楼主| 发表于 2010-1-8 22:54:06 | 显示全部楼层
回复 15# 水木子

我想问的是像这样的话怎么改?
  1. #include <GuiListView.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <WindowsConstants.au3>
  4. _11()
  5. Func _11()
  6. $dir = @ScriptDir&"\config.ini"
  7. $Form1 = GUICreate("列表框操作", 280, 270)
  8. GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
  9. $ListView1 = GUICtrlCreateListView("账号           |密码           |", 10, 10, 260, 150)
  10. $Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
  11. $Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
  12. $Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
  13. $Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
  14. $Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
  15. $Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
  16. $Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
  17. GUISetState(@SW_SHOW)
  18. Read()

  19. While 1
  20.         $nMsg = GUIGetMsg()
  21.         Switch $nMsg
  22.                 Case $GUI_EVENT_CLOSE
  23.                         Exit
  24.                 Case $Button1
  25.                         tian()
  26.         EndSwitch
  27. WEnd
  28. EndFunc


  29. func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)

  30.         Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
  31.         Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
  32.         If @error Then Return $GUI_RUNDEFMSG
  33.         $IDFrom = DllStructGetData($tagNMHDR, 2)
  34.         $Event = DllStructGetData($tagNMHDR, 3)
  35.         $tagNMHDR = 0
  36.         Switch $IDFrom;选择产生事件的控件

  37.                         Case $ListView1

  38.                                 Switch $Event; 选择产生的事件

  39.                                         Case $NM_CLICK ; 左击
  40.                                                  $a = _GUICtrlListView_GetSelectedIndices($ListView1)
  41.         $b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
  42.         $c = StringSplit($b,"|")        
  43.         GUICtrlSetData ($Input1 ,$c[1])
  44.         GUICtrlSetData ($Input2 ,$c[2])               
  45.                                         Case $NM_DBLCLK ; 双击
  46.                                                         
  47.                                         Case $NM_RCLICK ; 右击

  48.                                 EndSwitch
  49.         EndSwitch
  50.         Return $GUI_RUNDEFMSG
  51. EndFunc   ;==>WM_NOTIFY

  52. Func Read()
  53.         $z = 0
  54.         _GUICtrlListView_DeleteAllItems($ListView1)
  55.         $read = IniReadSection($dir,"config")
  56.         If Not @error Then
  57.                 For $i = 1 To $read[0][0]
  58.                         GUICtrlCreateListViewItem($read[$i][0], $ListView1)
  59.                         _GUICtrlListView_AddSubItem($ListView1, $z, $read[$i][1], 1, $z+1)
  60.                         GUICtrlSetData($Label4,$z+1)
  61.                         $z += 1               
  62.                 Next
  63.         EndIf
  64. EndFunc

  65. Func tian()
  66.         $z = GUICtrlRead($Label4)
  67.         $a = GUICtrlRead($Input1)
  68.         $b = GUICtrlRead($Input2)        
  69.         If $a <> "" And $b <> "" Then
  70.                 IniWrite($dir,"config",$a,$b)
  71.                 GUICtrlCreateListViewItem($a, $ListView1)               
  72.                 _GUICtrlListView_AddSubItem($ListView1, $z, $b, 1, $z+1)
  73.                 MsgBox(0,"提示"," 账号: "&$a&" 密码: "&$b&" 保存成功 ")               
  74.                 GUICtrlSetData($Input1,"")
  75.                 GUICtrlSetData($Input2,"")
  76.                 GUICtrlSetData($Label4,$z+1)
  77.         EndIf        
  78. EndFunc  
复制代码
 楼主| 发表于 2010-1-8 22:54:57 | 显示全部楼层
回复 14# netegg

请教下怎么改!
发表于 2010-1-8 23:06:15 | 显示全部楼层
本帖最后由 netegg 于 2010-1-8 23:07 编辑

# $hListView = _GUICtrlListView_Create($GUI, "", 10, 10, 260, 150)
# GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

下面的消息子函数就可以用了
发表于 2010-1-8 23:08:10 | 显示全部楼层
你是想做成事件模式吧?
发表于 2010-1-8 23:13:21 | 显示全部楼层
刚看明白楼主什么意思,做函数前,把listview定义成全局变量Globle $listview,后面的操作再说后面的
 楼主| 发表于 2010-1-8 23:37:09 | 显示全部楼层
回复 18# netegg

不行耶
还是提示变量为定义!

如16代码那样
只要他不提示错误就行了!
 楼主| 发表于 2010-1-8 23:38:36 | 显示全部楼层
回复 19# 水木子


也不是什么事件
您的代码就是我想要的效果
只是我想把那一整段代码放在FUNC里

可能有多处要用到 !
但是一放FUNC里就出错!
FUNC又不能嵌套   麻烦就在这!
发表于 2010-1-8 23:45:25 | 显示全部楼层
没仔细看。。。
  1. #include <GuiListView.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <WindowsConstants.au3>

  4. Dim $ListView1, $dir, $z, $Label4, $Input1, $Input2
  5. _11()

  6. Func _11()
  7.         $dir = @ScriptDir & "\config.ini"
  8.         $Form1 = GUICreate("列表框操作", 280, 270)
  9.         GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
  10.         $ListView1 = GUICtrlCreateListView("账号           |密码           |", 10, 10, 260, 150)
  11.         $Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
  12.         $Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
  13.         $Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
  14.         $Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
  15.         $Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
  16.         $Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
  17.         $Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
  18.         GUISetState(@SW_SHOW)
  19.         Read()

  20.         While 1
  21.                 $nMsg = GUIGetMsg()
  22.                 Switch $nMsg
  23.                         Case $GUI_EVENT_CLOSE
  24.                                 Exit
  25.                         Case $Button1
  26.                                 tian()
  27.                 EndSwitch
  28.         WEnd
  29. EndFunc   ;==>_11


  30. Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)

  31.         Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
  32.         Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
  33.         If @error Then Return $GUI_RUNDEFMSG
  34.         $IDFrom = DllStructGetData($tagNMHDR, 2)
  35.         $Event = DllStructGetData($tagNMHDR, 3)
  36.         $tagNMHDR = 0
  37.         Switch $IDFrom;选择产生事件的控件

  38.                 Case $ListView1

  39.                         Switch $Event; 选择产生的事件

  40.                                 Case $NM_CLICK ; 左击
  41.                                         $a = _GUICtrlListView_GetSelectedIndices($ListView1)
  42.                                         $b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
  43.                                         $c = StringSplit($b, "|")
  44.                                         GUICtrlSetData($Input1, $c[1])
  45.                                         GUICtrlSetData($Input2, $c[2])
  46.                                 Case $NM_DBLCLK ; 双击

  47.                                 Case $NM_RCLICK ; 右击

  48.                         EndSwitch
  49.         EndSwitch
  50.         Return $GUI_RUNDEFMSG
  51. EndFunc   ;==>WM_NOTIFY

  52. Func Read()
  53.         $z = 0
  54.         _GUICtrlListView_DeleteAllItems($ListView1)
  55.         $read = IniReadSection($dir, "config")
  56.         If Not @error Then
  57.                 For $i = 1 To $read[0][0]
  58.                         GUICtrlCreateListViewItem($read[$i][0], $ListView1)
  59.                         _GUICtrlListView_AddSubItem($ListView1, $z, $read[$i][1], 1, $z + 1)
  60.                         GUICtrlSetData($Label4, $z + 1)
  61.                         $z += 1
  62.                 Next
  63.         EndIf
  64. EndFunc   ;==>Read

  65. Func tian()
  66.         $z = GUICtrlRead($Label4)
  67.         $a = GUICtrlRead($Input1)
  68.         $b = GUICtrlRead($Input2)
  69.         If $a <> "" And $b <> "" Then
  70.                 IniWrite($dir, "config", $a, $b)
  71.                 GUICtrlCreateListViewItem($a, $ListView1)
  72.                 _GUICtrlListView_AddSubItem($ListView1, $z, $b, 1, $z + 1)
  73.                 MsgBox(0, "提示", " 账号: " & $a & " 密码: " & $b & " 保存成功 ")
  74.                 GUICtrlSetData($Input1, "")
  75.                 GUICtrlSetData($Input2, "")
  76.                 GUICtrlSetData($Label4, $z + 1)
  77.         EndIf
  78. EndFunc   ;==>tian
复制代码
发表于 2010-1-9 01:42:07 | 显示全部楼层
本帖最后由 netegg 于 2010-1-9 01:44 编辑
回复  netegg

不行耶
还是提示变量为定义!

如16代码那样
只要他不提示错误就行了!
jscpu 发表于 2010-1-8 23:37

哪个变量未定义,不是有三个#include吗,下一行直接定义全局变量
把前面几位的代码里面dim改成global
发表于 2010-1-9 09:06:35 | 显示全部楼层
哎!简直没搞懂,基本靠猜。
发表于 2010-1-10 20:49:30 | 显示全部楼层
变量未声明
发表于 2010-1-11 09:56:45 | 显示全部楼层
回复 1# jscpu


1、根据选择的条目修改input的内容的方法,不建议楼主用检测鼠标点击操作的方法,那样既占资源(貌似),而且有出错的可能,更重要的是有一个最大的bug(就是鼠标点的时候,input可以根据所选内容进行修改,键盘上下键选的时候,input就傻了),解决这个问题我的方法,请参考【传送门】
2、提示变量不存在的问题,说明你没有好好看过au3的帮助,我引用一下au3的帮助里的原文:
变量的作用域
某个变量的作用域要看您是何时以及如何声明该变量的. 如果您在脚本开头且在所有函数之外声明了某个变量 则该变量将在Global(全局)范围内存在,此时您就可以在脚本的任意位置读取或更改该变量, 我们把这种变量称为全局变量.
如果您是在某个 函数 内部声明一个变量则该变量就只在该函数的 Local(局部) 范围内有效,我们把这种变量称为局部变量. 在函数内创建的变量将在函数结束时 自动被销毁.
在默认情况下,使用 Dim 声明的变量或在函数内部直接赋值而成的变量都是 Local(局部)变量,除非 有同名的全局变量存在(此时将视此变量为该全局变量).  另外我们可以使用关键字 Local 和 Global 来声明变量以 强制 变量的作用域.


所以你要解决这个问题,有两个方法,
一、把所有的全局变量都在func 外边声明,也就是说你就不要去想着把一段创建gui的代码用func包括起来了,除非你在这个func外边把所有的控件变量都提前声明一遍,但那样就绕弯路啦,相当于你写了两遍gui的代码。
二、如果你非要把创建gui的代码部分用func包括起来,那另外一个方法就是,在func里面创建控件的时候把变量声明为全局变量 Global
三、要说啥来着,忘了,回头想起来再说。刚明明想好了的,被同事打断了,工作了,不说了。、、
发表于 2010-1-15 09:00:16 | 显示全部楼层
可怜的水木子,费老大劲了,呵呵

建议楼主上传全部代码,光让猜怎么行啊,光看你的出错情况,应该是简单的逻辑问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2026-9-25 12:05 , Processed in 0.059244 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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