O
O-('' Q)
Hi all.
I am looking for help in converting this delphi code to C#.net form. I
am having trouble getting it right as I am still learning (I know this
may be advanced for me in c#) right now. What this code does is it
searched, with a wild card, for a window mathing the string passed to
the function and then returns the hWnd to the calling function.
Any help converting this is much appreciated. I am using Visual Studio
2005 C#.NET if this helps any.
[CODE BEGIN]
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;
//frmMain.ListBox1.Items.Add(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 END]
-- Kirby
I am looking for help in converting this delphi code to C#.net form. I
am having trouble getting it right as I am still learning (I know this
may be advanced for me in c#) right now. What this code does is it
searched, with a wild card, for a window mathing the string passed to
the function and then returns the hWnd to the calling function.
Any help converting this is much appreciated. I am using Visual Studio
2005 C#.NET if this helps any.
[CODE BEGIN]
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;
//frmMain.ListBox1.Items.Add(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 END]
-- Kirby