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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Trapping Keyboard or Mouse Event in a Rich Text Box 1

Status
Not open for further replies.

Apata

Programmer
Apr 5, 2006
52
US
I placed a button and 3 Rich Text Boxes on a form. I want to be able to dump the content of RichText1 and RichText2 in RigTtext3. I can do this manually when I run the form. I tried to do it by code by setting up the Click event of the Button with the following code:

Thisform.RichText1.Setfocus
KEYBOARD "{CTRL+A}"
KEYBOARD "{CTRL+C}"

But nothing happened. I also tried to simulate right mouse click inside RichText1 by setting the Autoverb to True. But nothing happened there either.

Is there a bug somewhere? or what's the way out of this? Thanks for your help.
 

Apata,

No, it's not a bug. ActiveX controls cannot see the VFP keyboard buffer, so the KEYBOARD command has no effect.

If you want to save the contents of the control, use the File property. This points to an RTF file that contains the entire text of the control.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I see. Thanks again, Mike. The problem then is this: I need to combine the contents of these RTF boxes (about 8 of them per record) and put them in this one that'll combine all of them. I know how to save the big piece into a file. My problem is how to combine all these smaller pieces into the big one.
 
Oh yeah, I need to combine them with their RTF formating intact. Thanks.
 
Apata,

While the VFP KEYBOARD command won't work, API calls should. Here's the code...
Code:
*!* Use API calls to simulate CTRL + A, CTRL + C
#DEFINE KEYEVENTF_KEYUP 0x02
#DEFINE VK_CONTROL 0x11

DECLARE INTEGER keybd_event IN Win32API ;
      INTEGER, INTEGER, INTEGER, INTEGER

Thisform.RichText1.Setfocus()
DOEVENTS
keybd_event(VK_CONTROL, 0, 0, 0)
keybd_event(0x41, 0, 0, 0) && 0x41 is 'A'
keybd_event(0x43, 0, 0, 0) && 0x43 is 'C'
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
CLEAR DLLS "keybd_event"

boyd.gif

SweetPotato Software Website
My Blog
 
Thank you so much Craig. It works. I put it in a command button and it copies the text from RichText1.

I need to paste the text inside RichText3. I duplicated the whole code on the same button, replacing:

keybd_event(0x41, 0, 0, 0) && 0x41 is 'A'
with
keybd_event(0x62, 0, 0, 0) && thought that would be "V"

But nothing happened. Eventually, I need to copy text from RichText1 and RichText2 and combine them in RichText3. I need to do this process for about 8 records each time. So, I would need to do a loop.

Could you clue me in on the code for paste, and how to structure the code when moving from RichtText1 to Richtext3, RichText2 to RichText3, etc? Thanks for your help.
 
Hi again Craig:

It's been quite a while on this topic, but I couldn't get it to work. I'm sure it's the way I am ordering the sequence of the codes.

On the code that copies the text from the 1st RTF control, I put this:
Code:
*!* Use API calls to simulate CTRL + A, CTRL + C
#DEFINE KEYEVENTF_KEYUP 0x02
#DEFINE VK_CONTROL 0x11

DECLARE INTEGER keybd_event IN Win32API ;
      INTEGER, INTEGER, INTEGER, INTEGER

Thisform.RichText1.Setfocus()
DOEVENTS
keybd_event(VK_CONTROL, 0, 0, 0)
keybd_event(0x41, 0, 0, 0) && 0x41 is 'A'
keybd_event(0x43, 0, 0, 0) && 0x43 is 'C'
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
CLEAR DLLS "keybd_event"

On the command that do the paste on the 2nd RTF, Richtext2, I have this:
Code:
*!* Use API calls to simulate CTRL + V
#DEFINE KEYEVENTF_KEYUP 0x02
#DEFINE VK_CONTROL 0x11

DECLARE INTEGER keybd_event IN Win32API ;
      INTEGER, INTEGER, INTEGER, INTEGER

Thisform.RichText2.Setfocus()
DOEVENTS
keybd_event(VK_CONTROL, 0, 0, 0)
keybd_event(0x56, 0, 0, 0) && 0x56 is 'V'
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
CLEAR DLLS "keybd_event"

I've changed this around several times without success. Please, help me out.

Thanks.

Apata

Apata
 
Code:
PUBLIC oform1_1TC0ZVBYF

oform1_1TC0ZVBYF=NEWOBJECT("form1")

oform1_1TC0ZVBYF.Show
RETURN

DEFINE CLASS form1 AS form

	Top = 0
	Left = 0
	Height = 271
	Width = 375
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
	Visible = .T.

	ADD OBJECT richtext1 AS olecontrol_L1_C1_TC2

	ADD OBJECT richtext2 AS olecontrol_L1_C2_TC3

	ADD OBJECT command1 AS commandbutton_L1_C3_TC4

ENDDEFINE

DEFINE CLASS olecontrol_L1_C1_TC2 AS olecontrol

	Top = 12
	Left = 12
	Height = 97
	Width = 349
	Name = "RichText1"
	OleClass = "RICHTEXT.RichtextCtrl.1"
	Visible = .T.

ENDDEFINE

DEFINE CLASS olecontrol_L1_C2_TC3 AS olecontrol

	Top = 120
	Left = 12
	Height = 97
	Width = 349
	Name = "RichText2"
	OleClass = "RICHTEXT.RichtextCtrl.1"
	Visible = .T.

ENDDEFINE

DEFINE CLASS commandbutton_L1_C3_TC4 AS commandbutton

	Top = 228
	Left = 276
	Height = 27
	Width = 84
	Caption = "Copy/Paste"
	Name = "Command1"
	Visible = .T.

	PROCEDURE Click
		*!* Use API calls to simulate CTRL + A, CTRL + C
		#DEFINE KEYEVENTF_KEYUP 0x02
		#DEFINE VK_CONTROL 0x11

		DECLARE INTEGER keybd_event IN Win32API ;
		      INTEGER, INTEGER, INTEGER, INTEGER

		*!* Copy text from first control
		Thisform.RichText1.Setfocus()
		keybd_event(VK_CONTROL, 0, 0, 0)
		keybd_event(0x41, 0, 0, 0) && 0x41 is 'A'
		keybd_event(0x43, 0, 0, 0) && 0x43 is 'C'
		keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)

		DOEVENTS FORCE && Make sure that the keyboard events are processed before RichText2 receives focus

		*!* Paste into second control
		Thisform.RichText2.Setfocus()
		keybd_event(VK_CONTROL, 0, 0, 0)
		keybd_event(0x56, 0, 0, 0) && 0x56 is 'V'
		keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
		CLEAR DLLS "keybd_event"
	ENDPROC
	
ENDDEFINE

boyd.gif

SweetPotato Software Website
My Blog
 
Thanks Craig. That was neat.

One more thing, please. What would be the hexadecimal code for keyboard combinations like the following:


Backspace
End
Ctrl-End
PgDn
PgUp

My RTF keeps adding carriage return each time I save it. So, I am trying to find a way to control this behavior.

Thanks.
 
Thanks very much. That's good to know. I also discovered the cause of the extra space is my use of SelRTF instead of RTFText.

Apata.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top