Minimize window app

HI,
I need to know when my window is minimized; this below works but it
capture also when I go on-out window BAR; A way to avoid that? thanks

case SDL_ACTIVEEVENT:
if (event.active.gain)
printf(“minimized\n”);
break;