This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Trying to add an exit confirmation dialog to Cygwin setup.exe, failing


I want setup to ask for confirmation before exiting when alt+f4 is
pressed, like firefox and many other programs do, rather than
immediately exiting and terminating any download/install in progress,
like it currently does.
I spent many of the past 24 hours reading Win32 API documentation (I'm
not a Windows programmer) and the setup.exe source, and finally
determined that as an initial step to make sure I'm catching the
alt+f4 signal, I could add to Window::WindowProc in window.cc the
lines
  if((uMsg==WM_SYSCOMMAND)&&((wParam&0xfff0)==SC_CLOSE)) {
    MessageBox(NULL,"Got alt+f4 signal","Sys command received", MB_OK |
      MB_ICONINFORMATION);
    return 0;
  }
right before the line
  return DefWindowProc (WindowHandle, uMsg, wParam, lParam);

This should show a message that alt+f4 was pressed, and then leave
setup running rather than terminate it.
However, it doesn't work. The message isn't displayed, and setup
terminates immediately.

I grepped the source for DefWindowProc and found two other occurrences
of it, in PickView.cc and proppage.cc, and tried intercepting those
too, in case I'm reading the API docs wrong, but that had no effect.

I created a WinMain program from scratch with the simplest possible message loop
  while(GetMessage(&msg, NULL, 0, 0))
  {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }
My function which I registered for lpfnWndProc just intercepts
SC_CLOSE as above and then calls DefWindowProc for everything else. It
works as expected when I press alt+f4: display the message box, and
then leave the program running.

Cygwin setup.exe's message loop is this
  while (GetMessage (&msg, NULL, 0, 0) != 0
	 && GetMessage (&msg, (HWND) NULL, 0, 0) != -1)
    {
      if (!IsWindow (WindowHandle) || !IsDialogMessage (WindowHandle, &msg))
	{
	  TranslateMessage (&msg);
	  DispatchMessage (&msg);
	}

    }
which baffles me. Is the message loop difference causing the problem?
Where's the correct place to intercept SC_CLOSE in Cygwin's setup?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]