Jump to content

Solid Block Cursor in Input Fields


Recommended Posts

Thanks Yashied.

So the GUIRegisterMsg need to be located before the GUISetState...

And the GUICtrlSetState(-1, $GUI_FOCUS) is preventing the working...

That last one I don't understand why. Anyway many thanks for the solution.

And yes, hiding the mouse cursor is a nice idea! ^_^

See closely.

...
$input = GUICtrlCreateInput("", 10, 30, 500, 21, -1, 0)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0x00ff00)
;GUICtrlSetState(-1, $GUI_FOCUS)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND"); Set the Function
GUISetState()
...

EDIT: Use GUISetCursor(16) for better DOS emulation.

Link to comment
Share on other sites

Thanks Yashied.

So the GUIRegisterMsg need to be located before the GUISetState...

And the GUICtrlSetState(-1, $GUI_FOCUS) is preventing the working...

That last one I don't understand why. Anyway many thanks for the solution.

And yes, hiding the mouse cursor is a nice idea! ^_^

GUICtrlSetState(-1, $ GUI_FOCUS) generates a WM_COMMAND message before calling GUIRegisterMsg(). Then in your script, change of focus does not happen, and everything remains the same. Edited by Yashied
Link to comment
Share on other sites

There is just one thing I am unable to obtain, it is the position of the carret:

DllCall("User32.dll", 'int', 'SetCaretPos', 'int', $iCaretX, 'int', $iCaretY)

seems not willing to work. How to create an underscore instead of an upperscore?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>

Global $hBitmap, $h_WinMain, $hiddenbutton, $input, $iCaretW = 10, $iCaretH = 2, $iCaretX = 100, $iCaretY = 100

$h_WinMain = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetBkColor(0x000000, $h_WinMain)
GUISetFont(14, 400, 0, "DOSLike")
GUICtrlCreateLabel("AUTOIT-DOS 2009", 0, 0, 500, 20)
GUICtrlSetColor(-1, 0xffffff)
GUICtrlCreateLabel(">", 0, 30, 20, 20)
GUICtrlSetColor(-1, 0xffffff)

$hiddenbutton = GUICtrlCreateButton("OK", 260, 90, 100, 30, $BS_DEFPUSHBUTTON)
GUICtrlSetState(-1, $GUI_HIDE)

$input = GUICtrlCreateInput("", 10, 30, 500, 21, -1, 0)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0xffffff)


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND"); Set the Function
GUISetState()


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3, $GUI_EVENT_CLOSE
            Exit
        Case $hiddenbutton
            GUICtrlSetState($hiddenbutton, $GUI_FOCUS)
            GUICtrlCreateLabel("BAD COMMAND OR FILE NAME", 0, 60, 500, 20)
            GUICtrlSetColor(-1, 0xff0000)
            Sleep(1000)
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $hBitmap = "" Then $hBitmap = _WinAPI_CreateSolidBitmap(0, 0xffffff, $iCaretW, $iCaretH); color ori was 0x66FFFF
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode; Edit control event messages only
        Case $EN_SETFOCUS; Edit (Input) control has focus
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', -1); change the last value to -1 for immobile caret or to another value in milliseconds to change the blink rate (f.ex. 200)
            DllCall("User32.dll", 'int', 'SetCaretPos', 'int', $iCaretX, 'int', $iCaretY)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam)
        Case $EN_KILLFOCUS; Edit (Input) control lost focus
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            DllCall('user32.dll', 'int', 'DestroyCaret')
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Link to comment
Share on other sites

here's a command prompt simulation you could probably make look nicer

#include <GuiConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <GuiTab.au3>
#include <GuiStatusBar.au3>
#include <array.au3>
#include <Misc.au3>
#include <GDIPlusConstants.au3>

#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#include <ie.au3>


Global $Pau
Global $sav
HotKeySet('{del}',"back")
HotKeySet('{backspace}',"back") 
HotKeySet('{enter}',"cmds")

