Page 1 of 1

Paste RTF in EditorGadget [Windows]

Posted: Wed Sep 01, 2010 6:06 pm
by RASHAD
For Test :
1- Run MS Word or WordPad write any formatted text
2- Select the text then copy to clipbopard
3- Run the next code

Code: Select all

Procedure PasteRTF(gadget,line,column)
  SetActiveGadget(gadget)
  Pos = SendMessage_(GadgetID(gadget),#EM_LINEINDEX,line-1,0)
  Length = SendMessage_(GadgetID(gadget),#EM_LINELENGTH,Pos,0) 
  If Length >= column-1 
    Pos + column-1 
  EndIf 
  xy.CHARRANGE 
  xy\cpMin = Pos
  xy\cpMax = Pos 
  SendMessage_(GadgetID(gadget),#EM_EXSETSEL,0,xy) 
  keybd_event_(#VK_CONTROL,0,0,0)
  keybd_event_(#VK_V,0,0,0)
  keybd_event_(#VK_V,0,#KEYEVENTF_KEYUP,0)
  keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
EndProcedure

If OpenWindow(0, 0, 0, 400, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  hWnd = EditorGadget(0, 5, 5, 390, 150)
  ClearGadgetItems(0)
  ButtonGadget(1,10,160,80,24,"Paste")
  For i = 0 To 4
    AddGadgetItem(0, i,"Text for testing only")
  Next
  
  Repeat
      Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow       
          Q = 1
      
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              PasteRTF(0,2,3)
          EndSelect
      EndSelect
  Until Q = 1
EndIf


Re: Paste RTF in EditorGadget [Windows]

Posted: Wed Sep 01, 2010 6:17 pm
by srod
Why not just send a #WM_PASTE message?

Re: Paste RTF in EditorGadget [Windows]

Posted: Wed Sep 01, 2010 6:46 pm
by RASHAD
As per srod comment
I think I am not Ok I did that before but it gave me black fomatted text
Now it works OK
Maybe because of SetActiveGadget()

Code: Select all


If OpenWindow(0, 0, 0, 400, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  hWnd = EditorGadget(0, 5, 5, 390, 150)
  ClearGadgetItems(0)
  ButtonGadget(1,10,160,80,24,"Paste")
  For i = 0 To 4
    AddGadgetItem(0, i,"Text for testing only")
  Next
  
  Repeat
      Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow       
          Q = 1
      
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              SendMessage_(GadgetID(0),#WM_PASTE ,0,0)
          EndSelect
      EndSelect
  Until Q = 1
EndIf

Re: Paste RTF in EditorGadget [Windows]

Posted: Wed Sep 01, 2010 6:48 pm
by srod
Just the #wm_paste without all the additional messages should be enough I reckon. :)

Re: Paste RTF in EditorGadget [Windows]

Posted: Wed Sep 01, 2010 7:02 pm
by RASHAD
It was for positioning the cursor programmatic
But you got it
Post updated

Re: Paste RTF in EditorGadget [Windows]

Posted: Wed Sep 01, 2010 7:04 pm
by srod
:)

Re: Paste RTF in EditorGadget [Windows]

Posted: Thu Sep 02, 2010 12:15 pm
by Nico
I'm sorry but CTRL+V=#WM_PASTE, tested with code

so there is no advantage.

Re: Paste RTF in EditorGadget [Windows]

Posted: Thu Sep 02, 2010 12:55 pm
by RASHAD
@Nico
For the Scroll problem I just asked Fred to take a look to give us a proper solution
For Paste a colored RTF it seems that I can not reproduce the case
So can you submit some code to let us know the exact problem
and what PB ver ,OS ver you are using


Thank you

Re: Paste RTF in EditorGadget [Windows]

Posted: Thu Sep 02, 2010 1:17 pm
by Nico
So can you submit some code to let us know the exact problem
and what PB ver ,OS ver you are using
For the scroll problem?

I have posted a code, you want a demo video?

Re: Paste RTF in EditorGadget [Windows]

Posted: Thu Sep 02, 2010 1:23 pm
by RASHAD
Take it easy Nico
No sarcasm please
The code is for the color RTF
Reread my post carefully
I am just trying to help

Re: Paste RTF in EditorGadget [Windows]

Posted: Thu Sep 02, 2010 2:04 pm
by Nico
I do not understand, I have no problem, I spoke just to tell you that your code does not solve your problem in my opinion.

I assure you there is no sarcasm in my words. :)