_IDE returns 1 when in the IDE / batch debugger, or 0 if not.

 

See also BDEBUGGER.