找回密码
 加入
搜索
查看: 3348|回复: 12

[AU3基础] 已经解决 按钮切换

  [复制链接]
发表于 2010-4-27 19:38:14 | 显示全部楼层 |阅读模式
本帖最后由 fugq0fff 于 2010-4-29 18:33 编辑

While 1
If ProcessExists("notepad.exe")  Then
$Button1 = GUICtrlCreateButton("关闭", 0, 0, 97, 33)
GUICtrlSetBkColor(-1, 0xFF0000)
Sleep(1000)
Else
$Button2 = GUICtrlCreateButton("启动", 0, 0, 97, 33)
EndIf
WEnd
我想让程序启动后就不断的检测 指定的程序有没有在工作 例如 notepad.exe 如果没有就跳到 启动 如果已经启动就会跳到 关闭
可是他总是在启动和关闭之间跳来跳去  不知道怎么办
 楼主| 发表于 2010-4-27 22:14:42 | 显示全部楼层
请 高手帮帮忙啊  先谢谢了
发表于 2010-4-28 00:20:01 | 显示全部楼层
If ... Then
    ...
    Exit
Else
    ...
    Exit
EndIf

你这条件无论怎样都exit了
 楼主| 发表于 2010-4-28 00:27:18 | 显示全部楼层
不好意思 我这个exit有去了  可是他在启动和关闭之间总是跳来跳去  不知道有没有好的方法  请 版主 帮忙一下
发表于 2010-4-28 00:31:29 | 显示全部楼层
好像是死循环。。。。。
发表于 2010-4-28 00:50:57 | 显示全部楼层
本帖最后由 afan 于 2010-4-28 00:53 编辑

没有完整代码和意图,这段仅为猜测
不需要循环
$Button1 = GUICtrlCreateButton("关闭", 0, 0, 97, 33)
If Not ProcessExists("notepad.exe") Then GUICtrlSetState(-1, $GUI_HIDE)
$Button2 = GUICtrlCreateButton("启动", 0, 0, 97, 33)
If ProcessExists("notepad.exe") Then GUICtrlSetState(-1, $GUI_HIDE)
发表于 2010-4-28 05:46:42 | 显示全部楼层

评分

参与人数 1金钱 -10 收起 理由
afan -10 警告,禁止纯表情!

查看全部评分

发表于 2010-4-28 09:37:00 | 显示全部楼层
不大理解楼主的意思,只能猜一下了
        If Not ProcessExists("notepad.exe") Then 
                If MsgBox(4,0,"进程不存在"&@CRLF&"想创建记事本吗?")=6 Then 
                        ShellExecute("Notepad.exe")
                EndIf
        Else
                If MsgBox(4,0,"进程存在"&@CRLF&"想关闭记事本吗?")=6 Then
                        $PID = ProcessExists("notepad.exe") 
                        If $PID Then ProcessClose($PID)                        
                EndIf
        EndIf
发表于 2010-4-28 17:44:21 | 显示全部楼层
写循环时要特别小心,否则容易出错。。
 楼主| 发表于 2010-4-29 14:56:28 | 显示全部楼层
自己  顶上去

评分

参与人数 1金钱 -10 收起 理由
afan -10 无意义

查看全部评分

发表于 2010-4-29 16:30:16 | 显示全部楼层
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 100, 50, 192, 114)
$Button1 = GUICtrlCreateButton("MyButton", 0, 0, 97, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        If ProcessExists("notepad.exe")  Then 
                If GUICtrlRead($Button1)<>"关闭" Then
                        GUICtrlSetData($Button1,"关闭")
                        GUICtrlSetBkColor($Button1, 0xFF0000)
                        Sleep(1000)
                EndIf
        Else
                If GUICtrlRead($Button1)<>"启动" Then
                        GUICtrlSetData($Button1,"启动")
                        GUICtrlSetBkColor($Button1, 0x00FF00)
                        Sleep(1000)
                EndIf
        EndIf
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If GUICtrlRead($Button1)="启动" Then
                                Run("notepad.exe")
                        ElseIf GUICtrlRead($Button1)="关闭" Then
                                ProcessClose("notepad.exe")
                        EndIf
        EndSwitch
WEnd
不知道我猜对了楼主的意思了没。 斗胆给个代码。
发表于 2010-4-29 17:16:33 | 显示全部楼层
强烈建议在学习编程之前把基础语文学好
 楼主| 发表于 2010-4-29 17:58:17 | 显示全部楼层
本帖最后由 fugq0fff 于 2010-4-29 18:32 编辑
不知道我猜对了楼主的意思了没。 斗胆给个代码。
lanfengc 发表于 2010-4-29 16:30

谢谢你的代码  已经好了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-19 00:25 , Processed in 0.114800 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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