Sign in to follow this  
Followers 0
SLK001

Deleting Picture Causes Script To Be Nonfunctional

4 posts in this topic

I created the script below using GUIBuilder. The order that I placed the individual components was:

1) Placed combo box

2) Placed Button 1

3) Placed Button 2

4) Placed picture ($Pic_1)

5) Placed label ($Label_1)

I got everything organized that way I wanted it, compiled it and everything worked okay. However, the application that was using this GUI had problems with my original picture in that it couldn't properly display it. So I commented out the "$Pic_1 = GuiCtrlCreatePic("\Splash.bmp", 0, 0, 410, 80)" command. While it did remove the picture, it also may all the data for the combo box disappear. The only way that I could get the combo box back was to put the picture back in.

Can someone tell me what is wrong with this code that would corrupt the combo box data like this?

Also, if I move the command "$Label_1 = GuiCtrlCreateLabel("What do you want the computer to do?", 75, 95, 200, 20) " to just above the "$Combo_1 = GuiCtrlCreateCombo("", 75, 120, 260, 100)" statement, everything is again all screwed up.

Can someone shed some light on these issues for me? I'm new to this syntax, so I wouldn't be surprised if there

were quite a few errors in this script.

Thanks,

Steve

; Script generated by AutoBuilder 0.6 Prototype

#Compiler_Icon = Icons\SML_COMP.ico
#include <D:\Program Files\AutoIt3\Include\GuiConstants.au3>
FileInstall("D:\Program Files\AutoIt3\Include\SPLASH.bmp","\Splash.bmp")
;FileInstall("peshuteject.exe","\peshuteject.exe")

GuiCreate("Shut Down BartPE Session", 410, 240,-1,-1)
GUISetIcon("icons\SML_COMP.ico")
;WinSetOnTop("Shut Down BartPE Session", "", 1);Puts window always on top.
;$1="Eject - Wait 5 Seconds - Close Door - Restart"
;$2="Eject - Wait 5 Seconds - Close Door - Shutdown"
$3="Eject - Restart"
$4="Eject - Shut Down"
$5="Restart"
$6="Shut Down"

          
$Pic_1 = GuiCtrlCreatePic("\Splash.bmp", 0, 0, 410, 80)



$Combo_1 = GuiCtrlCreateCombo("", 75, 120, 260, 100);,$CBS_DROPDOWNLIST)
      ;GUICtrlSetData(4,$2)
       GUICtrlSetData(4,$3)
       GUICtrlSetData(4,$4)
       GUICtrlSetData(4,$5)
       GUICtrlSetData(4,$6,$3)
       
$Button_2 = GuiCtrlCreateButton("OK", 240, 205, 70, 22)
$Button_3 = GuiCtrlCreateButton("Cancel", 325, 205, 70, 22)


$Label_1 = GuiCtrlCreateLabel("What do you want the computer to do?", 75, 95, 200, 20)
$Pic_2 = GUICtrlCreatePic("icons\BIG_COMP.bmp", 120, 40, 50, 50); $SS_BITMAP)

GuiSetState()
Do
   $msg = GuiGetMsg()
   If $msg=$Button_3 Then Exit
   If $msg=$GUI_EVENT_CLOSE Then Exit
   
Until $msg=$Button_2 


If GUICtrlRead(4)=$3 Then
  ;Run("\peshuteject.exe /reboot /eject:X","",@SW_HIDE)
   MsgBox(0,"Results",$3,10)
   Exit
EndIf

If GUICtrlRead(4)=$4 Then
  ;Run("\peshuteject.exe /shutdown /eject:X","",@SW_HIDE)
   MsgBox(0,"Results",$4,10)
   Exit 
EndIf

If GUICtrlRead(4)=$5 Then
  ;Run("\peshuteject.exe /reboot","",@SW_HIDE)
   MsgBox(0,"Results",$5,10)
   Exit
EndIf

If GUICtrlRead(4)=$6 Then
  ;Run("\peshuteject.exe /shutdown","",@SW_HIDE)
   MsgBox(0,"Results",$6,10)
   Exit     
EndIf

Exit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Not sure why it's happening, but your if then endif section would be better served with a select case endselect structure.

Select
   Case GUICtrlRead(4)=$3
;Run("\peshuteject.exe /reboot /eject:X","",@SW_HIDE)
      MsgBox(0,"Results",$3,10)
      Exit
   Case GUICtrlRead(4)=$4 
;Run("\peshuteject.exe /shutdown /eject:X","",@SW_HIDE)
      MsgBox(0,"Results",$4,10)
      Exit  
   Case GUICtrlRead(4)=$5
;Run("\peshuteject.exe /reboot","",@SW_HIDE)
      MsgBox(0,"Results",$5,10)
      Exit
   Case GUICtrlRead(4)=$6
