Hello and sorry if this is the wrong group for this.
I am looking to translate some delphi code to .Net/C++ style code. I've
tried, but it is simply a mess as I am still learning. I got it to
compile once, but it never worked as intended and it would sometimes
crash on me.
Here is the code:
[code]
function HWndGet(partialTitle: string): hWnd;
var
hWndTemp: hWnd;
iLenText: Integer;
cTitletemp: array [0..254] of Char;
sTitleTemp: string;
begin
//find first window and loop through all subsequent windows in the
master window list
hWndTemp := FindWindow(nil, nil);
while hWndTemp <> 0 do
begin //retrieve caption text from current window
iLenText := GetWindowText(hWndTemp, cTitletemp, 255);
sTitleTemp := cTitletemp;
//clean up the return string, preparing for case insensitive
comparison
sTitleTemp := UpperCase(copy( sTitleTemp, 1, iLenText));
//use appropriate method to determine if the current window's
caption
//either starts with or contains passed string
partialTitle := UpperCase( partialTitle );
if pos( partialTitle, sTitleTemp ) <> 0 then
break;
//get next window in master window list and continue
hWndTemp := GetWindow(hWndTemp, GW_HWNDNEXT);
end;
result := hWndTemp;
end;
[code]
This basically goes through all open windows to find any window which
contains the word passed to partialTitle. It then returns the hWnd of
the window it finds to the calling function.
I am lost with this one, hehe. It may be too much for someone just
learning, but I have gone too far in this application to stop now I
guess. So, any help on this would be greatly appreciated.
Thanks in advance.
|