From: Joseph C. Lehner Date: Fri, 13 Jan 2017 10:22:57 +0000 (+0100) Subject: Show exit prompt in Windows when run from console X-Git-Tag: v0.9.10~6^2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f24eb9e549f03df5d7f28c591d787ac8898ce5c9;p=oweals%2Fnmrpflash.git Show exit prompt in Windows when run from console --- diff --git a/main.c b/main.c index 2830cf7..66d7d80 100644 --- a/main.c +++ b/main.c @@ -104,6 +104,20 @@ void require_admin() fprintf(stderr, "Warning: failed to check administrator privileges\n"); } + +void show_exit_prompt() +{ + DWORD pid; + HWND win = GetConsoleWindow(); + if (!win || !GetWindowThreadProcessId(win, &pid)) { + return; + } + + if (GetCurrentProcessId() == pid) { + printf("Press any key to exit\n"); + getch(); + } +} #else void require_admin() { @@ -139,6 +153,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);