$Form1 = GUICreate("Test Cmd", 600, 600,@DesktopWidth/2, @DesktopHeight/2)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 599, 599)

GUICtrlSetData(-1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'&@CRLF& _
'Simulated Command Prompt'&@CRLF&'Copyright (c) blah blah'& _
'tes test All Rights Reserved.'&@CRLF&'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'&@CRLF&@CRLF&@CRLF&'MyPrompt>')

GUICtrlSetFont(-1, 10, 400, 0, "Lucida Console")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)
WinSetTrans($Form1,"",185)
GUISetState(@SW_SHOW)

Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)

While 1
    Sleep(10)
    _GUICTrlEdit_SetSel($Edit1, _GUICtrlEdit_GetTextLen($Edit1)+1, _GUICtrlEdit_GetTextLen($Edit1)+1)
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func close()
    _GUICtrlEdit_AppendText($Edit1,@CRLF&"Bye Bye   "&@UserName&"     "&@HOUR&":"&@MIN)
    timeout()
    for $p = 125 to 0 step -5
    sleep(10)
    WinSetTrans($form1,'',$p)
Next
exit
    EndFunc
    
    Func back()
    Local $sSel = _GUICtrlEdit_GetSel($Edit1)
    If $sSel[0] <= $sLastLine Then Return
    If $sSel[1] - $sSel[0] = 0 Then
        GUICtrlSetData($Edit1, StringTrimRight(GUICtrlRead($Edit1), 1))
    Else
        _GUICtrlEdit_ReplaceSel($Edit1, "")
    EndIf
EndFunc

Func cmds ()
    Local $sCmd = StringMid(GUICtrlRead($Edit1), $sLastLine+1)
    _GUICtrlEdit_BeginUpdate($Edit1)
    _GUICtrlEdit_EndUpdate($Edit1)
    Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)
    if $sCmd = "hello" then
            hello()
    ElseIf $sCmd = "note" then
        run('Notepad.exe')
    ElseIf $sCmd = "co" then
        exit 0
            ElseIf $sCmd = "?" then
        help()
    Else
        NoCom()
    EndIf
EndFunc

Func Hello()
        _GUICtrlEdit_AppendText($Edit1,@CRLF&"Hello World!")
        _GUICtrlEdit_AppendText($Edit1,@CRLF&"MyPrompt>")
Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)
EndFunc

Func NoCom()
    _GUICtrlEdit_AppendText($Edit1,@CRLF&"You didnt enter a proper command, Enter a ? to see a list off commands!")
    _GUICtrlEdit_AppendText($Edit1,@CRLF&"MyPrompt>")
Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)
EndFunc

Func help()
        _GUICtrlEdit_AppendText($Edit1,@CRLF&"Commands"&@CRLF&"Note - For Notepad"&@CRLF&"Hello - Flip Hellow World"&@CRLF&"Co - To close the program")
        _GUICtrlEdit_AppendText($Edit1,@CRLF&"MyPrompt>")
Global $sLastLine = _GUICtrlEdit_GetTextLen($Edit1)
EndFunc
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

But it does not solve my problem about the $iCaretX and $iCaretY ............

Looks like a timing issue, substituting with this version of func wm_command works for me
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $hBitmap = "" Then $hBitmap = _WinAPI_CreateSolidBitmap(0, 0xffffff, $iCaretW, $iCaretH); color ori was 0x66FFFF
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $nNotifyCode; Edit control event messages only
        Case $EN_SETFOCUS; Edit (Input) control has focus
            DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0)
            DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', 500); change the last value to -1 for immobile caret or to another value in milliseconds to change the blink rate (f.ex. 200)
            Sleep(10)
            DllCall("User32.dll", 'int', 'SetCaretPos', 'int', $iCaretX, 'int', $iCaretY)
            DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam)
        Case $EN_KILLFOCUS; Edit (Input) control lost focus
            DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            DllCall('user32.dll', 'int', 'DestroyCaret')
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
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...