Click here to Skip to main content
15,888,286 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionVC++ MFC QT Qwt OPENGL based application JOB WANTED CAD/CAM/CAE/FEA/CFD Pin
appollosputnik29-Apr-10 20:50
appollosputnik29-Apr-10 20:50 
AnswerRe: VC++ MFC QT Qwt OPENGL based application JOB WANTED CAD/CAM/CAE/FEA/CFD PinPopular
Rajesh R Subramanian29-Apr-10 21:57
professionalRajesh R Subramanian29-Apr-10 21:57 
GeneralRe: VC++ MFC QT Qwt OPENGL based application JOB WANTED CAD/CAM/CAE/FEA/CFD Pin
ThatsAlok2-May-10 20:08
ThatsAlok2-May-10 20:08 
QuestionHandling a process termination. Pin
progDes29-Apr-10 20:13
progDes29-Apr-10 20:13 
AnswerRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 20:47
Michel Godfroid29-Apr-10 20:47 
GeneralRe: Handling a process termination. Pin
progDes29-Apr-10 21:32
progDes29-Apr-10 21:32 
GeneralRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 21:42
Michel Godfroid29-Apr-10 21:42 
AnswerRe: Handling a process termination. [modified] Pin
Software_Developer29-Apr-10 20:53
Software_Developer29-Apr-10 20:53 
Yes there is, its called WM_QUIT. A Win32 Message. You must create a Win32 app for this code.
This app is not a console app , its a windows app and will use int WinMain() instead of int main().

PeekMessage() looks into the message queue and checks to see if any messages are waiting. If not, the program will continue on.

If our message is WM_QUIT, then that means its time to exit and return to Windows.
// example code snippet

#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
 
      case WM_QUIT:
                           // Normal exit
                           // put stuff to do before exiting here
      break;
       
      case WM_CLOSE:
			// Abnormal termination	
			// put stuff to do before exiting here
                        // this only works if you terminate	 the window from Taskmanager's "end task"
                        
                MessageBox(NULL, "user terminated the window from Taskmanager!", "abnormal exit" , MB_OK);
        	DestroyWindow(hWnd);
         
      break;
      
      case WM_DESTROY:
      
         	PostQuitMessage(0);
      break;
      default:
         return DefWindowProc(hWnd, message, wParam, lParam);
   }

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "The title of my window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}


And thats it.
GeneralRe: Handling a process termination. Pin
progDes29-Apr-10 21:35
progDes29-Apr-10 21:35 
GeneralRe: Handling a process termination. Pin
Software_Developer29-Apr-10 22:36
Software_Developer29-Apr-10 22:36 
GeneralRe: Handling a process termination. Pin
progDes29-Apr-10 23:04
progDes29-Apr-10 23:04 
GeneralRe: Handling a process termination. [modified] Pin
Software_Developer30-Apr-10 0:26
Software_Developer30-Apr-10 0:26 
GeneralRe: Handling a process termination. Pin
progDes30-Apr-10 0:49
progDes30-Apr-10 0:49 
GeneralRe: Handling a process termination. Pin
enhzflep30-Apr-10 1:12
enhzflep30-Apr-10 1:12 
GeneralRe: Handling a process termination. Pin
progDes30-Apr-10 1:42
progDes30-Apr-10 1:42 
GeneralRe: Handling a process termination. Pin
progDes30-Apr-10 1:53
progDes30-Apr-10 1:53 
GeneralRe: Handling a process termination. Pin
enhzflep30-Apr-10 2:23
enhzflep30-Apr-10 2:23 
GeneralRe: Handling a process termination. [modified] Pin
Software_Developer30-Apr-10 2:21
Software_Developer30-Apr-10 2:21 
GeneralRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 23:09
Michel Godfroid29-Apr-10 23:09 
GeneralRe: Handling a process termination. Pin
Michel Godfroid29-Apr-10 21:40
Michel Godfroid29-Apr-10 21:40 
AnswerRe: Handling a process termination. Pin
David Crow30-Apr-10 3:21
David Crow30-Apr-10 3:21 
AnswerRe: Handling a process termination. Pin
Michel Godfroid30-Apr-10 4:49
Michel Godfroid30-Apr-10 4:49 
AnswerRe: Handling a process termination. Pin
Randor 30-Apr-10 4:57
professional Randor 30-Apr-10 4:57 
AnswerRe: Handling a process termination. Pin
kawayi30-Apr-10 6:31
kawayi30-Apr-10 6:31 
AnswerRe: Handling a process termination. Pin
«_Superman_»30-Apr-10 6:54
professional«_Superman_»30-Apr-10 6:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.