Jump to content

Block input to GUICtrlCreateEdit()


Recommended Posts

I have a script that I just want to output log entries to, I guess similar to a Nullsoft Install Details Pane.

I have something that works, but is not pretty:

;GUI
$ptrGui = GuiCreate(@ScriptName & " - Log", 500, 700)
Global $ptrGUIList = GUICtrlCreateEdit("", 10, 10, 480, 650, BitOR($ES_READONLY, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_MULTILINE))
GUICtrlSetState($ptrGUIList, $GUI_DISABLE);stop from clicking in it
GUICtrlSetBkColor($ptrGUIList, 0xFFFFFF);white
$buttonExit = GUICtrlCreateButton("Start", 200, 670, 80, 20)
GUISetState(@SW_SHOW, $ptrGui)

Unfortunately, this still can be interrupted when you minimize the window and the text, being disabled, is a light gray and hard to read.

Does anyone know a better way to do this?

Link to comment
Share on other sites

Might want to look at http://www.autoitscript.com/forum/index.ph...st&p=358302 for the read-only and being able to set the color to any color you want.

I already have the box set as read only, but that does not prevent the user from clicking in the box and moving the cursor.

For example:

I am outputting a number every second, the box will look like this:

1

2

3

4

5

6

...

If the user just happens to click on the 2 after the 4th second, it will start filling in the box at the place they last clicked:

1

25

63

74

...

This is what I do not want.

Link to comment
Share on other sites

I already have the box set as read only, but that does not prevent the user from clicking in the box and moving the cursor.

I knew what you wanted but also you said:

Unfortunately, this still can be interrupted when you minimize the window and the text, being disabled, is a light gray and hard to read.

Does anyone know a better way to do this?

I was just showing you how to make it any color you want and still be read-only

As to stopping the user from clicking in the edit box and moving the caret, I believe this has been attempted many times, don't recall any sucessfull results.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I knew what you wanted but also you said:

I was just showing you how to make it any color you want and still be read-only

As to stopping the user from clicking in the edit box and moving the caret, I believe this has been attempted many times, don't recall any sucessfull results.

Correct, but I already had it white. But when you disable the text box, it fades the text to grey. The background is still white but even if you set the text to black after you disable it, it still stays faded.

The code at the top works to prevent users from screwing with it, the only real issue is the fading.

Edited by Shaun Burdick
Link to comment
Share on other sites

Correct, but I already had it white. But when you disable the text box, it fades the text to grey. The background is still white but even if you set the text to black after you disable it, it still stays faded.

The code at the top works to prevent users from screwing with it, the only real issue is the fading.

And did you try the link i gave? it doesn't fade when disabled.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

And did you try the link i gave? it doesn't fade when disabled.

I did read it...

I think you are confusing READONLY with DISABLED

Your script greys out if you add the disable code:

#include <GuiConstants.au3>

Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE = 0x300
Global Const $EN_SETFOCUS = 0x100
Global Const $EN_KILLFOCUS = 0x200
Global Const $DebugIt = 1
Global $changed = 0

GUICreate("My GUI combo")  ; will create a dialog box that when displayed is centered

$edit = GUICtrlCreateEdit("This is a test, this is only a test", 80, 50, 270, 170) ; create first item
$btn_exit = GUICtrlCreateButton("Exit", 40, 230, 60, 20)
$btn_readonly = GUICtrlCreateButton("Read-Only", 120, 230, 60, 20)
GUICtrlSetBkColor($edit, 0xFFFFFF)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $btn_exit
            ExitLoop
        Case $btn_readonly
            If GUICtrlRead($btn_readonly) == "Read-Only" Then
                GUICtrlSetData($btn_readonly, "Edit")
                GUICtrlSendMsg($edit, $EM_SETREADONLY, True, 0)
                GUICtrlSetState($edit, $GUI_DISABLE);stop from clicking in it
            Else
                GUICtrlSetData($btn_readonly, "Read-Only")
                GUICtrlSendMsg($edit, $EM_SETREADONLY, False, 0)
                GUICtrlSetState($edit, $GUI_ENABLE);stop from clicking in it
            EndIf
    EndSwitch
WEnd

Func _Edit_Changed()
    If $DebugIt Then _DebugPrint("Edit Changed:" & GUICtrlRead($edit))
    If $DebugIt Then _DebugPrint(StringLen(GUICtrlRead($edit)))
EndFunc   ;==>_Edit_Changed

Func _Edit_GotFocus()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("Edit Got Focus")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Edit_GotFocus

Func _Edit_LostFocus()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("Edit Lost Focus")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Edit_LostFocus

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam
   
    Switch $nID
        Case $edit
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Edit_Changed()
                Case $EN_SETFOCUS
                    _Edit_GotFocus()
                Case $EN_KILLFOCUS
                    _Edit_LostFocus()
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_Text, $line = @ScriptLineNumber, $file = @ScriptName) 
    ConsoleWrite( _
   "!===========================================================" & @LF & _
   "+======================================================" & @LF & _
   "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_Text & @LF & _
   "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord
Link to comment
Share on other sites

  • 10 months later...

I've been searching these forums for literally hours and I couldn't find a solution for this. And then a light bulb just turned on inside my head:

#include <GUIConstants.au3>

HotKeySet("^{end}","_Exit")

GUICreate("Blocked Editbox",200,110)
GUICtrlCreateLabel("Press Ctrl+End to exit",45,5)
$edit = GUICtrlCreateEdit("",10,20,180,80,$ES_AUTOVSCROLL+$WS_VSCROLL)
$cover = GUICtrlCreateLabel("",10,20,162,80) ; blocking the edit box!
GUICtrlSetState($cover,$GUI_ONTOP+$GUI_FOCUS)
GUISetState()
Dim $line

While 1
    $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
            Exit
        EndSelect   
    $line = $line + 123456 ;just an example of the text scrolling
    GUICtrlSetData($edit, $line & @CRLF, 1)
    Sleep(500)
WEnd

Func _Exit()
    Exit
Endfunc

So basically I just put a transparent label on top of the edit box, so now it's not possible to click it.

I feel pretty clever ;o

Edited by taq
Link to comment
Share on other sites

I've been searching these forums for literally hours and I couldn't find a solution for this. And then a light bulb just turned on inside my head:

#include <GUIConstants.au3>

HotKeySet("^{end}","_Exit")

GUICreate("Blocked Editbox",200,110)
GUICtrlCreateLabel("Press Ctrl+End to exit",45,5)
$edit = GUICtrlCreateEdit("",10,20,180,80,$ES_AUTOVSCROLL+$WS_VSCROLL)
$cover = GUICtrlCreateLabel("",10,20,162,80) ; blocking the edit box!
GUICtrlSetState($cover,$GUI_ONTOP+$GUI_FOCUS)
GUISetState()
Dim $line

While 1
    $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
            Exit
        EndSelect   
    $line = $line + 123456 ;just an example of the text scrolling
    GUICtrlSetData($edit, $line & @CRLF, 1)
    Sleep(500)
WEnd

Func _Exit()
    Exit
Endfunc

So basically I just put a transparent label on top of the edit box, so now it's not possible to click it.

I feel pretty clever ;o

Great idea! :)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...