Page 1 of 2

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

Posted: Tue May 16, 2006 8:03 pm
by josku_x
Hello!

I am creating a "peek" program just like WinPeek with that you can view and edit stuff of other windows. However, I stumbled in this situation that I don't know how to get text from an EditorGadget() (RichEdit20A).

I tried using GetWindowText_(), but it returns an empty string. But if I use GetWindowText_() with another control like a button, then it works.

So, it's not an issue with my code, but with the Win API.

Thanks

Posted: Tue May 16, 2006 8:30 pm
by srod
You can use the following to retrieve the text in one great 'lump'! This will include any control codes separating individual lines though.

Code: Select all

tlen = SendMessage_(GadgetID(#edit), #WM_GETTEXTLENGTH, 0, 0) + 1 
edit$ = Space(tlen) 
SendMessage_(GadgetID(#edit), #WM_GETTEXT, tlen, @edit$) 
Why not GetGadgetText() though?

Posted: Tue May 16, 2006 8:33 pm
by josku_x
THanks srod!
srod wrote:Why not GetGadgetText() though?
If I retrieve a system handle to a control, I can't use PB commands with it, as PB commands need the #number of the gadget and not the #handle. Capich? :D

Posted: Tue May 16, 2006 8:51 pm
by Flype
You may be interested in this api function :

CtrlID = GetDlgCtrlID_( GadgetID(100) )

Then CtrlID should be 100.

Posted: Tue May 16, 2006 8:52 pm
by srod
GetDlgCtrlID_(ehWnd) will return the PB identifier for the gadget with the window's handle ehWnd etc. This assumes of course that you created the rich edit control with PB commands.

Posted: Tue May 16, 2006 8:54 pm
by srod
Sorry flype, I must have posted at the same time! :D

Posted: Tue May 16, 2006 9:24 pm
by Matt
Flype wrote:You may be interested in this api function :

CtrlID = GetDlgCtrlID_( GadgetID(100) )

Then CtrlID should be 100.
does this mean if you have the handle, for example of the input gadget for the URL in let's say firefox, and you do ctrlid = GetDlgCtrlID_(handlehere) , would I be able to take the ctrlid result and use it in gadget functions?

Posted: Tue May 16, 2006 9:36 pm
by josku_x
Flype wrote:You may be interested in this api function :

CtrlID = GetDlgCtrlID_( GadgetID(100) )

Then CtrlID should be 100.
Oh man! I am so dumb. Yesterday I was working on a project with Pelles C using dialogs. And I knew that there was this GetDlgCtrlID_() function.. :oops:

Thanks! Now I am enjoying the affair between PB and API more and more!

Posted: Tue May 16, 2006 9:39 pm
by josku_x
-REMOVED-

Posted: Tue May 16, 2006 9:41 pm
by srod
Matt wrote:does this mean if you have the handle, for example of the input gadget for the URL in let's say firefox, and you do ctrlid = GetDlgCtrlID_(handlehere) , would I be able to take the ctrlid result and use it in gadget functions?
In short, no! The control will mean nothing to PB as it will have no record of having created the control. In this case it is API all the way!

Posted: Tue May 16, 2006 9:44 pm
by josku_x
Mr. IKnowEverything (srod), why did you want to tell me then that there is the GetDlgCtrlID_() API function? If I can't use PB commands with the returned CtrlID, what's the use of it then?

Posted: Tue May 16, 2006 10:00 pm
by srod
Josku_x, not entire sure what just bit your backside there? My previous post was entered before I noticed your post.

Besides, did you even read my original post on the subject of GetDlgCtrlID_() ? Let me just repeat it for you:

GetDlgCtrlID_(ehWnd) will return the PB identifier for the gadget with the window's handle ehWnd etc. This assumes of course that you created the rich edit control with PB commands.

I guess you missed the 'assume...' part.

Posted: Tue May 16, 2006 10:03 pm
by josku_x
Sorry, yeah I didn't notice the 'assume' part.....................................................................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
................................. :?:

Posted: Tue May 16, 2006 10:13 pm
by josku_x
BTW: I can't get my code to work. I am using this code:

Code: Select all

SetClipboardText(GetGadgetText(GetDlgCtrlID_(hWnd)))
After I set the hWnd handle to the RichEdit (I get the handle through WinPeek) the program crashes and nothing happens.. Is it expected to be like this?

Posted: Tue May 16, 2006 10:28 pm
by Flype
SetClipboardText(GetGadgetText(GetDlgCtrlID_(hWnd))) is 'assumed' to work only if hWnd comes from a StringGadget(), TextGadget(), EditorGadget(), etc...