Welcome! Log In Create A New Profile

Advanced

Cursor at the end of an edit-field

Posted by Theo Derks 
Theo Derks
Cursor at the end of an edit-field
September 27, 2008 11:03PM
Hello,
In my app I want to set the cursor at the end of the edit-fields, so that the users don't have to input the END-key to go to the end of each edit-field.

Therefore I use an event with WM_SETFOCUS:
Event("Proc_GetFocusInEditField","*.*",WM_SETFOCUS)

In that Event I use the following code:
Procedure Proc_GetFocusInEditField()
myself..cursor = Length(MySelf+1) --> does not work
SendKey("{END}") --> does not work
SendKey("{END}"+".") --> works, but that's not I wanted

Does anyone know what's the reason the first two options don't work?

Many thanks!

Theo.
Sohan
Re: Cursor at the end of an edit-field
September 28, 2008 01:23AM
Hi Theo,

You probably mean

myself..cursor = Length(MySelf)+1

instead of

myself..cursor = Length(MySelf+1)

And you may want to add

IF Myself..Type = typText _and_ Myself..State = Active THEN ...

The WM_SETFOCUS message is sent to much more than just edit controls.

Personally I would prefer not to use SendKey. WM_SETFOCUS can be part of a chain of messages, and SendKey interrupts this chain. Setting ..Cursor should work I think.

/sohan

Sohan
Re: Cursor at the end of an edit-field
September 28, 2008 02:37AM
Hi Theo,

I just had a look at it. Indeed, none of the methods you tried seem to work.

SendKey actually translates into SendMessage, which is why I don't like to use it in event-handling routines. If you use PostMessage instead, it works.

PostMessage(Handle(MySelf),WM_KEYDOWN,VK_END,0)
I always wondered why Windev never implemented a PostKey command.

Cheers,
/sohan
Louis Verbraak
Re: Cursor at the end of an edit-field
September 28, 2008 12:50PM
Hello Theo,

I use this aswell, but I use ..Cursor and ..CursorEnd at the same time:

myself..cursor = Length(MySelf)+1
myself..cursorEnd = Length(MySelf)+1

It should work with only ..Cursor, but you need to uncheck 'Automatic erase' on the Details-tab.

HTH.



Edited 1 time(s). Last edit at 09/28/2008 01:11PM by Louis Verbraak.
DW
Re: Cursor at the end of an edit-field
September 28, 2008 03:32PM
Theo,

This is an option that you check in the Details Tab

Automatic End of Input

Dennis
Theo Derks
Re: Cursor at the end of an edit-field
September 28, 2008 07:52PM
Hello Dennis,

In my opinion the Automatic End of Input the cursor goes to the next control if the maximum of characters are entered. My question was to place the cursor after the last character in an edit-field, in stead of the beginning of the field.

The option mentioned by Sohan (the Postmessage) works fine.

Thank you for participating!

Theo.
Theo Derks
Re: Cursor at the end of an edit-field
September 28, 2008 07:58PM
Hi Louis,

If I use your suggestion, (two times the sendkey), I get the whole edit-field in reverse video, even if i uncheck the option Automatic Erase.

So, I don't know why it's working by you and not here by me, maybe we can test it the next time in Meer (Belgium).

The option Sohan mentioned is working fine (PostMessage).

Thank you for your answer!

Theo.
Theo Derks
Re: Cursor at the end of an edit-field
September 28, 2008 08:06PM
Hi Sohan,

Your suggestion works fine! (the Postmessage-line)

But I'm wondering why the Sendkey doesn't work, and the line SendKey("{END}"+".") is working!?

But thank you for your answer, i did never use Postmessage, but your suggestion is a new thing for me!

Theo.
DW
Re: Cursor at the end of an edit-field
September 29, 2008 12:27AM
Theo

Thank you for explaining that did not know.

Dennis
Sohan
Re: Cursor at the end of an edit-field
September 29, 2008 03:43AM
Hi Theo,

The thing with Event is that your trapping procedure is called prior to any actions taken by WD/MSW. The normal thing for Windev to do when giving focus to an edit control, is emulating CTRL-A (select all) when you have 'Automatic erase' enabled, or putting the cursor at the end of the input field when you have 'Automatic end of input' enabled, or whatever is appropriate depending on what you specified in the Details tab. Your trapping procedure however is called *before* this happens. The scenarios that you tried actually do work, all three of them. Try this:

Myself..Cursor = Length(MySelf)+1
Trace(Myself..Cursor)
Myself..Cursor = 1
Trace(Myself..Cursor)
SendKey("{END}")
Trace(Myself..Cursor)
As you can see, the commands *are* effective; the cursor *is* being moved by them. But when the trapping procedure returns Windev takes over again, and does the things that it is supposed to: emulate CTRL-A etc, effectively undoing your stuff.

When pressing TAB to jump from edit-field A to edit-field B, a lot of things happen. A WM_KILLFOCUS is sent to field A, its exit code is executed, and the field is repainted. Next a WM_SETFOCUS is sent to field B, its entry code is run and the field is repainted. All of this involves sending a lot of messages. It is usually best not to use SendKey or SendMessage when such a chain is being handled, because they disturb the logical sequence in which events are processed.

PostMessage does not interrupt anything, but simply adds a message to the message queue. It is processed when all the pending events have been handled, not earlier. In your case it means that the END-key is applied *after* Windev has done its thing. That is why it works.

Cheers,
/sohan
Theo Derks
Re: Cursor at the end of an edit-field
September 30, 2008 04:26PM
Hi Sohan

Thank for your explanation! Now I'm understanding my problems and how to get around with!

Theo.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: