Jump to content

Select Case Problem


Recommended Posts

Hi there,

first of all one sentence to introduce myself. My Nick is Zetup-EXE and i use AutoIt for programming simple Shells for WinPE.

Anyway, i encountered a problem with the Select Case statement. Maybe some of you know this either *hopefully*, or could help me to see the forest because of many trees :D

Ok, here's the Problem:

I have a GUI, with serveral Buttons and a Contextmenu. Each item (button and contextmenu entry) have it's own global variable. after generating the gui, i jump to the "controlfunction", which looks like this:

func control()

while 1

$maingui_msg = guigetmsg()

Select

Case $maingui_msg = $button0

if fileexists (%path to executable%) then

run (%path to executable%)

endif

Case $maingui_msg = $button1

....and so on...

.

.

.

Case $maingui_msg = $contextmenu_entry14

.

.

.

Case Else

sleep (100)

EndSelect

Endfunc

Overall there are aprox. 30 entries within this function. and allways after the gui is displayed on the screen the an event (when the program was launched) from the select case statement is immediatly executed although no button was pressed by an user.

does anybody know about this problem.

thx.

Zetup-EXe

P.s.: I know i should upload an example, but i forget this on my working computer. but maybe someone knows this problem and can help me out of this. if it's necessary i can upload the sources tomorrow. cu..

Link to comment
Share on other sites

  • Moderators

ZetupEXE,

The default GUIGetMsg return is 0. Do you have anything in your Switch which might be set to 0 - or perhaps a non-defined variable which would be interpreted as 0? If so - there is your answer, as it would trigger as soon as you enter your loop.

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

Wow, your responses are quite fast! thx. a lot.

@Manadar: will post the source tomorrow (Central European Time).

@Melba23: checked the variables again and again, no mistake found. i also set the value $maingui_msg=0 just before entering the loop, with no luck. but, well i forgot to mention before, what is really strange is this:

within the gui i have $button0 to $button5. allways when the program is launched the action i.e. 4 (which means $button3) is executed. but when i reversed the last 3 buttons like this $button0,..., $button2, button5, button4, button3 then button5 is executed. strange isn't it?

cu...

Zetup-EXE

Link to comment
Share on other sites

  • Moderators

ZetupEXE,

i also set the value $maingui_msg=0 just before entering the loop

That may not help solve the problem as the value is immediately reset by your $maingui_msg = guigetmsg() line.

Perhaps you might like to try setting $maingui_msg to 0 before the While...WEnd loop and removing that GUIGetMsg line to see if anything in your loop reacts on that value.

But best to post your code - there must be an answer because, as Manadar said, Select works!

See you tomorrow - a demain - bis morgen.

M23

Edited by Melba23

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

Good morning,

well, first of all i would like to thank you for your fast and patient. I found the mistake accidentally by myself. Here is a snipset of my script:

Func mainGUI($menucall)

Local $maingui_bckpic = @SystemDir & "\winpe.bmp"

Local $bckpic_state1

$maingui = GuiCreate("HauptGUI", 1, 1, 0, 0, $WS_POPUP + $WS_VISIBLE + $DS_SETFOREGROUND)

WinSetTrans ("HauptGUI", "", 0)

GUISetBkColor(0xFFFFFF, $maingui)

;WinMove ("HauptGUI", "", 0, 0, 1024, 768)

WinMove ("HauptGUI", "", 0, 0, @DesktopWidth, @DesktopHeight)

;$bckpic_state1 = GUICtrlCreatePic ($maingui_bckpic, 0, 0, 1024, 768)

$bckpic_state1 = GUICtrlCreatePic ($maingui_bckpic, 0, 0, @DesktopWidth, @DesktopHeight)

guiFade("HauptGUI", "In", 255, 255)

GUICtrlSetState ($bckpic_state1, $GUI_DISABLE)

$activewindow="HauptGUI"

