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

Terry Fleming
Sat Mar 14 12:42:00 GMT 2009

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 the
  if((uMsg==WM_SYSCOMMAND)&&((wParam&0xfff0)==SC_CLOSE)) {
    MessageBox(NULL,"Got alt+f4 signal","Sys command received", MB_OK |
    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 and, 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))
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?

More information about the Cygwin-apps mailing list