Jump to content

Edit control with $ES_READONLY isn't read-only


tgftw
 Share

Recommended Posts

As the title says, I have an Edit control which should have $ES_READONLY applied on creation, as it is just being used for output of messages to the user, they shouldn't edit it.

However, it still allows the user to type in the box, even with the $ES_READONLY extended style.

I'll try to paste my code in a logical way, it's separated among several files.

; ----- /ra.au3 -----

#include "header/ra.h.au3"

$GUI = GUIInit() ; Initialize GUI

Nap(15000) ; Sleep for 15 seconds



; ----- /header/ra.h/au3 -----

#include-once ; Prevent multiple inclusion

#include "ra.function.h.au3" ; Include function header



; ----- /header/ra.function.h.au3 -----

#include-once ; Prevent multiple inclusion

#include "ra.function.GUIInit.h.au3" ; Include GUIInit() header
#include "ra.function.Nap.h.au3" ; Include Nap()



; ----- /header/ra.function.GUIInit.h.au3 -----

#include-once ; Prevent multiple inclusion
            
#include "ra.global.h.au3" ; Include global header

; Initialize GUI
Func GUIInit()
    $hWndGUI = GUICreate($sGUITitle, $iGUIWidth, $iGUIHeight, $iGUILeft, $iGUITop, $iGUIStyle, $iGUIExStyle) ; Create GUI window

    $idEdit = GUICtrlCreateEdit($sGUIEditText, $iGUIEditLeft, $iGUIEditTop, $iGUIEditWidth, $iGUIEditHeight, $iGUIEditStyle, $iGUIEditExStyle) ; Create Edit control

    GUISetState() ; Show GUI window
    
    Local $GUI[2] = [$hWndGUI, $idEdit] ; Store both values in an array
    
    Return $GUI ; Return window handle [0] and Edit control ID [1]
EndFunc



; ----- /header/ra.global.h.au3 -----

#include-once

#include <EditConstants.au3> ; Access GUI styles and extended styles
#include <WindowsConstants.au3> ; Access GUI event messages

$sScript =          "RA" ; Script name
$sAuthor =          "TGFTW" ; Author name

$iVersionMajor =    0 ; Major version number
$iVersionMinor =    1 ; Minor version number
$iVersionPatch =    0 ; Patch number
$iVersionBuild =    8 ; Build number

; Concatenate version number
$sVersion =          String($iVersionMajor) & "." & String($iVersionMinor) & "." & String($iVersionPatch) & "." & String($iVersionBuild)

; Concatenate title
$sGUITitle =        $sScript & " " & $sVersion & " by " & $sAuthor

$iGUIHeight =       238 ; Set GUI height
$iGUIWidth =        480 ; Set GUI width
$iGUILeft =         -1 ; Set GUI left margin, -1 is centered
$iGUITop =          -1 ; Set GUI top margin, -1 is centered

$iGUIStyle =        BitOR($WS_SYSMENU, $WS_MINIMIZEBOX) ; Set GUI style, use BitOR() for multiple
$iGUIExStyle =      $WS_EX_TOPMOST ; Set GUI extended style, use BitOR() for multiple


Local $sGUIEditText ; Declare Edit control text variable

; Set Edit control text
For $i = 1 To 13
    $sGUIEditText = $sGUIEditText & @CRLF ; Set 13 blank lines, to start at the bottom
Next

$iGUIEditLeft =     1   ; Set Edit control left margin
$iGUIEditTop =      1   ; Set Edit control top margin
$iGUIEditWidth =    472 ; Set Edit control width
$iGUIEditHeight =   207 ; Set Edit control height

$iGUIEditStyle =    -1 ; Set Edit control style, -1 is default
$iGUIEditExStyle =  $ES_READONLY ; Set Edit control extended style



; ----- /header/ra.function.Nap.h.au3 -----

#include-once

#include <GUIConstantsEx.au3> ; Access GUI styles and extended styles

; Sleep in short intervals to allow for GUI event message detection
Func Nap($iMilliseconds)
    $hTimer = TimerInit() ; Begin a timer to keep track of how long the function has been running
    
    ; If the function has been running less than $iMilliseconds milliseconds, keep looping
    While TimerDiff($hTimer) < $iMilliseconds
        ; Check for GUI event messages
        Switch(GUIGetMsg())
            Case $GUI_EVENT_CLOSE ; the Close button was pressed
                Exit ; Exit the script
        EndSwitch
    WEnd
EndFunc

Since it might be a little hard to follow, what's happening is /header/ra.global.h.au3 contains $iGUIEditExStyle = $ES_READONLY which is eventually passed to GUICtrlCreateEdit().

The resulting Edit control is not read-only, though.

Link to comment
Share on other sites

everything happens before GUIInit except for Nap(15000) - I'm sure it LOOKS like the includes are below, but they're actually in separate files.

EDIT: If it's easier to try and execute, I can just zip up the project.

Edited by tgftw
Link to comment
Share on other sites

Well that should've been obvious! I'm not sure why I thought it was an extended style. Thanks so much for the help :)

EDIT: FYI, all the includes are because this is going to be a very large script and it's my way of keeping organized and segmenting code into manageable pieces which are essentially all self-contained. But yeah, with how few actual functions I have and the lack of logic, it looks pretty arbitrary :)

Edited by tgftw
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...