Solved

EnumChildWindows does not work on Windows NT, any solutions..?

Posted on 2003-11-21
7
367 Views
Last Modified: 2010-04-05
Hello!

I've been working on a project that gets data from a VB app. Everything works fin but not on Windows NT. I've been working hard to work around this with ex. GetWindow in some way but with no success. Any way to solve this??

Thanks,
Hokki
0
Comment
Question by:hakanfa
7 Comments
 
LVL 2

Expert Comment

by:Robn
ID: 9797156
According to the SDK, EnumChildWindows is supported on NT. Are you sure your code is correct?
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9797262
If you use the function from a service you have to set "Allow service to interact With Desktop" for the service.
0
 

Author Comment

by:hakanfa
ID: 9798825
Yes I am for shore. Been testing i alot of times.. Answer to the second comment: It is a standalone exe in question...
(the NT 4.0 has SP 6)
Hokki
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:Robn
ID: 9798874
I have used EnumWindows with no problems on NT (not exactly the same but maybe you'll find this works as well).

call this method    
EnumWindows(@EnumWindowsProc, 0);

implimentation of EnumWindowsProc

function EnumWindowsProc(hwnd: THandle; lParam: LPARAM): Boolean; stdcall;
var
  pClassName: Array[0..255] of char;
begin
  Result := True;
  if Windows.GetClassName(hWnd, pClassName,      SizeOf(pClassName)) = 0 then exit;
  if StrComp(pClassName, 'Classname of the form I am looking for') <> 0 then exit;
  // Do something with the handle.
end;

Hope this helps,
Rob
0
 

Author Comment

by:hakanfa
ID: 9799368
Does this function enumerate childwindows too?
Will test it...just asking..

The problem is that some of the user is usin Win 200, all works fine, but the major part of the users are using NT 4.0 and the
EnuChildWindows is not working on their machines anyway.. I tried the GetWindw and it returnes the handles but not childwindow
handles..
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 400 total points
ID: 9800569
No, you must use the EnumChildWindows callback to get any child window handles.
Here is some code, based upon an EnumWindows post by Ralph Friedman, that gets
the address dropdown of IE. Works on any Windows OS.

function EnumIEChildProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
var
  tmpS : string;
  theClassName : string;
  theWinText : string;
begin
  Result := True;
  SetLength(theClassName, 256);
  GetClassName(AHandle, PChar(theClassName), 255);
  SetLength(theWinText, 256);
  GetWindowText(AHandle, PChar(theWinText), 255);
  tmpS := StrPas(PChar(theClassName));
  if theWinText <> EmptyStr then
    tmpS := tmpS + ' "'
            + StrPas(PChar(theWinText)) + '"'
  else
    tmpS := tmpS + '""';
  if Pos('Edit', tmpS) > 0 then
  begin
    EditHandle := AHandle;
  end;
end;

function IEWindowEnumProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
// callback for EnumWindows.
var
  theClassName: string;
  theWinText: string;
  tmpS: string;
begin
  Result := True;
  SetLength(theClassName, 256);
  GetClassName(AHandle, PChar(theClassName), 255);
  SetLength(theWinText, 256);
  GetWindowText(AHandle, PChar(theWinText), 255);
  tmpS := StrPas(PChar(theClassName));
  if theWinText <> EmptyStr then
    tmpS := tmpS + ' "'
            + StrPas(PChar(theWinText)) + '"'
  else
    tmpS := tmpS + '""';
  if Pos('IEFrame', tmpS) > 0 then
  begin
    EnumChildWindows(AHandle, @EnumIEChildProc, longInt(0));
  end;
end;

procedure TForm1.FindIEEditHandle;
begin
  Screen.Cursor := crHourGlass;
  try
    EnumWindows(@IEWindowEnumProc, LongInt(0));
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  caption: Array [0..127] of Char;
  s: String;
begin
  FindIEEditHandle;
  if EditHandle > 0 then
  begin
    SendMessage(EditHandle, WM_GETTEXT, Sizeof( caption ), integer(@caption));
    s := Caption;
    s := StringReplace(s, '&', '&&' , [rfReplaceAll, rfIgnoreCase]);
    Label1.Caption := s;
  end
  else
    label1.Caption := 'Not Found';
end;
0
 

Author Comment

by:hakanfa
ID: 9803471
Great! You're a genius! Works lika a charm!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question