Paste RTF in EditorGadget [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Paste RTF in EditorGadget [Windows]

Post 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

Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Paste RTF in EditorGadget [Windows]

Post by srod »

Why not just send a #WM_PASTE message?
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Paste RTF in EditorGadget [Windows]

Post 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
Last edited by RASHAD on Wed Sep 01, 2010 7:09 pm, edited 2 times in total.
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Paste RTF in EditorGadget [Windows]

Post by srod »

Just the #wm_paste without all the additional messages should be enough I reckon. :)
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Paste RTF in EditorGadget [Windows]

Post by RASHAD »

It was for positioning the cursor programmatic
But you got it
Post updated
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Paste RTF in EditorGadget [Windows]

Post by srod »

:)
I may look like a mule, but I'm not a complete ass.
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: Paste RTF in EditorGadget [Windows]

Post by Nico »

I'm sorry but CTRL+V=#WM_PASTE, tested with code

so there is no advantage.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Paste RTF in EditorGadget [Windows]

Post 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
Egypt my love
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: Paste RTF in EditorGadget [Windows]

Post 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?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Paste RTF in EditorGadget [Windows]

Post 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
Egypt my love
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: Paste RTF in EditorGadget [Windows]

Post 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. :)
Post Reply