06-08-2024, 03:11 PM
(06-08-2024, 04:47 AM)SMcNeill Wrote: 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.
Thanks Steve, I even referred to the page in the Wiki pointing out equivalent values (int = long, etc) but neglected to make the change. Like I said before, I'll get this.
@DSMan195276 Thank you for the info as well. I only need this function to get the name of the current window that has focus outside of the main program. When the main window has focus (the window handles match) I'll indeed use _TITLE$ to avoid needing a delay.
I want to add a section in the tutorial's library lesson on how to use API calls so I'm taking a deep dive into the subject. Right now I just state it's possible and give a simple example.