api_GetWindowText

Blitz3D Forums/Blitz3D Programming/api_GetWindowText

I need a function to get the caption of a window and the class of a window by sending that function the hwnd of the window.. im not sure how to use getwindowtext, and if there is one i need a getwindowclass also.

Hi Syco.

GetWindowText() requires a buffer to store the windows caption this should be done using a bank.

when setting the call in the .decls use a bank pointer in GetWindowText(hwnd%,bank*,size%).

getting the caption would look somting like this

bank = CreateBank(256)
caption_length = GetWindowText(hwnd,bank,256)
for loop = 0 to caption_length
 ; peek the string from the bank
next
FreeBank bank


the same holds true when getting the class name using GetClassName()

kev

Man, youre a saver :D.

Nevermind, i noticed i didnt change the decls file, sorry :D.

Hey, what am I doing wrong here:


Local hwnd% = SystemProperty("AppHWND")

api_SetWindowText(hwnd,"BOBsasd")
	

Local bank%
	Local caption_length%
	Local i%
	Local Dave$ = ""

	bank = CreateBank(254)
	caption_length = api_GetWindowText(hwnd,bank,254)
	For i = 0 To caption_length
		
		Dave = Dave + Chr((PeekByte(bank,i)))
		
	Next
	FreeBank bank

	Print Dave$


It sets it fine, and returns that it is using 7 characters when it reads it back, but I can't get them to process it. It just returns 0000000 when I take away the chr conversion.

Any clues?

Fixed it, It turns out that the User32 decls in the code archives is wrong?

http://www.blitzbasic.com/codearcs/codearcs.php?code=1179

It lists:
api_GetWindowText% (hwnd%, lpString$, cch%) : "GetWindowTextA"

and I changed it to
api_GetWindowText% (hwnd%, lpString*, cch%) : "GetWindowTextA"

Which fixed it. Is this a mistake in the user32 decls?

in blitz we cant get the address of the string buffer, so we need to use a bank. this holds true for much of the windows api that require address pointers.

so yes its fixed for blitz :)