close all

I want to close all windows on the desktop. either they are minimised or maximised state i want to close all windows. which functions i have to use??
give me sample code..

thank u for answer..
chowdary010899Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

U can use EnumWindows For this operation. Follow the following Steps

1. Declare a function as global
    BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM     lparam);

2.Put the following code where U want to close all windows
   EnumWindows((WNDENUMPROC)EnumWindowsProc , 0);

3. Write the declared function as

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM       lparam)
{
     PostMessage(hwnd, WM_CLOSE, 0, 0);
     return 1;
}

Thats it, all windows will closed!!!.

Hope it helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vinayak KumbarSr Program ManagerCommented:
Hi,

If U want U can customise the function EnumWindowsProc(),

U can get the windowtext using hwnd, then compare it to close some of the windows only.(definitly U dont want to close Ur own application window right?. Then get the window text using ::GetWindowText() and if it matches with Urs then dont post that message.)

Try it out.
0
chowdary010899Author Commented:
Thanx for your response.. Whatever ur advise is correct but My application won't show any window on the desktop..
It will run as a service..

 one more thing.. If i use enumwindows function it is showing system shutdown dialog, after closing the all applications.it should not show that dialog and should not close my application, But it should close all others.. please get me solution..If u give ur email i will be happy.. :o)

Thanx for ur answer.. Mr Vinexpert..
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

chowdary010899Author Commented:
Thanx for your response.. Whatever ur advise is correct but My application won't show any window on the desktop..
It will run as a service..

 one more thing.. If i use enumwindows function it is showing system shutdown dialog, after closing the all applications.it should not show that dialog and should not close my application, But it should close all others.. please get me solution..If u give ur email i will be happy.. :o)

Thanx for ur answer.. Mr Vinexpert..
0
chowdary010899Author Commented:
Thanx for your response.. Whatever ur advise is correct but My application won't show any window on the desktop..
It will run as a service..

 one more thing.. If i use enumwindows function it is showing system shutdown dialog, after closing the all applications.it should not show that dialog and should not close my application, But it should close all others.. please get me solution..If u give ur email i will be happy.. :o)

Thanx for ur answer.. Mr Vinexpert..
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

I was waiting for Ur response. Okay, It will show that shut down message as program manager is also closed.

So After calling ::GetWindowText(), store the text in CString variable say l_strText and  if it is the program manager, then dont close it.

U may have to do something like this.
if(l_strText.Find("Program") == -1)
      PostMessage(hwnd, WM_CLOSE, 0, 0);

Do the same for Ur application also. Say if Ur application has the window text as "EnmWinws" (usually the application will have the title as the project itself), then
if((l_strText.Find("Program") == -1) && (l_strText.Find("EnmWinws") == -1)
      PostMessage(hwnd, WM_CLOSE, 0, 0);

Try it out.

Pls Note: One click on the Submit button is sufficient.(why               thrice?. Sorry I am not serious)

0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Give me Ur email ID, I will send U the sample workspace.
0
chowdary010899Author Commented:
My mail id is ksuneel@hotmail.com cyber friend..
:o)

thank u...
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

I have sent the zipped workspace to Ur ID. Check it out.
If there are any probs, tell me.

Good Luck.
0
chowdary010899Author Commented:
Hi VinExpert :)

Thank u friend...Its enough for me. if i want any help i will mail u or i will place question in this..

CHOWDARY
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.