954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ShowWindow(hWnd, SW_HIDE); Does not work -- Only with "SW_HIDE" ???

Heya i want to use ShowWindow(hWnd, SW_HIDE); to hide some application,

The problem is that the code i wrote works perfectly for any application except the one i need it for

heres the code

HWND hWnd = FindWindow(NULL, sName);
if(hWnd)
{
	ShowWindow(hWnd, SW_HIDE);
}


it does execute the line "ShowWindow(hWnd, SW_HIDE);" but it has no affect on the application, while if i put "SW_MAXIMIZE" , "SW_MINIMIZE" or any other "SW_***" it works perfectly and does manipulation on the application window,

Any idea why SW_HIDE does not work while all other SW_*** works?


Thanks Ahead....

vedmack
Junior Poster in Training
59 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Try calling ShowWindow twice, according to MSDN the second parameter to ShowWindow() might get ignored the first time it is called. I don't know if it will work, but its worth a try.

HWND hWnd = FindWindow(NULL, sName);
if(hWnd)
{
	ShowWindow(hWnd, SW_HIDE);
	ShowWindow(hWnd, SW_HIDE);
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
Try calling ShowWindow twice

Is it a joke ?!

marco93
Junior Poster
132 posts since Apr 2008
Reputation Points: -76
Solved Threads: 14
 

Does it happens with all the Windows or with any specefic Window ?
Are you trying to hide any window which you have created or any other applciaiton's Window ?

dubeyprateek
Junior Poster
176 posts since Mar 2006
Reputation Points: 39
Solved Threads: 24
 

The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown.

I suspect the window you are trying to hide processes this message and prevents itself from hiding.

You might use Spy++ to see wheather or not this notification is send to the target Window.

dubeyprateek
Junior Poster
176 posts since Mar 2006
Reputation Points: 39
Solved Threads: 24
 
Is it a joke ?!

No. Did you read the link I posted? MSDN says the first time ShowWindow is called SW_HIDE might be ignored. After that SW_HIDE parameter is honored.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

thx 4 the help Ancient Dragon, i will try it and will post the results...

vedmack
Junior Poster in Training
59 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Hi again... I found the solution...

1)This phenomenon happens with only one specific window...

2)To force this window to hide I do need call the "ShowWindow(hWnd, SW_HIDE);" Twice in the following way:

myClass::FocusP(str);
myClass::Hidep(str);
...
...
...
void myClass::FocusP(CString str)
{
	HWND hWnd = FindWindow(NULL, str);
	if(hWnd){
		ShowWindow(hWnd, SW_MINIMIZE);
		ShowWindow(hWnd, SW_HIDE);
		
	}
}

void myClass::Hidep(CString str)
{
	HWND hWnd = FindWindow(NULL, str);
	if(hWnd){
		ShowWindow(hWnd, SW_HIDE);
	}
}


I could call twice the myClass::FocusP(str); twice, but i prefered to split it... looks better IMO


Thx 4 the help Ancient Dragon and others...

vedmack
Junior Poster in Training
59 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You