Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetWindowTextW - can you get it to work?
#7
(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. Smile

@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.
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-08-2024, 03:11 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 968 08-15-2024, 11:36 AM
Last Post: mdijkens
  Does _MapTriangle work in a user defined Window? bplus 12 2,292 02-16-2024, 01:40 AM
Last Post: bplus
Bug I want it to work so bad.... NasaCow 39 9,046 11-30-2022, 10:30 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)