How to get text from an EditorGadget()? The API way...

Just starting out? Need help? Post your questions and find answers here.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Flype wrote:SetClipboardText(GetGadgetText(GetDlgCtrlID_(hWnd))) is 'assumed' to work only if hWnd comes from a StringGadget(), TextGadget(), EditorGadget(), etc...
the hWnd comes form an EditorGadget() but it fails here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Is the editor gadget from a different process\application by any chance? If so, this method will not work.
I may look like a mule, but I'm not a complete ass.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

srod wrote:Is the editor gadget from a different process\application by any chance? If so, this method will not work.
Yes, it's from another process/application. I wanted to have this feature because I am creating the "peek" program.

EDIT: is there any chance to get the text of an editorgadget of another process?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The API method should work in this case.

Sorry to send you off on a goose chase; I didn't realise the gadget was from another process.
I may look like a mule, but I'm not a complete ass.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

no problem, but the api way (in your first post) doesn't work here. the program crashes before it readed the text.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

you should use SendMessage_() with #EM_GETTEXTEX and fill the structure GETTEXTEX.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The following works here.

Code: Select all

;Make sure this program is running.

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  EditorGadget(0, 8, 8, 306, 133) 
  SetGadgetText(0,"HELLO!")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
Run the above program first. The next program will display the contents of the editor gadget in the already running program.

Code: Select all

hwnd=FindWindow_(#Null, "EditorGadget") 
If hwnd
  redit=FindWindowEx_(hwnd, #Null, "RichEdit20A", #Null) 
  tlen = SendMessage_(redit, #WM_GETTEXTLENGTH, 0, 0) + 1 
  edit$ = Space(tlen) 
  SendMessage_(redit, #WM_GETTEXT, tlen, @edit$) 
  Debug edit$
EndIf
I may look like a mule, but I'm not a complete ass.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

hint: they don't make it that easy :wink:
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

this one should work even if richedit is in ascii or unicode.

Code: Select all

Enumeration ; GT_
  #GT_DEFAULT
  #GT_USECRLF
  #GT_SELECTION
EndEnumeration
Enumeration ; GTL_
  #GTL_DEFAULT = 0
  #GTL_USECRLF = 1
  #GTL_PRECISE = 2
  #GTL_CLOSE = 4
  #GTL_NUMCHARS = 8
  #GTL_NUMBYTES = 16
EndEnumeration

Procedure.s GetRichEditText(hWindow.l, limit.l)
  
  Protected text.s, gt.GETTEXTEX, gtl.GETTEXTLENGTHEX
  
  If IsWindowUnicode_(hWindow)
    gtl\codepage = 1200
  Else
    gtl\codepage = #CP_ACP
  EndIf
  
  gtl\flags = #GTL_DEFAULT|#GTL_NUMCHARS
  
  gt\cb = SendMessage_(hWindow, #EM_GETTEXTLENGTHEX, @gtl, #Null)
  gt\flags = #GT_DEFAULT
  gt\codepage = gtl\codepage
  
  text = Space(gt\cb)
  
  SendMessage_(hWindow, #EM_GETTEXTEX, @gt, @text)
  
  ProcedureReturn text
  
EndProcedure

If OpenWindow(0, 0, 0, 320, 240, "test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  If CreateGadgetList(WindowID(0))
    EditorGadget(0, 5,  5, 200, 100)
  EndIf
  
  SetGadgetText(0, "hello world !")
  
  Debug GetRichEditText(GadgetID(0))
  
  Repeat :  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply