Jump to content

Recommended Posts

Posted (edited)

So, made a pretty form with buttons with the Koda FD tool. Worked spectacularly until we decided to have the script learn the CD drive letter so we could call items directly off the disc with the resulting variable.

grabbed @Mhz's .au3 (http://www.msfn.org/board/autoit-find-drive-letter-virtualclonedrive-t44991-pid-312233.html&view=findpost)

That piece works nicely; however, when combined with the form it renders the buttons un-clickable. You can still tab down and hit enter and it will execute, but left clicking the boxes does nada.

#AutoIt3Wrapper_Icon=app.ico
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <AviConstants.au3>


;Find CDROM variable
$CD1 = _FindCD("STA_Rollup.exe", 0)


;FindCD function

Func _FindCD($name, $option)
; e.g. _FindCD('Setup.exe', 0) or _FindCD('CD Title', 1)
; $option: 0 = Filename in CD Root; 1 = CD title
Local $cddrive
While Not $cddrive
$drvs = DriveGetDrive('CDROM')
If Not @error Then
For $i = 1 To $drvs[0]
If DriveStatus($drvs[$i] & '\') = 'READY' Then
If $option = 0 Then
If FileExists($drvs[$i] & '\' & $name) Then
$cddrive = $drvs[$i]
Return $cddrive
EndIf
ElseIf $option = 1 Then
$cddrive = $drvs[$i]
If DriveGetLabel($cddrive) = $name Then
Return $cddrive
EndIf
EndIf
EndIf
Next
If Not $cddrive Then
If MsgBox(21, 'Warning', 'Please insert CD into a drive now') = 2 Then
Sleep(1000)
If MsgBox(36, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
EndIf
Sleep(2000)
EndIf
EndIf
WEnd
EndFunc


Dircreate ("C:\Temp1\")
fileinstall ("sta2.ico" , "c:\temp1\" , 1)
fileinstall ("combosmall.bmp" , "c:\temp1\" , 1)

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("STA Rollup", 653, 251, 194, 132)
GUISetFont(8, 800, 4, "Times New Roman")
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("c:\temp1\combosmall.bmp", 0, -6, 652, 256)
$grpSa = GUICtrlCreateGroup("SA", 8, 80, 273, 161)
$btnSam1205 = GUICtrlCreateButton("12.05 WS", 80, 96, 123, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Edited by iamtheky

Posted

Hi iamtheky,

I tested your script by changing _FindCD() to search for autorun.inf on a CD for my convenience. I also added a small message loop to get the signal from a button press and show a msgbox with some details. I do not see an issue with button operation using my added message loop. (The variable $drvs should be made Local to _FindCD() as well just in case the variable is used Globally by mistake.)

This is the change to the _FindCD() I changed

$CD1 = _FindCD("autorun.inf", 0)

and this is the message loop that I added to the bottom of your script. Button "12.05 WS" is tested.

Do
$msg = GUIGetMsg()
If $msg = $btnSamsE1205 Then; 12.05 WS button signal
MsgBox(0, @ScriptName, _
'I am "' & @ScriptName & '"' & @CRLF & _
'I am located in "' & @ScriptDir & '"' & @CRLF & _
'My working directory is "' & @WorkingDir & '"' & @CRLF & _
'The full path to me is "' & @ScriptFullPath & '"' & @CRLF & _
'The drive that I am in is "' & StringLeft(@ScriptDir, 2) & '"' & @CRLF & @CRLF & _
'The value of $CD1 is "' & $CD1 & '"' _
, 0, $Form1_1 _
)
EndIf
Until $msg = -3; window close signal

I noticed that your script searches for "STAMIS_Rollup.exe" and the title of the GUI is "STAMIS Rollup". If the script resides on the CD that you want to access and the file structure to access is on the CD then you can just use the @Script* macros to complete the full paths around the file structure on the CD or just use relative paths from the location of your script. If you are going to open a text file then you could build the full path by using @ScriptDir as shown below.

ShellExecute(@ScriptDir & '\readme.txt')

If the script file is one directory level up then you can do this by using "..".

ShellExecute(@ScriptDir & '\..\readme.txt')

To use relative paths, ensure the script has a known working directory such as @ScriptDir. To set the working directory is done with FileChangeDir() as shown below.

If @WorkingDir <> @ScriptDir Then
FileChangeDir(@ScriptDir)
EndIf

Comparing @WorkingDir to @ScriptDir is optional as you could just use FileChangeDir(@ScriptDir) only. These are just simple examples.

You could do use FileChangeDir() at the top of your script to set the working directory for the rest of your script to use. With the working directory set, then you can use relative paths from your script directory as shown below.

ShellExecute('readme.txt')

If the script file is one directory level up then you can do this by using "..".

ShellExecute('..\readme.txt')

Hopefully enough information for you to decide on possibly fixing/improving your script.

Posted

Thats a fantastic amount of information. Your functioning examples will probably prove more fruitful than an explanation of why mine was behaving poorly.

Thank you sir. I will reply with results.

Posted (edited)

It was the image I had as the background. :no:

apparently it was in front of the buttons, but I could still bring focus with tab blue border (and execute with enter key). but the shifting of the blue border to gray was not it responding to clicked on, but rather the left click of the mouse anywhere in the form giving focus back to the image. This behavior was peculiar because eventhough the image had the focus the buttons would remain on top.

I am glad I had the issue though as your reply has given us hope for scaling down the au3 and making it a little more user-friendly.

Edited by iamtheky

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
  • Recently Browsing   0 members

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