Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using API to customize text box popup menu--Delete/Undo trouble 1

Status
Not open for further replies.

BobRodes

Instructor
May 28, 2003
4,215
0
0
US
I got interested in using the API to emulate the text box popup mneu after the discussion in thread222-1379849. I have most of it together, but I'm having trouble with a couple of things. I presently have the menu itself working, and the Undo feature. Now I'm working on the Delete. I have the following code for Undo (all the necessary declares and constant definitions are in place):

[tt]Public Sub ProcessUndoSelection(cCtl As Control)
If SendMessage(cCtl.hwnd, EM_CANUNDO, 0, 0) <> 0 Then
SendMessage cCtl.hwnd, EM_UNDO, 0, 0
End If
End Sub
[/tt]
This works if I just use keystrokes to alter the text in the box. However, if I programmatically change the contents of the text box it doesn't work, for example when I do this to support the Delete selection:
[tt]
Public Sub ProcessDelete(cCtl As Control, cForm As Form)
Dim cSelStart as Integer
With Text1
cSelStart = .SelStart
.Text = Replace(.Text, .SelText, "")
.SelStart = cSelStart
End With
[/tt]
After doing this, selecting Undo doesn't replace the deleted text. It looks pretty clear that there's an undo buffer that gets blanked in this situation, and I don't know how to either prevent that or store the deleted text to the buffer. I'm pretty sure there must be something like that that one can do. Can someone help?

TIA

Bob
 
I should note that I tried using SetWindowText with the same result.
 
The undo functionality of a textbox is pretty limited. And you don't really have much control of it.

Basically, you can undo whilst the undo flag is set - and the undo flag gets unset if the control receives a WM_SETTEXT message (which both your ProcessDelete sub and the SetWindowText API call cause to occur). I am not aware of any way of stopping this from happening. Nor am I aware of a method of accessing the undo buffer directly
 
So, I found (and I'm not suggesting that I plan to do this) that doing a Sendkeys on the delete key, or just using the delete key, works. We're saying then that keystrokes in a text box that alter the text do NOT send a WM_SETTEXT message to the edit control?
 
You should send the WM_CLEAR message to the textbox to delete the selected text, which also preserves the undo information.
 
Thank you, that seems to have done the trick. :)
 
Hypetia, thanks again for the nudge in the right direction. From that I was able to work out the use of WM_CUT, WM_COPY and WM_PASTE as well, rather than using regular VB commands. Strongm, I appreciate your comments as well. I'm posting the custom menu in the other thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top