Sign in to follow this  
Followers 0
Zohar

When in a TextBox(Edit), How to Check If the Cursor is LTR or RTL?

7 posts in this topic

#1 ·  Posted (edited)

Hello

On Windows that has another language installed, which is a RightToLeft Language,

The user can press Alt-Shift, to Toggle between English and the other, RTL language.

My question is,

I I am now on a TextBox, for example in Notepad's EDIT control,

How can I check If the cursor is for writing english, or for writing a RTL language?

Thank you

Edited by Zohar

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It looks from MSDN like the parent window receives a WM_COMMAND with EN_ALIGN_LTR_EC when it is changed to LTR, and EN_ALIGN_RTL_EC for a change to RTL.

That implies you should be able to make the change by sending a message, but I didn't find exactly what that was.

B)

Hmm... saw some references to using GetWindowLog (which would be _WinAPI_GetWindowLong($hEdit, $GWL_EXSTYLE) in AutoIt) and then testing for the bit WS_EX_LAYOUTRTL. But I haven't found the declaration for which bit that would be yet.

;)

Aha! Found it in MSDN: 0x400000

And it's in WindowsConstants.au3 include file. Here's a demo:

#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Opt("GuiOnEventMode", 1)

Global $fRTL = False
Global $hGUI = GUICreate("Test", 300, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

Global $ctrlEdit_1 = GUICtrlCreateEdit("", 20, 20, 260, 100)
Global $hEdit_1 = GUICtrlGetHandle($ctrlEdit_1)
Global $ctrlButton_1 = GUICtrlCreateButton("Toggle RTL", 100, 150, 100, 30)
GUICtrlSetOnEvent(-1, "_ToggleRTL")
GUISetState()

Sleep(1000)
ControlSetText($hGUI, "", $ctrlEdit_1, "Testing... how about that?" & @CRLF)

While 1
    Sleep(10)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _ToggleRTL()
    $fRTL = Not $fRTL
    $iExStyle = _WinAPI_GetWindowLong($hEdit_1, $GWL_EXSTYLE)
    If $fRTL Then
        $iExStyle = BitOR($iExStyle, $WS_EX_LAYOUTRTL)
    Else
        $iExStyle = BitAND($iExStyle, BitNOT($WS_EX_LAYOUTRTL))
    EndIf
    ControlSetText($hGUI, "", $ctrlEdit_1, "")
    _WinAPI_SetWindowLong($hEdit_1, $GWL_EXSTYLE, $iExStyle)
    ControlFocus($hGUI, "", $ctrlEdit_1)
    ControlSend($hGUI, "", $ctrlEdit_1, "Testing... how about that?" & @CRLF)
EndFunc   ;==>_ToggleRTL

I learned something today. Not bad for a Monday!

:)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hello PsaltyDS!

Your code is very cool, I like it:)

I should clarify one thing tho:

There's a difference between Alt-Shift and Ctrl-Shift.

The code you created, is doing the functionality that you would get by Ctrl-Shift, which is changing the TextAlignment(Left/Right).

Alt-Shift however, does another thing.

Alt-Shift does not change the alignment,

but it changes the Cursor's Direction, and most importantly the Cursor's Output Language.

That means that If the cursor is currently in regular(English - LTR) mode, then pressing Alt-Shift will make the cursor be RTL, and output a RightToLeft Language that you have set on your Windows(If any).

Also I should say that I am looking to Read the value, and not Set it.

I need to Check if the Cursor is currently in RTL, or LTR mode.

Might there be a Bit for that too?

Edited by Zohar

Share this post


Link to post
Share on other sites

Hello PsaltyDS!

Your code is very cool, I like it:)

I should clarify one thing tho:

There's a difference between Alt-Shift and Ctrl-Shift.

The code you created, is doing the functionality that you would get by Ctrl-Shift, which is changing the TextAlignment(Left/Right).

Alt-Shift however, does another thing.

Alt-Shift does not change the alignment,

but it changes the Cursor's Direction, and most importantly the Cursor's Output Language.

That means that If the cursor is currently in regular(English - LTR) mode, then pressing Alt-Shift will make the cursor be RTL, and output a RightToLeft Language that you have set on your Windows(If any).

Also I should say that I am looking to Read the value, and not Set it.

I need to Check if the Cursor is currently in RTL, or LTR mode.

Might there be a Bit for that too?

I knew it was slightly off what you were asking, but it illustrates the solution anyway. I don't have any RTL languages installed, so that's as close as I could come. But you can see from the code how to get the required bit from "$iExStyle = _WinAPI_GetWindowLong($hEdit_1, $GWL_EXSTYLE)", then doing a BitAND() on the returned value.

:)


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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I knew it was slightly off what you were asking, but it illustrates the solution anyway. I don't have any RTL languages installed, so that's as close as I could come. But you can see from the code how to get the required bit from "$iExStyle = _WinAPI_GetWindowLong($hEdit_1, $GWL_EXSTYLE)", then doing a BitAND() on the returned value.

:)

hi:)

yeah I've just finished playing with the code.

First I changed it to Read the value instead of Setting it.

Then I went on to look for the Flag for Alt-Shift instead of Ctrl-Shift.

Didn't find something in MSDN yet.

I then tried another trick.

look at this simple code:

Local   $CurrentControl_Handle  =ControlGetHandle("","",ControlGetFocus(""))
Local   $ExStyle                =_WinAPI_GetWindowLong($CurrentControl_Handle,$GWL_EXSTYLE)
MsgBox(0,$ExStyle)

This code simply displays the whole number that is represented by all flags in ExStyle.

I then ran this code when the TextBox is in regular(english) mode,

and then ran it again, when in a RTL language mode(that means, after pressing Alt-Shift).

If the number is different, then it means I can find the flag myself, even without MSDN.

However the displayed number was the same in both situations :/

Maybe there's another flag set that I can experiment with in addition to $GWL_EXSTYLE?

The value must exist somewhere, since windows knows If it's in LTR or RTL..

I must be able to find it somehow

I have a feeling that this flag is not stored per TextBox("Edit"), but per Window..

will check it now

Edited by Zohar

Share this post


Link to post
Share on other sites

Good idea. Use the same _WinAPI_GetWindowLong() and just point it to the window's handle vice the control's.

:)


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

Share this post


Link to post
Share on other sites

Good idea. Use the same _WinAPI_GetWindowLong() and just point it to the window's handle vice the control's.

:)

Hi..

I tried.. and no luck..

no flag changed on the window.. neither Style, nor ExStyle..

Anyone has an idea how can I get this flag?

Share this post


Link to post
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
Sign in to follow this  
Followers 0