Jump to content

User Formatted GUI Text Boxes


Recommended Posts

_GUICtrlEditSetSel

If anyone knows of an easier way to do this, please let me know... I don't like the idea of going to edit boxes.

Edit box and input box is the same kind of control.

SetSel and other messages is the way to go. GuiRegisterMsg WM_COMMAND message to catch EN_UPDATE notifications, and work with teh control from there, sending messages to it, EM_GETSEL, EM_SETSEL, EM_REPLACESEL, etc. Not sure if all of them are UDF-ed, although it doesn't really matter.

It should be doable, although it won't be very easy. Each action the user could possibly take has to be accounted for. Lets say, if the user types in non-digit chars, erase them; if the user types in third number after decimal point, erase it; if the user tries to erase decimal point, replace it (and possibly set selection to dollars); etc. etc...

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Edit box and input box is the same kind of control.

SetSel and other messages is the way to go. GuiRegisterMsg WM_COMMAND message to catch EN_UPDATE notifications, and work with teh control from there, sending messages to it, EM_GETSEL, EM_SETSEL, EM_REPLACESEL, etc. Not sure if all of them are UDF-ed, although it doesn't really matter.

It should be doable, although it won't be very easy. Each action the user could possibly take has to be accounted for. Lets say, if the user types in non-digit chars, erase them; if the user types in third number after decimal point, erase it; if the user tries to erase decimal point, replace it (and possibly set selection to dollars); etc. etc...

You lost me at EN_UPDATE, can you give a short example to work with?

Thanks for the help :)

Link to comment
Share on other sites

Ok, here's an example to build on...

#include <GUIConstants.au3>
#Include <GuiEdit.au3>

Global Const $WM_COMMAND = 0x0111

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 71, -1,-1)

$Input1 = GUICtrlCreateInput("$0.00", 64, 16, 153, 21)
_GUICtrlEditSetSel($Input1, 1, 2)

$btn = GUICtrlCreateButton("OK", 100, 45, 100, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input1
            ;
        Case $btn
            ;
        Case $GUI_EVENT_PRIMARYDOWN
            $aCursor = GUIGetCursorInfo()
            If $aCursor[4] = $input1 Then
                DllCall("user32.dll","int","ReleaseCapture")
                $aSel = _GUICtrlEditGetSel($Input1)
                If Not IsArray($aSel) Then ContinueCase
                ;if clicked behind dec point, select cents, else select dollars:
                ;(if double-clicked, selects cents):
                If $aSel[2] >= StringInStr(GUICtrlRead($Input1), ".") Then
                    _GUICtrlEditSetSel($Input1, StringInStr(GUICtrlRead($Input1), "."), StringLen(GUICtrlRead($Input1)))
                Else
                    _GUICtrlEditSetSel($Input1, 1, StringInStr(GUICtrlRead($Input1), ".")-1)
                EndIf
            EndIf
    EndSwitch
WEnd

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)
    $nID            = BitAnd($wParam, 0x0000FFFF)
    $hCtrl          = $lParam
    Switch $nNotifyCode
        Case 0x400 ;EN_UPDATE
            $aSel = _GUICtrlEditGetSel($Input1)
            If Not IsArray($aSel) Then Return $GUI_RUNDEFMSG
            $sChar = StringMid(GUICtrlRead($Input1), $aSel[2], 1)
            ConsoleWrite("User typed: " & $sChar & @CRLF)
        Case 0x100 ;EN_SETFOCUS
            ;
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Doesn't do any format checking yet, just reports what was typed. And also controls selection when user clicks on the control.

Edited by Siao

"be smart, drink your wine"

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