Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 9 Jahren, 10 Monaten
Letzter Beitrag:
vor 9 Jahren, 10 Monaten
Beteiligte Autoren:
Theo Derks, Sohan, DW, Louis Verbraak

Cursor at the end of an edit-field

Startbeitrag von Theo Derks am 27.09.2008 21:03

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:

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!



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.


von Sohan - am 27.09.2008 23:23
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.

I always wondered why Windev never implemented a PostKey command.


von Sohan - am 28.09.2008 00:37
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.


von Louis Verbraak - am 28.09.2008 10:50

This is an option that you check in the Details Tab

Automatic End of Input


von DW - am 28.09.2008 13:32
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!


von Theo Derks - am 28.09.2008 17:52
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!


von Theo Derks - am 28.09.2008 17:58
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!


von Theo Derks - am 28.09.2008 18:06

Thank you for explaining that did not know.


von DW - am 28.09.2008 22:27
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
Myself..Cursor = 1
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.


von Sohan - am 29.09.2008 01:43
Hi Sohan

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


von Theo Derks - am 30.09.2008 14:26
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.