Link to home
Start Free TrialLog in
Avatar of yingkit
yingkit

asked on

Findwindow?

Hi,
A simple question, so here is only 5 points. ^_^
For examples, THREE windows with the same caption and same class.  I used the following code:
ShowWindow(FindWindow(pchar('Caption'),pchar('ClassHere')),SW_HIDE);
Even execute the above code three times, I can still only hide one of them, how can I hide ALL of them?  And if I want to hide only two of them, how can I do so?
PS.  Full source codes required.
Avatar of kotik
kotik

Try to use EnumWindows function.
Avatar of yingkit

ASKER

Edited text of question.
Full source for 5 points? :))
hehehe
sounds good ;)
var
  bCount: Byte;

function MyEnumWindowsProc(h: HWND; p: Longint): longBool; stdcall;
begin
  GetWindowText(h, @WinCaption[0], 100);
  if StrPas(@WinCaption[0]) = 'Rechner' then begin
    Inc(bCount);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  li: Longint;
begin
  bCount := 0;
  EnumWindows(@MyEnumWindowsProc, li);
  MessageDlg('found ' + IntToStr(bCount) + ' times', mtInformation,
    [mbOk], 0);
end;

this one counts the instances of the calculator (in german: 'Rechner') -

in MyEnumWindowsProc u can do whatever u wanna do with the found window.

i think this should b enough 4 5 points. figure out what's to b done now by yourself or adjust the points.

;-)

BlackDeath.
ok, ok - var WinCaption: array[0..99] of Char;

;-))

BlackDeath.
I like your answer. I used a list box to store the window captions. I only had a two programs running. There was about 100 items. Wow.
Avatar of yingkit

ASKER

Hee....thank BlackDeath for the answers.  You may submit your comments as answer, I'll increase the points and grade it.
Thanks!
>>I only had a two programs running. There was about 100 items. Wow

hi calvin,
once i did a postmessage with wm_syscommand and scminimize in  a loop and used the wrong handle for sending.you should have seen all the windows that appeared in the taskbar ..
its amazing how many there are when even nothing running :-)
ASKER CERTIFIED SOLUTION
Avatar of BlackDeath
BlackDeath

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yingkit

ASKER

Adjusted points to 20
-'B'-?