Process still active when application exits

This is a discussion on Process still active when application exits within the Windows Programming forums, part of the Platform Specific Boards category; I noticed that when I close my window it is still in the active process's list when I hit ctrl-alt-del ...

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Process still active when application exits

    I noticed that when I close my window it is still in the active process's list when I hit ctrl-alt-del on my XP box. This happens no matter what except when i try to debug. Anyone know why it happens? Well ill post the code here:
    Main.cpp

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {	
    	CBWin cWin = CBWin(hInstance, "My Window", 300,300, 300, 200);
    
    	if(!cWin.Create(WS_OVERLAPPED | WS_SYSMENU, WS_EX_APPWINDOW))
    	{	return(0);
    	}
    	cWin.Show(SW_SHOW);
    	//::UpdateWindow(cWin.GetHandle());
    	
    	MSG msg;
    	HWND hWnd = cWin.GetHandle();
    
    	while(::GetMessage(&msg,hWnd,0,0))
    	{	if(!IsDialogMessage(hWnd,&msg))
    		{	TranslateMessage(&msg);
    			DispatchMessage(&msg);				
    		}	
    	}
    	return(msg.wParam);
    }
    CBWin.H
    Code:
    #ifndef __CBWIN_H__
    #define __CBWIN_H__
    
    #ifndef WIN32_LEAN_AND_MEAN
    #define WIN32_LEAN_AND_MEAN
    #endif
    
    #include<Windows.h>
    #include<string>
    using std::string;
    
    #define CNAME "CBWIN"
    
    class CBWin{
    	public:
    		CBWin();
    		//Pre:  None
    		//Post:
    
    		CBWin(const HINSTANCE& hInstance, const string& strWindowName, const UINT& uiXPos, const UINT& uiYPos, 
    			  const UINT& uiXSize, const UINT& uiYSize);
    		~CBWin();
    		//Pre:
    		//Post:
    
    		BOOL Create(const DWORD& dwStyle, const DWORD& dwExStyle);
    		//Pre:
    		//Post:
    
    		BOOL Show(int nShow);
    		//Pre:
    		//Post:
    
    		const HWND& GetHandle() const;
    
    	private:
    		//typedef unsigned int UINT;
    
    		HWND		hCBWin;
    		HINSTANCE	hInst;
    		string		strWName;
    		UINT		uiWidth;
    		UINT		uiHeight;
    		UINT		uiX;
    		UINT		uiY;
    		BOOL		bInitFail;	// True indicates creation faiure
    
    		BOOL	RegisterWindow();
    		//Pre:  Takes a UINT parameter representing styles to add to the WNDCLASSEX struct
    		//Post: Registers a default window w/ styles of CS_OWNDC, CS_VREDRAW, CS_HREDRAW,
    		//      CS_DBLCLKS, returns TRUE if reigstration was successful
    
    		BOOL	BuildWindow(const DWORD& dwStyle,const DWORD& dwExStyle);
    		//Pre:  Recieves two DWORDS, the window style and the extended window style
    		//Post: Returns TRUE if the Creation was succesful, FALSE if not
    
    		static LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    	
    	protected:
    		virtual LRESULT CALLBACK WindowProc(const HWND& hWnd, const UINT& Msg, const WPARAM& wParam, const LPARAM& lParam);
    		//Pre:
    		//Post:
    };
    
    #endif
    and CBWin.cpp
    Code:
    #include"CBWin.h"
    
    CBWin::CBWin()
    :	hCBWin(NULL), hInst(NULL), uiX(100), uiY(100), uiWidth(300), uiHeight(200), strWName("Window"), bInitFail(TRUE)
    {
    }
    
    CBWin::CBWin(const HINSTANCE& hInstance, const string& strWindowName, const UINT& uiXPos, const UINT& uiYPos,
    			 const UINT& uiXSize, const UINT& uiYSize)
    :	hCBWin(NULL), hInst(hInstance), strWName(strWindowName), uiX(uiXPos), uiY(uiYPos), uiWidth(uiXSize),
        uiHeight(uiYSize), bInitFail(FALSE)
    {
    }
    
    CBWin::~CBWin()
    {	::UnregisterClass(CNAME,hInst);
    	hCBWin = NULL;
    	hInst = NULL;
    }	
    
    BOOL CBWin::Create(const DWORD& dwStyle, const DWORD& dwExStyle)
    {	if(!bInitFail && !RegisterWindow())
    	{	bInitFail = TRUE;
    	}
    	if(!bInitFail && !BuildWindow(dwStyle,dwExStyle))
    	{	bInitFail = TRUE;
    	}
    	return(!bInitFail);
    }
    
    BOOL CBWin::Show(int nShow)
    {	BOOL bShow = TRUE;
    	if(!::ShowWindow(hCBWin,nShow))
    		bShow = FALSE;
    	return(bShow);
    }
    
    const HWND& CBWin::GetHandle() const
    {	return hCBWin;
    }
    
    BOOL CBWin::RegisterWindow()
    {	::WNDCLASSEX wndClass;
    
    	ZeroMemory(&wndClass,sizeof(WNDCLASSEX));
    
    	wndClass.cbSize = sizeof(WNDCLASSEX);
    	wndClass.hInstance = hInst;
    	wndClass.lpszClassName = CNAME;		// Defined in CBWin.h
    	wndClass.lpszMenuName = NULL;
    	wndClass.hIcon = ::LoadIcon(NULL,IDI_APPLICATION);
    	wndClass.hIconSm = ::LoadIcon(NULL,IDI_APPLICATION);
    	wndClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
    	wndClass.hCursor = ::LoadCursor(NULL,IDC_ARROW);
    	wndClass.lpfnWndProc = WndProc;
    	wndClass.style = CS_HREDRAW | CS_VREDRAW;
    	
    	if(!RegisterClassEx(&wndClass))
    	{	::MessageBox(NULL,"ERROR REGISTERING WNDCLASSEX","CRITICAL ERROR", MB_ICONERROR | MB_OK);
    		return(FALSE);
    	}
    	return(TRUE);
    }
    
    BOOL CBWin::BuildWindow(const DWORD& dwStyle, const DWORD& dwExStyle)
    {	if(!bInitFail) // if there was no problem registering the window
    	{	hCBWin = CreateWindowEx(dwExStyle,			
    								CNAME,				// Class Name
    								strWName.c_str(),	// Window Name
    								dwStyle,			
    								uiX,				// X Pos
    								uiY,				// Y Pos
    								uiWidth,			// Width
    								uiHeight,			// Height
    								NULL,				// Handle to parent window
    								NULL,				// Handle to MENU
    								hInst,				// Application Instance
    								(LPVOID)this);
    		if(!hCBWin)
    		{	::MessageBox(NULL,"ERROR CREATING WINDOW","CRITICAL ERROR", MB_ICONERROR | MB_OK);
    			return(FALSE);
    		}
    		return(TRUE);
    	}
    	return(FALSE);
    }
    
    LRESULT CALLBACK CBWin::WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {	static CBWin* pCWin;
    	
    	switch(Msg)
    	{	case WM_NCCREATE:
    		{	LPCREATESTRUCT lpCS = (LPCREATESTRUCT)lParam;
    			pCWin = (CBWin*)lpCS->lpCreateParams;
    			
    			::SetWindowText(hWnd,lpCS->lpszName);
    			return(::DefWindowProc(hWnd,Msg,wParam,lParam));
    		}
    		case WM_CLOSE:
    		{	::DestroyWindow(hWnd);
    			return(0);
    		}
    		default:
    		{	if(pCWin)
    			{	return(pCWin->WindowProc(hWnd,Msg,wParam,lParam));
    			}
    			else
    				return(::DefWindowProc(hWnd,Msg,wParam,lParam));
    		}
    	}
    }
    
    LRESULT CALLBACK CBWin::WindowProc(const HWND& hWnd, const UINT& Msg, const WPARAM& wParam, const LPARAM& lParam)
    {	switch(Msg)
    	{	
    		case WM_DESTROY:
    		{	::PostQuitMessage(0);
    			return(0);
    		}
    		default:
    			return(::DefWindowProc(hWnd,Msg,wParam,lParam));
    	}
    }
    Thanks in advance if you see why this doesnt work how it should.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Heres a copy of the source and VC.NET workspace in zip format of course.
    Attached Files Attached Files
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  3. #3
    Unregistered
    Guest
    Find some working code and compare the message loop in it with the one you have.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Hi xds4lx,

    I don't have/use vc.net so I used msvc6. This sort of thing used to happen to me heaps (still occasionally does ) and can be quite irritating. Anyway in your WinMain msg loop if you replace:
    Code:
    while(::GetMessage(&msg,hWnd,0,0))
    with:
    Code:
    while(::GetMessage(&msg,0,0,0))
    ie set second param of GetMessage to NULL then the process dies with the window. I'd be interested to know if this works out ok with vc.net.

    Good luck anyway.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    >Not only didn't you bother to look at the code

    I looked at the code. There wasn't much point in downloading the sample because as stated in my response the problem was with the message loop, which you then spelt out in baby language to the OP.

    >Your remark here has zero content or value and is in fact, no more nor less than you as an individual are: a complete and utter waste of time and space<

    What?? I pointed to the area where the problem is (the message loop). What's your problem; lack of reading skills.

  6. #6
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Haha thanks I noticed my mistake earlier, but thats what you get when your in a rush to get something done you should of a while ago (<--- major slacker at work) instead of chatting with friends who have moved to other states.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    >Add feeble liar to the list.

    You're losing me here. Where exactly am I lying? What in the original question refers to the message loop?

    I noticed that when I close my window it is still in the active process's list when I hit ctrl-alt-del on my XP box. This happens no matter what except when i try to debug. Anyone know why it happens?
    hmm....

    Even if I had no idea what the op was talking about and for some reason posted it to attempt to be an ass. I wouldn't have done a very good job as my post tells him/her exactly how to fix their problem; by comparing their message loop with one from a properly functioning program (shouldn't be too hard as it's only 7 lines of code).

    >Read it all again but this time dissociate your lying ego from your interpretaive faculties.
    <

    What is your problem?

    >Most people around here, if they fail to log-on at first attempt, usually post a follow up to identify themselves as the poster.<

    Sorry my cookies weren't updated. I really wasn't expecting my post to have that much impact (a simple answer to a simple problem) so I decided it wasn't worth slapping my lying ego all over it.

    > commend that you have now come forward and identified yourself. Accordingly I respectfully withdraw the word 'coward' from my previous rant.<

    Thank you. Perhaps I can slowly re-intergrate myself into the decent folk community. I might need some help from such fine upstanding citizens such as yourself but I think I can make it.

    >I have nothing more to say on the matter.<

    Perhaps you better go and have a lie down.

  8. #8
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    /me comes to the defense of FDiddy ally

    the fact that you are too lazy to even find a working example yourself speaks for the action aptly. If not even you wanted to do it, then why would he?

    In other news, your post didn't help at all. Since it is just "seven" lines of code and you are SO smart, why don't you copy and paste those wonderful seven lines of code from your bugless program to illustrate this poor boy's errors? I'm sure that was the LEAST you, as an upstanding member of cprog, could do, if you were going to post at all.

  9. #9
    Ken Fitlike
    Guest
    I apologise for my earlier rude outburts which were not necessary.

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Just to confirm that last post/apology was really from me.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    /another Fdiddy backup joins the fight

    echo Aran on this one... if it's so simple, point the solution out. Take 2 minutes of your time and offer a code sample. It's not gonna kill you.
    EntropySink. You know you have to click it.

  12. #12
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Enmerdemonkey, you son of a Bestial mother, why don't you respond in full! This young man was simply trying to discover his error, he did not want to solve riddles. He is not a psychic. For all we know this could be the most important thread this place will ever see. May the Lord have mercy on your soul. Blessed be the children. You're a demon, a baby killer. Do not post here again until you pray.

  13. #13
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    >the fact that you are too lazy to even find a working example yourself speaks for the action aptly. If not even you wanted to do it, then why would he?

    >

    and

    >another Fdiddy backup joins the fight

    echo Aran on this one... if it's so simple, point the solution out. Take 2 minutes of your time and offer a code sample. It's not gonna kill you.<

    I think you've got things mixed up here. I wasn't the one asking for help; why should I have to do it? I wasn't withholding the solution to try and be awkward/lazy/whatever; I was merely pointing the person in the right direction. I think you'll find this is done in quite a few responses to questions here and elsewhere. If somebody thinks this is inappropriate then there's nothing stopping them from posting the line that needed changing.

    I'm not quite sure how my actions warranted the subsequent outburst regardless of your opinion or loyalty to your fellow fdiddy and can only assume that Mr Fitlike was having a bad day.

  14. #14
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Enough!

    The question has been answered.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Almost finished with Round Robin algorithm
    By Shinobi-wan in forum C++ Programming
    Replies: 2
    Last Post: 12-19-2004, 03:00 PM
  2. Linux: Send keyboard input to background process
    By xErath in forum Tech Board
    Replies: 2
    Last Post: 12-09-2004, 07:02 PM
  3. passing a connection to another process.
    By Kinasz in forum Networking/Device Communication
    Replies: 3
    Last Post: 10-09-2004, 06:34 PM
  4. Child window with active (highlighted) title bar: Possible?
    By JasonD in forum Windows Programming
    Replies: 7
    Last Post: 10-16-2003, 07:43 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21