Show exit prompt in Windows when run from console
This commit is contained in:
		
							parent
							
								
									6835881e80
								
							
						
					
					
						commit
						f24eb9e549
					
				
					 1 changed files with 16 additions and 0 deletions
				
			
		
							
								
								
									
										16
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue