Skip to content

Commit

Permalink
Show exit prompt in Windows when run from console
Browse files Browse the repository at this point in the history
  • Loading branch information
jclehner committed Jan 13, 2017
1 parent 6835881 commit 8bbfb54
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ void require_admin()

fprintf(stderr, "Warning: failed to check administrator privileges\n");
}

void show_exit_prompt()
{
HWND win = GetConsoleWindow();
if (!win) {
return;
}

if (GetCurrentProcessId() == GetWindowThreadProcessId(win, NULL)) {
printf("\nPress any key to exit\n");
getch();
}
}
#else
void require_admin()
{
Expand Down Expand Up @@ -139,6 +152,8 @@ int main(int argc, char **argv)
char *windir = NULL;
WSADATA wsa;

atexit(&show_exit_prompt);

val = WSAStartup(MAKEWORD(2, 2), &wsa);
if (val != 0) {
win_perror2("WSAStartup", val);
Expand Down

0 comments on commit 8bbfb54

Please sign in to comment.