Solved

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

Posted on 2003-11-21
7
360 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now