Problem with closing my application

This is a discussion on Problem with closing my application within the Windows Programming forums, part of the Platform Specific Boards category; Im getting this error after I run my program and then close it and try re-compiling. --------------------Configuration: Code - Win32 ...

  1. #1
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    Posts
    114

    Problem with closing my application

    Im getting this error after I run my program and then close it and try re-compiling.
    --------------------Configuration: Code - Win32 Debug--------------------
    Compiling...
    main.cpp
    c:\documents and settings\owner\desktop\lightning round\code\main.cpp(0) : fatal error C1033: cannot open program database 'c:\documents and settings\owner\desktop\lightning round\code\debug\vc60.pdb'
    Error executing cl.exe.

    Code.exe - 1 error(s), 0 warning(s)


    Here is my handler.

    Code:
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    {
    PAINTSTRUCT ps;
    HDC hdc;
    switch(msg){
    case WM_CREATE:
    	{
    		HDC hdc = GetDC(hwnd);
    		COLORREF TextColor = RGB(0,175,0);
    		SetTextColor(hdc,TextColor);
    		SetBkMode(hdc,TRANSPARENT);
    		return(0);
    	}break;
    case WM_PAINT:
    	{
    		hdc = BeginPaint(hwnd,&ps);
    		TextOut(hdc,55,40,"Username:",strlen("Username:"));
    		TextOut(hdc,55,80,"Password:",strlen("Password:"));
    		EndPaint(hwnd,&ps);
    		return(0);
    	}break;
    case WM_CLOSE:
    	{
    		PostQuitMessage(0);
    		return(0);
    	} break;
    case WM_DESTROY:
    	{
    		PostQuitMessage(0);
    		return(0);
    	} break;
    default:break;
    }
    return(DefWindowProc(hwnd,msg,wparam,lparam));
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I think the problem is that it is still hanging out in your process list due to improper handling of the WM_CLOSE message. WM_CLOSE is supposed to initiate a DestroyWindow call (::DefWindowProc does this for us if you don't specify it!) which kills child and the owner windows. So basically, you can just take out handling of the WM_CLOSE message out of your code, or implicitely call DestroyWindow from it which will then post a WM_DESTROY and you PostQuite Message, etc.

    Code:
    switch(message)
    {
       WM_MESSAGE: ...;
       WM_MESSAGE: ...;
       // Not needed WM_CLOSE: DestroyWindow(hwnd); break;
       WM_DESTROY: PostQuitMessage(0); break;
    }

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    If you return false (zero) to a message you are telling the OS / app that you have done all processing required (and so not to do anything else).

    If you return true (non zero) then the OS / app will do the default processing (ie call destroywindow) as well as what you did.

    In this case your WM_CLOSE should be empty or simply ask the user if they are sure they want to quit.

    If you are not sure let the default handler DefWindowProc() do the work.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Application closing by default?
    By Blackroot in forum Windows Programming
    Replies: 2
    Last Post: 07-31-2008, 01:34 AM
  2. Problem ending application
    By rbrodbeck in forum C Programming
    Replies: 6
    Last Post: 07-17-2008, 03:44 PM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  5. Dev Resource problem
    By algi in forum Windows Programming
    Replies: 3
    Last Post: 04-19-2005, 03:53 PM

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