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?
 
Vinayak KumbarConnect With a Mentor Sr 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
 
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
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on 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
All Courses

From novice to tech pro — start learning today.