I can find a specific windows by its title but returning the title text into the buffer is one character short for some reason. Can anyone tell me what I have missed?
I would also like to find a window by string subset rather than the entire string. Is there a way to do that witht he API like FindString but in a window title?
WindowText.s = "Untitled - Notepad"
TargetWindowHandle.i = FindWindow_(0, WindowText.s)
If TargetWindowHandle.i
Debug "Found notepad window handle: " + Str(TargetWindowHandle.i)
TextLength.i = GetWindowTextLength_(TargetWindowHandle.i)
If TextLength.i
Debug "Found title text of: " + Str(TextLength.i) + " characters in length "
*CharacterBuffer = AllocateMemory(TextLength.i)
If *CharacterBuffer
GetWindowText_(TargetWindowHandle.i, *CharacterBuffer, TextLength.i)
Debug PeekS(*CharacterBuffer)
Else
Debug "There was n0 character buffer allocated for some reason or other"
EndIf
Else
Debug "No text found in the notepad window titlebar to display"
EndIf
Else
Debug "Target window handle not found"
EndIf
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
WindowText.s = "Untitled - Notepad"
TargetWindowHandle.i = FindWindow_(0, WindowText.s)
If TargetWindowHandle.i
Debug "Found notepad window handle: " + Str(TargetWindowHandle.i)
TextLength.i = GetWindowTextLength_(TargetWindowHandle.i)+1
If TextLength.i
Debug "Found title text of: " + Str(TextLength.i) + " characters in length "
*CharacterBuffer = AllocateMemory(TextLength.i)
If *CharacterBuffer
GetWindowText_(TargetWindowHandle.i, *CharacterBuffer, TextLength.i)
Debug PeekS(*CharacterBuffer)
Else
Debug "There was n0 character buffer allocated for some reason or other"
EndIf
Else
Debug "No text found in the notepad window titlebar to display"
EndIf
Else
Debug "Target window handle not found"
EndIf
Thanks RSBASIC, I was playing with that earlier and figured it out but I don't understand why GetWindowTextLength_(TargetWindowHandle.i) returns the text length -1?
I noticed that MSDN had some things to say and they pretty well hinted that ALL the text would be returned and sometimes a little more depending on some circumstances but never less.
They also said "To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT, or CB_GETLBTEXT messages".
Maybe I have to do that?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Fangbeast wrote:They also said "To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT, or CB_GETLBTEXT messages".
You can also use WM_GETTEXT.
But you can't use LB_GETTEXT and CB_GETLBTEXT because LB_GETTEXT is only for List Box Control (ListViewGadget) and CB_GETLBTEXT for Combo Box Control (ComboBoxGadget).