GUISetState (@SW_SHOW)

Sleep (100)

GUIDelete ($passwordgui) <--- THIS caused the script not to function properly!!!

Select

Case $menucall=0

adminShortcut()

shortcutControls()

Case Else

Sleep (500)

EndSelect

EndFunc

; Shortcut-GUI (Erstellt die Shortcut-Buttons auf der HauptGUI)

Func adminShortcut()

Local $maingui_size = WinGetClientSize ("HauptGUI") ;Ermittelt die Grösse der Haupt-GUI

Local $x_cord = Round ($maingui_size[0]*0.5, -1)

Local $y_cord = Round ($maingui_size[1]*0.5, -1)

$button0 = GUICtrlCreateButton ("", $x_cord*1.800, $y_cord*1.500, 24, 24, $BS_ICON)

GUICtrlSetImage ($button0, @SystemDir & "\wlrmdr.exe", 0, 0)

GUICtrlSetTip ($button0, "Computer sperren")

$button1 = GUICtrlCreateButton ("", $x_cord*1.800, $y_cord*1.500+30, 24, 24, $BS_ICON)

GUICtrlSetImage ($button1, @SystemDir & "\shell32.dll", -239, 0)

GUICtrlSetTip ($button1, "Neu starten")

$button2 = GUICtrlCreateButton ("", $x_cord*1.800, $y_cord*1.500+60, 24, 24, $BS_ICON)

GUICtrlSetImage ($button2, @SystemDir & "\imageres.dll", -93, 0)

GUICtrlSetTip ($button2, "Herunterfahren")

$button5 = GUICtrlCreateButton ("", $x_cord*0.220+60, $y_cord*1.392, 24, 24, $BS_ICON)

GUICtrlSetImage ($button5, @SystemDir & "\cmd.exe", 0, 0)

GUICtrlSetTip ($button5, "Eingabeaufforderung")

$button4 = GUICtrlCreateButton ("", $x_cord*0.220+30, $y_cord*1.392, 24, 24, $BS_ICON)

GUICtrlSetImage ($button4, @SystemDir & "\networkexplorer.dll", 0, 0)

GUICtrlSetTip ($button4, "Netzwerk starten und Netzlaufwerke verbinden")

$button3 = GUICtrlCreateButton ("", $x_cord*0.220, $y_cord*1.392, 24, 24, $BS_ICON)

GUICtrlSetImage ($button3, @WindowsDir & "\explorer.exe", 0, 0)

GUICtrlSetTip ($button3, "Q-Dir - Explorer")

;################ Kontextmenu ################

$contextmenu = GUICtrlCreateContextMenu()

$prgmenu = GUICtrlCreateMenu ("Programme", $contextmenu)

$prg_fileexp = GUICtrlCreateMenuItem ("Q-Dir - Explorer", $prgmenu)

$prg_copy = GUICtrlCreateMenuItem ("FastCopy", $prgmenu)

$prg_seperator1 = GUICtrlCreateMenuItem ("", $prgmenu)

$imageprgm = GUICtrlCreateMenu ("Imaging", $prgmenu)

$prg_imagex = GUICtrlCreateMenuItem ("ImageX", $imageprgm)

$prg_ghost = GUICtrlCreateMenuItem ("Ghost", $imageprgm)

$prg_snapshot = GUICtrlCreateMenuItem ("Drive Snapshot", $imageprgm)

;$prg_seperator2 = GUICtrlCreateMenuItem ("", $prgmenu)

$nicmenu = GUICtrlCreateMenu ("Netzwerk", $contextmenu)

$nic_network = GUICtrlCreateMenuItem ("Netzwerk starten", $nicmenu)

$nic_rdp = GUICtrlCreateMenuItem ("Remotedesktopverbindung", $nicmenu)

$nic_vnc = GUICtrlCreateMenuItem ("Vncviewer", $nicmenu)

