pbecks1963 Posted March 18, 2010 Share Posted March 18, 2010 (edited) Hello y'all, I have a this script: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST)) GUICtrlCreatePic("Enquete.bmp", 0, 0, @DesktopWidth, @DesktopHeight) GUISetState() ; Set filenames $file_to_write = @ScriptDir & "\InquiryAnswers.txt" $file_to_read = @ScriptDir & "\InquiryQuestions.txt" ; open file to read and store the handle $handle_read = FileOpen($file_to_read, 0) ; open file to Write and store the handle $handle_write = FileOpen($file_to_write, 1); append mode ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 ; Set or Reset array for this set of answers Local $aAnswers[1] = [0] ; Loop through each line of the file to get the questions While 1 ; read each line from a file - starting at 1 for each pass If $aAnswers[0] = 0 Then $line_read = FileReadLine($handle_read, 1) Else $line_read = FileReadLine($handle_read) EndIf ; exit the loop if end of file If @error = -1 Then ExitLoop ; get answer to question $answer = _Get_Answer($line_read) ; Increase count $aAnswers[0] += 1 ; Increase array size ReDim $aAnswers[$aAnswers[0] + 1] ; Save answer $aAnswers[$aAnswers[0]] = $answer WEnd ; Collect answers $sAllAnswers = "" For $i = 1 To $aAnswers[0] - 1 $sAllAnswers &= $aAnswers[$i] & "," Next $sAllAnswers &= $aAnswers[$i] FileWriteLine($handle_write, $sAllAnswers) ; Write file MsgBox(0, "", "Thank you!",2) WEnd ; close the file handle for read FileClose($handle_read) ; close the file handle for write FileClose($handle_write) Exit Func _Get_Answer($sQuestion) $hGUI = GUICreate("Questions", 700, 180, Default, Default, BitOR($WS_CAPTION, $WS_POPUP), $WS_EX_TOPMOST) GUISetFont(24, Default, Default, "MS Comic Sans") GUICtrlCreateLabel($sQuestion, 10, 10, 700, 40) $hInput = GUICtrlCreateInput("", 10, 60, 650, 40) $hOK_Button = GUICtrlCreateButton("OK", 10, 120, 120, 50) GUISetState() While 1 Switch GUIGetMsg() Case $hOK_Button $sAnswer = GUICtrlRead($hInput) GUIDelete($hGUI) Return $sAnswer EndSwitch WEnd EndFunc ;==>_Get_Answer What it does is show a window with a question and get the answer to that question. This is looped (in the rest of the script) until the end of the file (which holds the questions) is reached. HOWEVER, every time a new question is asked, the window isn't active (i have to click with the left mouse button on the window to get it active) and the OK-button needs to be clicked (in stead of a plain <ENTER> which i prefer) in order to go to the next question. How can i change this? ps: i noticed that when i remove lines 5, 6 and 7 the popup windows are always active! But i need this background pic to be displayed ALl the time.. howwww....??? Edited March 18, 2010 by pbecks1963 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 18, 2010 Moderators Share Posted March 18, 2010 pbecks1963,To ensure your input has focus, add a line to set the focus to it when the GUI is displayed.If you want to use Enter to terminate the data input, use an Accelerator key.Look for the <<<<<<<<<<<<<<<<< lines:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> GUICreate('MyGUI', @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST)) GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\facepalm.jpg", 0, 0, @DesktopWidth, @DesktopHeight) GUISetState() ; Set filenames $file_to_write = @ScriptDir & "\InquiryAnswers.txt" $file_to_read = @ScriptDir & "\InquiryQuestions.txt" ; open file to read and store the handle $handle_read = FileOpen($file_to_read, 0) ; open file to Write and store the handle $handle_write = FileOpen($file_to_write, 1); append mode While 1 ; Set or Reset array for this set of answers Local $aAnswers[1] = [0] ; Loop through each line of the file to get the questions While 1 ; read each line from a file - starting at 1 for each pass If $aAnswers[0] = 0 Then $line_read = FileReadLine($handle_read, 1) Else $line_read = FileReadLine($handle_read) EndIf ; exit the loop if end of file If @error = -1 Then ExitLoop ; get answer to question $answer = _Get_Answer($line_read) ; Increase count $aAnswers[0] += 1 ; Increase array size ReDim $aAnswers[$aAnswers[0] + 1] ; Save answer $aAnswers[$aAnswers[0]] = $answer WEnd ; Collect answers $sAllAnswers = "" For $i = 1 To $aAnswers[0] - 1 $sAllAnswers &= $aAnswers[$i] & "," Next $sAllAnswers &= $aAnswers[$i] FileWriteLine($handle_write, $sAllAnswers) ; Write file If MsgBox(4, "", "Thank you!" & @CRLF & @CRLF & "Do you want to exit?") = 6 Then Exit ; <<<<<<<<<<<<<<<<<<<<<<<<<< WEnd ; close the file handle for read FileClose($handle_read) ; close the file handle for write FileClose($handle_write) Exit Func _Get_Answer($sQuestion) $hGUI = GUICreate("Questions", 700, 180, Default, Default, BitOR($WS_CAPTION, $WS_POPUP), $WS_EX_TOPMOST) GUISetFont(24, Default, Default, "MS Comic Sans") GUICtrlCreateLabel($sQuestion, 10, 10, 700, 40) $hInput = GUICtrlCreateInput("", 10, 60, 650, 40) $hOK_Button = GUICtrlCreateButton("OK", 10, 120, 120, 50) ; Set accelerators for Enter <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Dim $AccelKeys[1][2]=[["{ENTER}", $hOK_Button]] GUISetAccelerators($AccelKeys) GUISetState() _WinAPI_SetFocus(GUICtrlGetHandle($hInput)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Set focus to input While 1 Switch GUIGetMsg() Case $hOK_Button $sAnswer = GUICtrlRead($hInput) GUIDelete($hGUI) Return $sAnswer EndSwitch WEnd EndFunc ;==>_Get_AnswerI also amended your MsgBox so you can exit gracefully. Forcing people to use Task Manager to stop the script because you have made a full screen app with no exit code will not win you many friends. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
pbecks1963 Posted March 18, 2010 Author Share Posted March 18, 2010 (edited) Thank you! ps: I don't want people to be able to exit bacause then we would have to start this survey/inquiry again and again. This script runs on 2 dedicated pc's (with no or little human assistance) and at the end of the day I terminate the script and collect the data. (import it as csv in Excel) Edited March 18, 2010 by pbecks1963 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now