The Upper limit of GetWindowText_()

Windows specific forum
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

The Upper limit of GetWindowText_()

Post by cecilcheah »

Hi all

How big can the third parameter be in the GetWindowText_(,,) function? I search the forum and see someonme uses 10000, but what is the upper limit?

What happen if the window text is more than the upper limit, how can i retrieve all the text then?

Thanks

Cecil
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

There should be no upper limit to that function.
The only limit you will run into is PB's limit of the String size (max 64K)

However, if you use a memorybuffer instead of a PB string, it should be unlimited.

Timo
quidquid Latine dictum sit altum videtur
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Hi there

Can you give me an example of how to use a memorybuffer in the GetWindowText_().

I am new to this Pure Basic and am just searching for PB codes to learn the stuff

hanks in advance

Cecil
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

The question is: why would you want a windowtext with more than 65536 characters..)) hehe ;)

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Good question.

The reason is i am not getting the window title text, but say the text in the text field itself.

For example
So instead of getting the "Untitled - Notepad", i am getting the text in the note pad.

Cecil
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

aaahh.. ok... my bad... :roll:

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Saboteur
Enthusiast
Enthusiast
Posts: 273
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

You can do it with pointers:

Code: Select all

If OpenWindow(0, 100,100,300,300,#PB_Window_SystemMenu,"Hello")
  If CreateGadgetList(WindowID())
    StringGadget(0,10,10,200,20,"this is a demo")
  EndIf

  *buffer=AllocateMemory(0,100000)
  GetWindowText_(GadgetID(0),*buffer,100000)
  
  MessageRequester("result",PeekS(*buffer),0)
  
  FreeMemory(0)
EndIf

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
End
Try it with a long text... :wink:
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Thanks a lot. Really appreciate your quick response.

Cecil
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

You can also use the GetWindowTextLength_() function to find out the size of the buffer needed:

Code: Select all

If OpenWindow(0, 100,100,300,300,#PB_Window_SystemMenu,"Hello") 
  If CreateGadgetList(WindowID()) 
    StringGadget(0,10,10,200,20,"This is text") 
  EndIf 
    bufferSize=GetWindowTextLength_(GadgetID(0))+1
  If bufferSize > 0
      *buffer=AllocateMemory(0,bufferSize) 
    GetWindowText_(GadgetID(0),*buffer,bufferSize) 
    
    MessageRequester("result",PeekS(*buffer, bufferSize),0) 
    
    FreeMemory(0) 
    Else
        MessageRequester("result","",0) 
    EndIf
EndIf 

Repeat 
Until WaitWindowEvent()=#PB_Event_CloseWindow 
End 
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Thanks a lot. This is a good idea to do, so my programme will not take up too much resources.

thanks

Cecil
Post Reply