Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-21
7
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1600 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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