Solved

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

Posted on 2003-11-21
7
362 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 111
Print Graphic and Text to Epson TM-T88v 12 247
How to debug For loops? 3 49
Performance of SQL statement 37 111
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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