;Run("\peshuteject.exe /shutdown","",@SW_HIDE)
      MsgBox(0,"Results",$6,10)
      Exit      
EndSelect

Let me insert a block of code I developed that works just fine in my GUI application.

$btnStart = GUICtrlCreateButton("Start &Camp", ($guiWidth / 2) - ($guiTemp[2]), $guiTemp[1], $guiTemp[2], $guiTemp[3], BitOR($GUI_SS_DEFAULT_BUTTON, $BS_DEFPUSHBUTTON))
$guiTemp = ControlGetPos($frmMainGUI, "", $btnStart)
$btnExit = GUICtrlCreateButton("E&xit", $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1], $guiTemp[2], $guiTemp[3])
; image/label creation
If FileExists($imgLocation & "clicktop.gif") And FileExists($imgLocation & "clickright.gif") _
        And FileExists($imgLocation & "clickbottom.gif") And FileExists($imgLocation & "clickleft.gif") Then
; if the images are found, use them.
    $imgFiles = 1
    $guiTemp = ControlGetPos($frmMainGUI, "", $rbtnGroup02)
    $imgClickZone[1] = GUICtrlCreatePic($imgLocation & "clicktop.gif", $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    $imgClickZone[2] = GUICtrlCreatePic($imgLocation & "clickright.gif", $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    $imgClickZone[3] = GUICtrlCreatePic($imgLocation & "clickbottom.gif", $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    $imgClickZone[4] = GUICtrlCreatePic($imgLocation & "clickleft.gif", $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    For $x = 1 To 4
        GUICtrlSetState($imgClickZone[$x], $GUI_HIDE)
        If GUICtrlRead($rbtnClickZone[$x]) = $GUI_CHECKED Then GUICtrlSetState($imgClickZone[$x], $GUI_SHOW)
    Next
Else
; otherwise, use text labels
    $guiTemp = ControlGetPos($frmMainGUI, "", $rbtnGroup02)
    $lblClickZone[1] = GUICtrlCreateLabel("The script will send a single left click in the top area of the monitor, 30 pixels from the edge, avoiding a 30x30 pixel square at the corners.", _
            $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    $lblClickZone[2] = GUICtrlCreateLabel("The script will send a single left click in the right area of the monitor, 30 pixels from the edge, avoiding a 30x30 pixel square at the corners.", _
            $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    $lblClickZone[3] = GUICtrlCreateLabel("The script will send a single left click in the bottom area of the monitor, 30 pixels from the edge, avoiding a 30x30 pixel square at the corners." & @LF & "NOT RECOMMENDED", _
            $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    $lblClickZone[4] = GUICtrlCreateLabel("The script will send a single left click in the left area of the monitor, 30 pixels from the edge, avoiding a 30x30 pixel square at the corners.", _
            $guiTemp[0] + $guiTemp[2] + 10, $guiTemp[1] + 12, 136, 96)
    For $x = 1 To 4
        GUICtrlSetState($lblClickZone[$x], $GUI_HIDE)
        If GUICtrlRead($rbtnClickZone[$x]) = $GUI_CHECKED Then GUICtrlSetState($lblClickZone[$x], $GUI_SHOW)
    Next
EndIf

If I comment out the first section of the if/then or the images don't exist, I don't have a problem since I'm creating a text label for the same place. Also, if I comment the whole block out and use no labels or graphics, I still have no problem with my other GUI elements.

Keep in mind, I don't use a program to build my GUIs. Everything is laid out by hand. Though it's a wonderful program, you just don't get the same control with it versus actually building the GUI with raw code.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$Combo_1 = GuiCtrlCreateCombo("", 75, 120, 260, 100);,$CBS_DROPDOWNLIST)
     ;GUICtrlSetData(4,$2)
       GUICtrlSetData(4,$3)
       GUICtrlSetData(4,$4)
       GUICtrlSetData(4,$5)
       GUICtrlSetData(4,$6,$3)

You're setting the data for the combo wrong:

it should be GUICtrlSetData(CtrlID,data)

and you have a CtrlID Called '4'????

try

$Combo_1 = GuiCtrlCreateCombo("", 75, 120, 260, 100);,$CBS_DROPDOWNLIST)
       GUICtrlSetData($Combo_1,$3)
       GUICtrlSetData($Combo_1,$4)
       GUICtrlSetData($Combo_1,$5)

HardCopy

Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Hardcopy,

Thanks, your suggestion worked. I had used Au3Info.exe to find the number of the control. I see that while it might have worked, the number of the control actually changes depending on the order of items in your script.

Chalk one up for "lessons learned"!

Share this post


Link to post
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
Sign in to follow this  
Followers 0