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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Does _base64decode$ and _inflate$ work when used together? Dav 5 540 11-21-2025, 06:59 AM
Last Post: Pete
  CAN someone please get the graphics in this to work? Dragoncat 3 663 05-07-2025, 12:17 PM
Last Post: bplus
  Even robocopy doesn't work krovit 3 969 08-15-2024, 11:36 AM
Last Post: mdijkens
  Does _MapTriangle work in a user defined Window? bplus 12 2,294 02-16-2024, 01:40 AM
Last Post: bplus
Bug I want it to work so bad.... NasaCow 39 9,047 11-30-2022, 10:30 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)