special-names.
symbolic constant
gw_hwndfirst is 0
gw_hwndnext is 2
.
data division.
working-storage section.
01 get-this-window-handle.
05 this-window-handle pic s9(9) comp-5 value 0.
05 filler pic x(12) value spaces.
01 title-bar-search-string pic x(1025) value spaces.
01 title-bar-index pic 9(9) comp-5 value 0.
01 child-window-handle pic s9(9) comp-5 value 0.
01 parent-window-handle pic s9(9) comp-5 value 0.
01 length-of-title-bar-buffer pic s9(9) comp-5.
01 title-bar-buffer-max pic s9(9) comp-5.
01 title-bar-buffer pic x(1025) value spaces.
01 hwnd-type pic 9(9) comp-5.
01 null-value pic s9(9) comp-5 value 0.
linkage section.
01 title-bar-string pic x(1024).
01 found-window-sw pic 9(4) comp-5.
01 found-window-handle pic s9(9) comp-5.
01 return-value pic s9(9) comp-5.
procedure division using title-bar-string, found-window-sw, found-window-handle, return-value.
move 0 to return-value
move 0 to found-window-sw
move 0 to found-window-handle
compute title-bar-buffer-max = function length(title-bar-buffer)
*
* Let's make sure they passed the title bar string
*
if title-bar-string not > " "
move 1 to return-value
exit program
end-if
*
* Let's get the handle of this window
*
call "GetTopWindow" with STDCALL using
by value null-value
returning this-window-handle
*
* Now, let's find the length of the search string
*
move title-bar-string to title-bar-search-string
perform varying title-bar-index from 1025 by -1
until title-bar-search-string(title-bar-index:1) not = " "
continue
end-perform
*
* Now, let's get the first window
*
move gw_hwndfirst to hwnd-type
call "GetWindow" with STDCALL using
by value this-window-handle
by value hwnd-type
returning child-window-handle
if child-window-handle = 0
move 3 to return-value
exit program
end-if
move gw_hwndnext to hwnd-type
*
* Now, let's see if this is the target window, if not, loop through all open windows
*
perform until child-window-handle = 0
*
* Let's get the title bar text of this window
*
call "GetWindowTextA" with STDCALL using
by value child-window-handle
by reference title-bar-buffer
by value title-bar-buffer-max
returning length-of-title-bar-buffer *> Note, the length returned does NOT include the NULL byte
*
* If the window has a title bar, is it the one we're looking for?
*
if length-of-title-bar-buffer > 0
if title-bar-search-string(1:title-bar-index) = title-bar-buffer(1:title-bar-index)
move 1 to found-window-sw
move child-window-handle to found-window-handle
move 0 to return-value
exit program
end-if
end-if
*
* Get the next window
*
move child-window-handle to this-window-handle
call "GetWindow" with STDCALL using
by value this-window-handle
by value hwnd-type
returning child-window-handle
end-perform
*
* Didn't find the window
*
move 0 to return-value
move 0 to found-window-sw
move 0 to found-window-handle
exit program