Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetWindowTextW - can you get it to work?
#4
(06-07-2024, 07:21 PM)SMcNeill Wrote: A working example, plus a few changes which you'll want to make use of:

Code: (Select All)
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION GetWindowTextA (BYVAL hWnd AS _OFFSET, lpString AS STRING, BYVAL nMaxCount AS INTEGER)
    FUNCTION GetWindowTextW (BYVAL hWnd AS _OFFSET, lpString AS STRING, BYVAL nMaxCount AS INTEGER)
END DECLARE

DIM Dummy AS INTEGER
DIM n AS STRING * 255

_TITLE "This is a test"
Dummy = GetWindowTextA(_WINDOWHANDLE, n, 255)
PRINT n
Dummy = GetWindowTextW(_WINDOWHANDLE, n, 255)
PRINT n
_DELAY .5
Dummy = GetWindowTextA(_WINDOWHANDLE, n, 255)
PRINT n
Dummy = GetWindowTextW(_WINDOWHANDLE, n, 255)
PRINT n


Note that since this is a Windows call, you'll need a delay after the _TITLE to give the OS time to update things to return the proper title for you.

Also note that I'm passing an _OFFSET and not an _INTEGER64.

And you can see the difference in A and W function calls here.

Also notice the STRING * 255 here.  Wink
I tried everything your code has except for _OFFSET and that seems to be the trick.

I thought _OFFSET and _INTEGER64 were basically the same thing. I'll need to investigate that further.

Thank you for the explanation and code Steve. I'll get the hang of this yet.

Ah, the string length also must be identified: n AS STRING * 255

I also found out you need to pad the string with spaces: n = SPACE$(255) before using it otherwise LTRIM, RTRIM, and _TRIM won't work on it.

Ugh, and a CHR$(0) is appended to the end of the name that needs to be removed.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply


Messages In This Thread
RE: GetWindowTextW - can you get it to work? - by TerryRitchie - 06-07-2024, 09:30 PM



Users browsing this thread: 4 Guest(s)