Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide window of other app?

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
0
0
GB
Hi, just wondering if there is a way to hide a window created by a different application? I don't want to close it (unless there is a way to without it doing all the stuff it normally does on shutdown), just hide it. I know what the name of the window will be.
 
Hi KempCGDR,

Just Post it a WM_HIDE Message( PostMessage API ) or
kill it( under Nt/2000/XP ).

Cheers,

Andrew
 
Obvious now that I think about it (I played around with this sort of stuff for a while at one point, never got it to work properly but meh). Unfortunately, I'm stuck with D3 right now and the help files don't help, they have nothing on that, so could you give me an example? Assume the window title is 'A Program'. Thanks
 
Hi KempCGDR,

FindWindow to find the Window handle based on title and/or
class name.

Use then PostMessage like this:

PostMessage( Handle,WM_Hide,0,0 );

Should work.

Cheers,

Andrew

P.S. Remember to include the "Windows" unit, if it's not
already present!
 
I think I've done it right now, but unfortunately WM_HIDE is an undeclared identifier apparently, do you know the actual value of the constant so I can put that in instead? I did include the Windows unit, I can only assume it's because of my seriously out-of-date version of Delphi (must upgrade, must upgrade).

Btw, if you want a ' in a string you just double it up right? So you would get (for example) 'Kemp''s string'.
 
And while I think about it:

1) What value is returned from FindWindow when the window doesn't exist?
2) Would FindWindow work as:
Code:
Handle := FindWindow('','Window name here');
?

At the moment I have
Code:
   Handle := FindWindow('','Window name here');
   PostMessage( Handle,WM_Hide,0,0 );
 
Hi KempCGDR,

Sorry, my bad. Look at the help about WM_SHOWWINDOW.

HTH,

Andrew
 
In delphi 6, you can find it the help menu under "Windows SDK"

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Unfortunately, I'm stuck with D3 right now and the help files don't help

From previous post
 
Sorry, I didn't read the whole thread very carefully (which I guess is obvious).

Can you try something like this?:

procedure Hidewindow(AWindowName:string);
begin
h := Findwindow(nil,AWindowName);
ShowWindow(h,sw_Hide);
end;


sw_Hide = 0, according to the delphi debugger.

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Ok, so I have

Code:
   Handle := FindWindow(nil,'Window name');
   ShowMessage(inttostr(Handle));
   PostMessage( Handle,0,0,0 );

And it doesn't do anything. It reports
Code:
Handle
as being somewhere in the hundreds of thousands range, it can't be right can it? Other than that, no effect, no error messages, no window vanishing, nothing.
 
Hi KempCGDR,

This time's your bad! ^_^

ShowWindow is different from PostMessage!

Use ShowWindow with a 0 argument, after FindWindow.

Cheers,

Andrew
 
Doh, must have missed the point where you changed advice. I'll try it and get back.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top