Windows: Padding a string before assigning?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

To get the text of the foreground window, you can do this:

Code: Select all

fg=getforegroundwindow_() : t$=Space(255) : getwindowtext_(fg,t$,255)
However, I've noticed that this also works:

Code: Select all

fg=getforegroundwindow_() : getwindowtext_(fg,t$,255)
So is there any actual requirement to pad t$ first? I know it creates a
buffer for the text, but if it works without it, what's the problem?

PB - Registered PureBasic Coder

Edited by - PB on 27 March 2002 11:10:02
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.
To get the text of the foreground window, you can do this:

Code: Select all

fg=getforegroundwindow_() : t$=Space(255) : getwindowtext_(fg,t$,255)
However, I've noticed that this also works:

Code: Select all

fg=getforegroundwindow_() : getwindowtext_(fg,t$,255)
So is there any actual requirement to pad t$ first? I know it creates a
buffer for the text, but if it works without it, what's the problem?

PB - Registered PureBasic Coder

Edited by - PB on 27 March 2002 11:10:02
UAR! What are you doing there?? :))
It works, but you do not allocate memory for your use. It is possible that these section of mem is allready in use by another task and it would be fatal to write datas to a random memory position.
This should work too, but you shoul NEVER use it:
fg=getforegroundwindow_() : getwindowtext_(fg,rnd(5000000),255) :))))

Please alloc some mem first and other tasks will thank you.

Mike

Tranquilizer/ Secretly!
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> It works, but you do not allocate memory for your use.
> Please alloc some mem first and other tasks will thank you.

So by setting t$ to Space(255), this is allocating the memory for it, right?
That's what I've been doing all along, and if that's the right way, then I'll
keep doing it.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Thats the way - aha aha - I like it.... aha aha... uuhhuhh...*singin*
(a melody out of a german commercial)
:-)


Tranquilizer/ Secretly!
Registred PureBasic User
Post Reply