Jump to content

Clicking Issues


AlexTaitson
 Share

Recommended Posts

Hi, I'm new to AutoIt and I can say I'm loving it, but I got stuck with one problem...

I made my GUI, but for some reason, many times when I click a Button, it won't listen. I click it, it won't work... I click again, it won't work, but then I click and it works.

It might be a silly problem that you might figure just by looking, but through examples I couldn't see how to solve it.

Other thing I can't get to work is the X button on the top right, it won't close the program. I click it and nothing happens, no matter how many times I click it.

So far, the program is working if I click the many times for the buttons to listen, and that's what makes me think its not a syntax issue or nothing like that.

Can someone help me with this?

Here is the code so far:

(Its probably ugly to experts eyes xP but I'm learning...)

; AutoIt 3.0.103
; 09 Feb 2009 - Alexandre Taitson Moreira
; This script is a Printer driver installer

#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <AVIConstants.au3>
#include <String.au3>
#include <Inet.au3>

; GUI
GuiCreate("Tecnolta Installation Software", 400, 450)
GuiSetIcon(@ScriptDir & "\Imagens\icone2.JPG", 0)
GuiCtrlCreatePic(@ScriptDir & "\Imagens\Logo.JPG",50,0, 241,80)
GuiCtrlSetColor(-1,0xffffff)

; Variáveis
Global $Button1, $Button2, $Button3, $Button_driver, $Button_porta, $Button_del
Local $printerName, $inf, $porta, $ip, $driver

; MENU
GuiCtrlCreateMenu("Arquivo")
GuiCtrlCreateMenu("Sobre")

$driver = GUICtrlCreateCombo("Driver", 55, 103, 160, 20)
GUICtrlSetData($driver,"CC c118 WC m188 - m118i|Phaser 3200MFP|Phaser 6110|Phaser 8560|WC 5632-5638 - 5687|WC 5645-5655|WC 5665-5675-5687|WC 7232-7242|WC m20i|WC m123 - m128|BH 160|BH 210|BH 250|BH 350|BH 600|BH 750|BH 1050|BH c250|BH c500|BH Pro920|CF 3102")
GUISetState(@SW_SHOW)
GUICtrlCreateLabel("Porta: ", 220, 130)
$porta = GUICtrlCreateInput("", 260, 128, 100, 20)
GUICtrlCreateLabel("Inf File: ", 7, 130)
$inf = GuiCtrlCreateInput("", 55, 128, 160, 20)
GUICtrlCreateLabel("Nome: ", 220, 105)
$printerName = GUICtrlCreateInput("", 260, 103, 125, 20)
GUICtrlCreateLabel("Printers: ", 220, 155)
GUICtrlCreateInput("", 260, 153, 25, 20)

GuiCtrlCreateGroup("Versão do Windows", 7, 190, 180, 75)
GuiCtrlCreateRadio("Window 2000, XP, 2003", 27, 210, 145)
GuiCtrlSetState(-1, $GUI_CHECKED)
GuiCtrlCreateRadio("Windows Vista", 27, 230, 100)
GUICtrlCreateGroup ("",-99,-99,1,1) ;close group

; DATE
GuiCtrlCreateLabel("(Date control expands into a calendar)", 7, 380, 200, 20)
GuiCtrlCreateDate("", 7, 400, 200, 20)

; BUTTON
$Button1 = GuiCtrlCreateButton("Salvar", 220, 330, 150, 50, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", 7)
$Button_del = GuiCtrlCreateButton("Deletar", 220, 382, 150, 40, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", 32)
$Button2 = GuiCtrlCreateButton("Instalar", 10, 330, 100, 30)
$Button3 = GuiCtrlCreateButton("Cancelar", 112, 330, 100, 30)
$Button_driver = GUICtrlCreateButton("Driver: ", 4, 99, 40, 28, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", 23)
$Button_porta = GUICtrlCreateButton("Criar Portas", 295, 153, 65, 20)

; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
        
    Case $Button1
        $read_input = GUICtrlRead($printerName)
        $read_input2 = GUICtrlRead($inf)
        $read_input3 = GUICtrlRead($porta)
        $read_input4 = GUICtrlRead($driver)
        FileWrite("Impressora.bat", "rundll32 printui.dll,PrintUIEntry /if /b """&$read_input&""" /f """&$read_input2&""" /r """&$read_input3&""" /m """&$read_input4&"""");Escrever o arquivo Batch que instalará a impressora
        ExitLoop
    EndSwitch
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button2
        run("E:\GUI\Printer\Impressora.bat")
        ExitLoop
    EndSwitch
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button_del
            If FileExists("Impressora.bat") Then
                FileDelete("Impressora.bat")
            ElseIf
                MsgBox(2,"Ação inválida","Arquivo Inexistente")
            EndIf
        ExitLoop
    EndSwitch
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button_driver
        $SelectedText = GUICtrlRead($driver)
        If $SelectedText = "Driver" Then
            MsgBox(1,"Erro de Parâmetros", "Driver inválido")
        EndIf
        If $SelectedText = "CC c118 WC m188 - m118i" Then
            FileDelete("Impressora.bat")
            GUICtrlSetData($inf, "E:\GUI\Drivers\Xerox3200MFP\Driver\ps3200.INF")
            GUICtrlSetData($driver, "Xerox Phaser 3200MFP PCL 6")
            GUICtrlSetData($printerName, "Phaser 3200MFP(1)")   
        EndIf
        If $SelectedText = "Phaser 3200MFP" Then
            FileDelete("Impressora.bat")
            GUICtrlSetData($inf, "E:\GUI\Drivers\XeroxPhaser3200MFP\ps3200.INF")
            GUICtrlSetData($driver, "Xerox Phaser 3200MFP PCL 6")
            GUICtrlSetData($printerName, "Phaser 3200MFP(1)")
        EndIf
        If $SelectedText = "Phaser 6110" Then
            FileDelete("Impressora.bat")
            GUICtrlSetData($inf, "E:\GUI\Drivers\XeroxPhaser6110MFP\xrxi1.inf")
            GUICtrlSetData($driver, "Xerox Phaser 6110MFP")
            GUICtrlSetData($printerName, "Phaser 6110MFP(1)")
        EndIf
        If $SelectedText = "Phaser 8560" Then
            FileDelete("Impressora.bat")
            GUICtrlSetData($inf, "E:\GUI\Drivers\XeroxPhaser6110MFP\xrxi1.inf")
            GUICtrlSetData($driver, "Xerox Phaser 6110MFP")
            GUICtrlSetData($printerName, "Phaser 6110MFP(1)")
        EndIf
        If $SelectedText = "WC 5632-5638 - 5687" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "WC 5645-5655" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "WC 5665-5675-5687" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "WC 7232-7242" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "WC m20i" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "WC m123 - m128" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 160" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 210" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 250" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 250" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 350" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 600" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 750" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH 1050" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH c250" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH c500" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "BH Pro920" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        If $SelectedText = "CF 3102" Then
            GUICtrlSetData($inf, $SelectedText)
        EndIf
        ExitLoop
    EndSwitch
WEnd
    
WEnd

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
Link to comment
Share on other sites

  • Moderators

AlexTaitson,

Your [X] does not work because you have nothing in the Case statement to tell it what to do. Make it read like this:

Case $GUI_EVENT_CLOSE
        Exit

and it will work.

You need to look at the Switch syntax in the Help file more closely. You do not need all those loops! Look at this (based on your code):

While 1
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ConsoleWrite("Button 1 pressed" & @CRLF)
        Case $Button2
            ConsoleWrite("Button 2 pressed" & @CRLF)
        Case $Button3
            ConsoleWrite("Button 3 pressed" & @CRLF)
        Case $Button_del
            ConsoleWrite("Button Del pressed" & @CRLF)
        Case $Button_driver
            ConsoleWrite("Button Driver pressed" & @CRLF)
    EndSwitch
  
WEnd

See how much cleaner it looks? Your problem was the number of times you called GUIGetMsg - your button presses were being lost because you kept overwriting $nMsg. You only need to call GUIGetMsg once and then run the necessary Cases against it. All these work for me - try it and see!

Ask again if you have problems or do not understand something.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...