Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetWindowTextW - can you get it to work?
#6
A few more changes which you'll want to look at and make use of:

Code: (Select All)
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION GetWindowTextA& (BYVAL hWnd AS _OFFSET, lpString AS STRING, BYVAL nMaxCount AS LONG)
    FUNCTION GetWindowTextW& (BYVAL hWnd AS _OFFSET, lpString AS STRING, BYVAL nMaxCount AS LONG)
END DECLARE
DIM Dummy AS INTEGER
DIM n AS STRING * 255
_TITLE "This is a test"
Dummy = GetWindowTextA(_WINDOWHANDLE, n, 255)
PRINT LEFT$(n, Dummy)
Dummy = GetWindowTextW(_WINDOWHANDLE, n, 255)
PRINT LEFT$(n, Dummy * 2) '*2 as we're not print wide-text and just printing ASCII text
_DELAY .5
Dummy = GetWindowTextA(_WINDOWHANDLE, n, 255)
PRINT LEFT$(n, Dummy)
Dummy = GetWindowTextW(_WINDOWHANDLE, n, 255)
PRINT LEFT$(n, Dummy * 2) 'as above

Notice that I made the return function types LONGs, instead of SINGLES.   Now you can get the proper length back from the function.

Note #2 -- also notice that I changed your last type.  You were sending it an INTEGER, while it was wanting a LONG.  See the Windows Types here: https://learn.microsoft.com/en-us/window...data-types   (Not that it really mattered at this point, as you were sending it a pure value of 255 -- which is more than small enough to work for both INTEGER or LONG.  I just wanted to point this mismatch out, to draw attention to it so you wouldn't get bit by it in the future when it would matter more.)

Quote:INT
A 32-bit signed integer. The range is -2147483648 through 2147483647 decimal.

This type is declared in WinDef.h as follows:

typedef int INT;

I think this should have all the little glitches out and have the functions working 100% as advertised now.
Reply


Messages In This Thread
RE: GetWindowTextW - can you get it to work? - by SMcNeill - 06-08-2024, 04:47 AM



Users browsing this thread: 8 Guest(s)