Jump to content

How do I get a string to write to a gui window?


Recommended Posts

When I compile and this I get a window that wont allow me to close or press any buttons. When I open the program I want to see a decrypted string from temp.ini in the GUI window. Can anyone help?

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=stringencrypt example.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <guiconstants.au3>
#include <string.au3>
; GUI and String stuff
$WinMain = GuiCreate('Encryption tool', 400, 400); (Name of Window, Width, Height)
; Creates window
$EditText = GuiCtrlCreateEdit('',5,5,390,350); (Name if object, offset from top, offset from side, Width, Height)
; Creates main edit
$Apply_Changes = GuiCtrlCreateButton('Apply Changes', 63, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
; Encryption button
$Exit = GuiCtrlCreateButton('Exit', 231, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
; Decryption button

; Simple text labels so you know what is what
GuiSetState()
; Shows window

Local $temp_encrypted
Local $Decrypted_Data
Local $GuiGetMsg
    FileOpen("temp.ini", 0); calls the file temp.ini for reading later
;Check if file opened for writing OK
        If $temp_encrypted = -1 Then
            MsgBox(0, "Error", "Cant find temp.ini.")
            Exit
        EndIf
    $temp_encrypted = FileRead("temp.ini"); reads temp.txt and assigns the data to $file
    GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
    $string = GuiCtrlRead($EditText); Saves the editbox for later
    GUICtrlSetData($EditText,'Please wait while the text is Encrypted/Decrypted.'); Friendly message
    GuiCtrlSetData($EditText,_StringEncrypt(0,$string,GuiCtrlRead(1234))); decrypts the data and displays it in the textbox

While 1
$msg = $GuiGetMsg()
    Switch $msg
        Case $Apply_Changes
            GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
            $string = GuiCtrlRead($EditText); Saves the editbox for later
            GUICtrlSetData($EditText,'Please wait while the text is Encrypted/Decrypted.'); Friendly message
            GuiCtrlSetData($EditText,_StringEncrypt(1,$string,GuiCtrlRead(1234))); Encrypts the data in the textbox
            FileOpen("temp.ini", 2);opens the file in write mode (it will create the file if it doesn't exist)
            FileWrite("temp.ini", $Decrypted_Data); writes the data to temp.ini
            FileClose("temp.ini");closes the file
            GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on
        Case $Exit
            Exit
    EndSwitch
Wend
Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

When I compile and this I get a window that wont allow me to close or press any buttons. When I open the program I want to see a decrypted string from temp.ini in the GUI window. Can anyone help?

GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
Do you think disabling the window before going into your message loop is a good idea...?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I figure that if there is a lot of data that needs to be decrypted during start up that it cant be interrupted if the user wants to start entering data. That's not the problem though. As you see a few lines down I re-enable the window. I will however try to remove that and see what happens.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

I figure that if there is a lot of data that needs to be decrypted during start up that it cant be interrupted if the user wants to start entering data. That's not the problem though. As you see a few lines down I re-enable the window. I will however try to remove that and see what happens.

No, I don't see you re-enable the window a few lines down. Four lines after you disable it with the line I quoted, you go into the While/WEnd loop, where the only thing that enables the GUI is inside a Switch Case activated by $Apply_changes, which you never get because you disabled the window...

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I have a Question about GUICtrlCreateEdit()

I Need to put many Words in it ... However it looks like it got limits ... I cant put more than some certain number of characters ... I think thats about 30,000 characters ... not exactly sure about that number ...

Anyway , any Suggestion on how I can do and add as many line as I want in an Edit window ... Iam trying to make a Gui that looks similar to the Help menu ... you know it ... a Tree View in the left hand side ... and whenever you click an list there , the opposite Edit window will show the topic with unlimited amount of characters ....

Thanx in advance :)

.

Edited by hussert
Link to comment
Share on other sites

I have a Question about GUICtrlCreateEdit()

I Need to put many Words in it ... However it looks like it got limits ... I cant put more than some certain number of characters ... I think thats about 30,000 characters ... not exactly sure about that number ...

Anyway , any Suggestion on how I can do and add as many line as I want in an Edit window ... Iam trying to make a Gui that looks similar to the Help menu ... you know it ... a Tree View in the left hand side ... and whenever you click an list there , the opposite Edit window will show the topic with unlimited amount of characters ....

Thanx in advance :)

.

@hussert: Start your own topic for your own issue. Don't hijack other people's topics!

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Sorry this thing is a work in progress. Here's the current code:

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=stringencrypt example.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <guiconstants.au3>
#include <string.au3>
$WinMain = GuiCreate('Encryption tool', 400, 400); (Name of Window, Width, Height)
$EditText = GuiCtrlCreateEdit('',5,5,390,350); (Name if object, offset from top, offset from side, Width, Height)
$Apply_Changes = GuiCtrlCreateButton('Apply Changes', 63, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
$Exit = GuiCtrlCreateButton('Exit', 231, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
GuiSetState()
Local $temp_encrypted
Local $Decrypted_Data
Local $Encrypted_Data
Local $GuiGetMsg
    FileOpen("temp.ini", 0); calls the file temp.ini for reading later
;Check if file opened for writing OK
        If $temp_encrypted = -1 Then
            MsgBox(0, "Error", "Cant find temp.ini.")
            Exit
        EndIf
    $temp_encrypted = FileRead("temp.ini"); reads temp.ini and assigns the data to $temp_encrypted -tested
;   GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
;   $string = GuiCtrlRead($EditText); Saves the editbox for later
    GUICtrlSetData($EditText,'Please wait while the text is Encrypted/Decrypted.'); Friendly message
    GuiCtrlSetData($EditText,_StringEncrypt(0,$temp_encrypted,GUICtrlRead(1234))); decrypts the data and displays it in the textbox
;   GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on 
While 1
$msg = $GuiGetMsg()
    Switch $msg
        Case $Apply_Changes
;           GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
            $string = GuiCtrlRead($EditText); Saves the editbox for later
            GUICtrlSetData($EditText,'Please wait while the text is Encrypted/Decrypted.'); Friendly message
            GuiCtrlSetData($EditText,_StringEncrypt(1,$string,GuiCtrlRead(1234))); Encrypts the data in the textbox
            FileOpen("temp.ini", 2);opens the file in write mode (it will create the file if it doesn't exist)
            FileWrite("temp.ini", $Encrypted_Data); writes the data to temp.ini
            FileClose("temp.ini");closes the file
;           GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Wend
Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Sorry this thing is a work in progress. Here's the current code:

Cleaned up:
#include <guiconstants.au3>
#include <string.au3>

Local $temp_encrypted
Local $Decrypted_Data
Local $Encrypted_Data
Local $GuiGetMsg

$WinMain = GUICreate('Encryption tool', 400, 400); (Name of Window, Width, Height)
$EditText = GUICtrlCreateEdit('', 5, 5, 390, 350); (Name if object, offset from top, offset from side, Width, Height)
$Apply_Changes = GUICtrlCreateButton('Apply Changes', 63, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
$Exit = GUICtrlCreateButton('Exit', 231, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
GUISetState()

FileOpen("temp.ini", 0); calls the file temp.ini for reading later
If $temp_encrypted = -1 Then
    MsgBox(0, "Error", "Cant find temp.ini.")
    Exit
EndIf
$temp_encrypted = FileRead("temp.ini"); reads temp.ini and assigns the data to $temp_encrypted -tested
GUICtrlSetData($EditText, 'Please wait while the text is Encrypted/Decrypted.'); Friendly message
GUICtrlSetData($EditText, _StringEncrypt(0, $temp_encrypted, GUICtrlRead(1234))); decrypts the data and displays it in the textbox

While 1
    $msg = $GuiGetMsg()
    Switch $msg
        Case $Apply_Changes
            $string = GUICtrlRead($EditText); Saves the editbox for later
            GUICtrlSetData($EditText, 'Please wait while the text is Encrypted/Decrypted.'); Friendly message
            GUICtrlSetData($EditText, _StringEncrypt(1, $string, GUICtrlRead(1234))); Encrypts the data in the textbox
            FileOpen("temp.ini", 2);opens the file in write mode (it will create the file if it doesn't exist)
            FileWrite("temp.ini", $Encrypted_Data); writes the data to temp.ini
            FileClose("temp.ini");closes the file
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

What's up with the "GUICtrlRead(1234)"? Where did 1234 come from? Aside from that, does it respond to the buttons now?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

1234 is the password for the encryption. I dont need it to be extremely hard to guess but I did want encryption on the ini file.

I think the problem is in this line:

GuiCtrlSetData($EditText,_StringEncrypt(0,$temp_encrypted,GUICtrlRead(1234),GuiCtrlRead(1))); decrypts the data and displays it in the textbox

Can anyone elaborate?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

1234 is the password for the encryption. I dont need it to be extremely hard to guess but I did want encryption on the ini file.

I think the problem is in this line:

GuiCtrlSetData($EditText,_StringEncrypt(0,$temp_encrypted,GUICtrlRead(1234),GuiCtrlRead(1))); decrypts the data and displays it in the textbox

Can anyone elaborate?

GuiCtrlRead() takes the Control ID of a GUI control as its input. "1234" is likely not a valid Control ID, so you are getting 0 (Failure) back from GuiCtrlRead() there.

It's possible "1" is a valid Control ID, but it is very bad practice to use it literally, since it can change so easily and might not point to the control you think it does. That makes it likely you are getting an invalid result from GuiCtrlRead(1) also.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

OK one last thing. Here's my working code so far:

#include <guiconstants.au3>
#include <string.au3>
$WinMain = GuiCreate('Encryption tool', 400, 400); (Name of Window, Width, Height)
$EditText = GuiCtrlCreateEdit('',5,5,390,350); (Name if object, offset from top, offset from side, Width, Height)
$Apply_Changes = GuiCtrlCreateButton('Apply Changes', 63, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
$Exit = GuiCtrlCreateButton('Exit', 231, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)

GuiSetState()
Local $temp_encrypted
Local $Decrypted_Data
Local $Encrypted_Data
;Local $GuiGetMsg
    FileOpen("temp.ini", 1); calls the file temp.ini for reading later
;Check if file opened for writing OK
        If $temp_encrypted = -1 Then
            MsgBox(0, "Error", "Cant find temp.ini.")
            Exit
        EndIf
    $temp_encrypted = FileRead("temp.ini"); reads temp.ini and assigns the data to $temp_encrypted -tested
    $Decrypted_Data = _StringEncrypt(0,$temp_encrypted,"1234","1"); decrypts the string "$file" - Tested
    FileClose("temp.ini")
    GUICtrlSetData($EditText,$Decrypted_Data); decrypts the data and displays it in the textbox
;Perfect thus far
While 1
   $Msg = GuiGetMsg()
    Switch $Msg
        Case $Apply_Changes
;           GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
            $Encrypted_Data = _StringEncrypt(1,$Decrypted_Data,"1234","1"); Encrypts the data
            FileOpen("temp.ini",2)
            FileWrite("temp.ini", $Encrypted_Data); writes the data to temp.ini
            FileClose("temp.ini");closes the file
;           GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Wend

When I open the program now I get the unencrypted data from temp.ini and I can add stuff to the text window but when I hit 'apply changes' it doesn't write the newly encrypted data to the temp.ini file. What is the problem?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

OK one last thing. Here's my working code so far:

;Perfect thus far
While 1
   $Msg = GuiGetMsg()
    Switch $Msg
        Case $Apply_Changes
;           GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
            $Encrypted_Data = _StringEncrypt(1,$Decrypted_Data,"1234","1"); Encrypts the data
            FileOpen("temp.ini",2)
            FileWrite("temp.ini", $Encrypted_Data); writes the data to temp.ini
            FileClose("temp.ini");closes the file
;           GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Wend

When I open the program now I get the unencrypted data from temp.ini and I can add stuff to the text window but when I hit 'apply changes' it doesn't write the newly encrypted data to the temp.ini file. What is the problem?

You can use functions like FileRead() and FileWrite() without first opening the file, by giving a string for the path\file. You can also open the file first in an appropriate mode, saving the handle to the open file, and passing the handle instead of the string path\file.

Don't mix the two. If you open the file with FileOpen(), then save the handle and use that for your file operations until you FileClose() the handle:

$sFile = "temp.ini"; path\file name
            $hFile = FileOpen($sFile, 2); 2 = overwrite
            FileWrite($hFile, $Encrypted_Data); writes the data to temp.ini
            FileClose($hFile); closes the file

From the help file under FileRead():

Remarks

If a filename is given rather than a file handle - the file will be opened and closed during the function call - for parsing large text files this will be much slower than using filehandles.

Note: Do not mix filehandles and filenames, i.e., don't FileOpen a file and then use a filename in this function. Use either filehandles or filenames in your routines, not both!

:) Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

And the final code is:

#include <guiconstants.au3>
#include <string.au3>
$WinMain = GuiCreate('Encryption tool', 400, 400); (Name of Window, Width, Height)
$EditText = GuiCtrlCreateEdit('',5,5,390,350); (Name if object, offset from top, offset from side, Width, Height)
$Apply_Changes = GuiCtrlCreateButton('Apply Changes', 63, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
$Exit = GuiCtrlCreateButton('Exit', 231, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)

GuiSetState()
$sFile = (@ScriptDir & "\" & "temp.ini"); path\file name
$Encryption_String = ("1234")
$Encryption_Level = ("1")
Local $temp_encrypted
Local $Decrypted_Data
Local $Encrypted_Data
Local $Gui_Info
FileOpen($sFile,0); calls the file temp.ini for reading later
;Check if file opened for writing OK
        If $sFile = -1 Then
            MsgBox(0, "Error", "Cant find temp.ini.")
            Exit
        EndIf
    $temp_encrypted = FileRead($sFile); reads temp.ini and assigns the data to $temp_encrypted -tested
    $Decrypted_Data = _StringEncrypt(0,$temp_encrypted,$Encryption_String,$Encryption_Level); decrypts the string "$file" - Tested
    FileClose($sFile)
    GUICtrlSetData($EditText,$Decrypted_Data); displays decrypted data in the textbox
;Perfect thus far
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Apply_Changes
;           GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
            $Gui_Info = GuiCtrlRead($EditText)
            $Encrypted_Data = _StringEncrypt(1,$Gui_Info,$Encryption_String,$Encryption_Level); Encrypts the data
            $hFile = FileOpen($sFile, 2)
            FileWrite($hFile, $Encrypted_Data); writes the data to temp.ini
            FileClose($hFile)
;           GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Wend

Thanks a lot Psalty! Works great.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

$Encryption_String = ("1234")

$Encryption_Level = ("1")

better use :

$Encryption_String = "1234"

$Encryption_Level = 1 ; but default level is already defined as 1, so no need to redefine it !

Local $temp_encrypted

Local $Decrypted_Data

Local $Encrypted_Data

Local $Gui_Info

the "Local" declaration is wrong here since local should only be declared within a "function" , you define a local variable in a global context !

so better use "global" or "DIM"

FileOpen($sFile,0); calls the file temp.ini for reading later

;Check if file opened for writing OK

If $sFile = -1 Then

MsgBox(0, "Error", "Cant find temp.ini.")

Exit

EndIf

$temp_encrypted = FileRead($sFile); reads temp.ini and assigns the data to $temp_encrypted -tested

$Decrypted_Data = _StringEncrypt(0,$temp_encrypted,$Encryption_String,$Encryption_Level); decrypts the string "$file" - Tested

FileClose($sFile)

you mix file-handle and file-names !!

better

$filehandle = FileOpen($sFile,0);

If $filehandle = -1 Then

please read the help fle on the fileopen / fileread / filewrite topic

PS : you are still not finished with your little barcode script ?

Edited by nobbe
Link to comment
Share on other sites

OK then, Final code beta 2! Why so harsh? I am doing it as fast as I can with 5 children and a customer that keeps making changes to the program. Geez!

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=stringencrypt example.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <guiconstants.au3>
#include <string.au3>
Global $temp_encrypted
Global $Decrypted_Data
Global $Encrypted_Data
Global $Gui_Info
Global $filehandle
$WinMain = GuiCreate('Encryption tool', 400, 400); (Name of Window, Width, Height)
$EditText = GuiCtrlCreateEdit('',5,5,390,350); (Name if object, offset from top, offset from side, Width, Height)
$Apply_Changes = GuiCtrlCreateButton('Apply Changes', 63, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)
$Exit = GuiCtrlCreateButton('Exit', 231, 360, 105, 35); (Name on button, Offset from left, offset from top, Width, Height)

GuiSetState()
$sFile = (@ScriptDir & "\" & "temp.ini"); path\file name
$Encryption_String = "1234"
$filehandle = FileOpen($sFile,0);
; calls the file temp.ini for reading later
;Check if file opened for writing OK
        If $filehandle = -1 Then
            MsgBox(0, "Error", "Cant find temp.ini.")
            Exit
        EndIf
    $temp_encrypted = FileRead($sFile); reads temp.ini and assigns the data to $temp_encrypted -tested
    $Decrypted_Data = _StringEncrypt(0,$temp_encrypted,$Encryption_String); decrypts the string "$file" - Tested
    FileClose($sFile)
    GUICtrlSetData($EditText,$Decrypted_Data); displays decrypted data in the textbox
;Perfect thus far
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Apply_Changes
;           GuiSetState(@SW_DISABLE,$WinMain); Stops you from changing anything
            $Gui_Info = GuiCtrlRead($EditText)
            $Encrypted_Data = _StringEncrypt(1,$Gui_Info,$Encryption_String); Encrypts the data
            $hFile = FileOpen($sFile, 2)
            FileWrite($hFile, $Encrypted_Data); writes the data to temp.ini
            FileClose($hFile)
;           GuiSetState(@SW_ENABLE,$WinMain); This turns the window back on
        Case $Exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
Wend

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

i assume your code works, but only due to a little inconsistent implementation of "fileread()"

so please change

FileClose($sFile)

to

FileClose($filehandle)

$temp_encrypted = FileRead($sFile)

to

$temp_encrypted = FileRead($filehandle)

PS: i wasnt meant to be _harsh_, i was just wondering ..

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