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

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

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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?
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 »

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
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 may be interested in this api function :

CtrlID = GetDlgCtrlID_( GadgetID(100) )

Then CtrlID should be 100.
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 »

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 may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sorry flype, I must have posted at the same time! :D
I may look like a mule, but I'm not a complete ass.
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post 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?
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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!
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

-REMOVED-
Last edited by josku_x on Tue May 16, 2006 9:42 pm, edited 1 time in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
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 »

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?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
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 »

Sorry, yeah I didn't notice the 'assume' part.....................................................................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
................................. :?:
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

SetClipboardText(GetGadgetText(GetDlgCtrlID_(hWnd))) is 'assumed' to work only if hWnd comes from a StringGadget(), TextGadget(), EditorGadget(), etc...
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