$toolsmenu = GUICtrlCreateMenu ("Tools", $contextmenu)

$tool_defrag = GUICtrlCreateMenuItem ("Defragmentieren", $toolsmenu)

$tool_mbrutil = GUICtrlCreateMenuItem ("MBR Utility", $toolsmenu)

$tool_drvinj = GUICtrlCreateMenuItem ("DriverInjection", $toolsmenu)

$tool_seperator = GUICtrlCreateMenuItem ("", $toolsmenu)

$rcvrytoolm = GUICtrlCreateMenu ("Recovery", $toolsmenu)

$rcvrytestdisk = GUICtrlCreateMenuItem ("Testdisk", $rcvrytoolm)

$rcvryphotorec = GUICtrlCreateMenuItem ("Photorec", $rcvrytoolm)

$systemmenu = GUICtrlCreateMenu ("System", $contextmenu)

$system_cmd = GUICtrlCreateMenuItem ("Eingabeaufforderung", $systemmenu)

;$system_regedt = GUICtrlCreateMenuItem ("Registrierungs-Editor", $systemmenu)

$system_udev = GUICtrlCreateMenuItem ("Hardware PCI\VEN-IDs", $systemmenu)

$sys_seperator1 = GUICtrlCreateMenuItem ("", $systemmenu)

$system_taskmgr = GUICtrlCreateMenuItem ("Taskmanager", $systemmenu)

$cnt_seperator1 = GUICtrlCreateMenuItem ("", $contextmenu)

$helpmenu = GUICtrlCreateMenu ("?", $contextmenu)

$help_about = GUICtrlCreateMenuItem ("Über...", $helpmenu)

;##############################################

EndFunc

Func shortcutControls()

GUIDelete($desktoplockgui) <--- Moved to this position, and all worked fine!!!

GUISwitch ($maingui)

HotKeySet ("!{TAB}")

HotKeySet ("{Enter}")

Sleep (100)

While 1

$maingui_msg = GUIGetMsg()

Select

Case $maingui_msg = 0

Sleep (100)

Case $maingui_msg = $button0

desktopLock(192, 192)

passwordGUI(255, 255)

Case $maingui_msg = $button1

If FileExists (@SystemDir & "\wpeutil.exe") Then

desktopLock(255, 255)

Run (@SystemDir & "\wpeutil.exe Reboot", "", @SW_HIDE)

Sleep (10000)

Exit

EndIf

Case $maingui_msg = $button2

If FileExists (@SystemDir & "\wpeutil.exe") Then

desktopLock(255, 255)

Run (@SystemDir & "\wpeutil.exe Shutdown", "", @SW_HIDE)

Sleep (10000)

Exit

EndIf

Case $maingui_msg = $button3

If FileExists (@ProgramFilesDir & "\Q-DIR\Q-DIR.EXE") Then

Run (@ProgramFilesDir & "\Q-DIR\Q-DIR.EXE")

EndIf

Case $maingui_msg = $button4

If FileExists (@ProgramFilesDir & "\PENETCFG\PENETCFG.EXE") Then

Run (@ProgramFilesDir & "\PENETCFG\PENETCFG.EXE")

EndIf

Case $maingui_msg = $button5

If FileExists (@SystemDir & "\CMD.EXE") Then

Run (@SystemDir & "\CMD.EXE")

EndIf

Case $maingui_msg = $prg_fileexp

If FileExists (@ProgramFilesDir & "\Q-DIR\Q-DIR.EXE") Then

Run (@ProgramFilesDir & "\Q-DIR\Q-DIR.EXE")

EndIf

Case $maingui_msg = $prg_imagex

If FileExists (@ProgramFilesDir & "\IMAGEX\GIMAGEX.EXE") Then

Run (@ProgramFilesDir & "\IMAGEX\GIMAGEX.EXE")

EndIf

...

EndSelect

EndFunc

thx.

cu..

Zetup-EXE

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...