Solved

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

Posted on 2003-11-21
7
356 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now