DosSetSignalExceptionFocus

From EDM2
Jump to: navigation, search

Causes the current process to become the focus for the Ctrl+C and Ctrl+Break signals.

Syntax

DosSetSignalExceptionFocus(flag, pulTimes)

Parameters

flag (BOOL32)
Focus flag.
pulTimes (PULONG)
The number of times DosSetSignalExceptionFocus has been called by the current process with flag set to SIG_SETFOCUS, minus the number of times it has been called with flag set to SIG_UNSETFOCUS.

Return Code

ulrc (APIRET) - returns
DosSetSignalExceptionFocus returns one of the following values:
  • 0 NO_ERROR
  • 1 ERROR_INVALID_FUNCTION
  • 300 ERROR_ALREADY_RESET
  • 303 ERROR_INVALID_PROCID
  • 650 ERROR_NESTING_TOO_DEEP

Remarks

Do not make Presentation Manager calls from exception handlers.

DosSetSignalExceptionFocus causes the calling process to become the signal focus for its screen group for the XCPT_SIGNAL_BREAK (Ctrl+Break) and XCPT_SIGNAL_INTR (Ctrl+C) signal exceptions.

You cannot issue DosSetSignalExceptionFocus from a Presentation Manager (PM) application. If you do, you get the return code ERROR_INVALID_PROCID. You can issue this function from a full-screen or windowed application.

Example Code

This example shows how to set the current thread to be the focus for the Ctrl+C and Ctrl+Break signals.

#define INCL_DOSPROCESS       /* DOS process values (for DosSleep) */
#define INCL_DOSEXCEPTIONS    /* DOS exception values */
#define INCL_ERRORS           /* DOS error values     */
#include <os2.h>
#include <stdio.h>

ULONG _System MyTermHandler( PEXCEPTIONREPORTRECORD       p1,
                             PEXCEPTIONREGISTRATIONRECORD p2,
                             PCONTEXTRECORD               p3,
                             PVOID                        pv );

int main (VOID)
{
  EXCEPTIONREGISTRATIONRECORD  RegRec  = {0}; /* Exception Registration Record */
  APIRET                       rc      = NO_ERROR;   /* Return code*/

  /* Add MyTermHandler to this thread's chain of exception handlers */

  RegRec.ExceptionHandler = (ERR)MyTermHandler;
  rc = DosSetExceptionHandler( &RegRec );
  if (rc != NO_ERROR) {
     printf("DosSetExceptionHandler error: return code = %u\n",rc);
     return 1;
  }

  printf("Terminate this program using Ctrl-C or Ctrl-Break.\n");

  rc = DosSleep(60000L);   /* Give user plenty of time to comply... */
  rc = DosUnsetExceptionHandler( &RegRec );
  if (rc != NO_ERROR) {
     printf("DosUnsetExceptionHandler error: return code = %u\n",rc);
     return 1;
  }
  return NO_ERROR;
}
/***************************************************************************/
ULONG _System MyTermHandler( PEXCEPTIONREPORTRECORD       p1,
                             PEXCEPTIONREGISTRATIONRECORD p2,
                             PCONTEXTRECORD               p3,
                             PVOID                        pv )
{
  ULONG       ulCount = 0;          /* Count of API calls  */
  APIRET      rc      = NO_ERROR;   /* Return code         */

  printf("*** MyTermHandler entered: ExceptionNum = %x\n",p1->ExceptionNum);

   rc = DosSetSignalExceptionFocus( SIG_UNSETFOCUS, &ulCount);
   if (rc != NO_ERROR) {
      printf("DosSetSignalExceptionFocus error: return code = %u\n", rc);
      return 1;
   }
        /**************************************/
        /* Handle XCPT_SIGNAL exceptions here */
        /**************************************/

   rc = DosSetSignalExceptionFocus( SIG_SETFOCUS, &ulCount);
   if (rc != NO_ERROR) {
      printf("DosSetSignalExceptionFocus error: return code = %u\n", rc);
      return 1;
   }

  return XCPT_CONTINUE_SEARCH;          /* Exception not resolved... */
}

Related Functions