Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIGWINCH equivalent on Windows?

This could very well be another silly question, but I can't seem to find the answer (or any for that matter), so here goes.

I have a command line program that uses SIGWINCH on Linux to detect the window size change, and I apparently have a user who is using the program on Windows. The problem, is that the program uses SIGWINCH to detect changes in the window size and this signal is unsupported on Windows. I've tried Googling for every combination of search terms I can think of, but due to the relationship between SIGWINCH and changes in the size of the window, I'm having trouble finding any useful results. I'm looking for a Windows equivalent, or the method most often used to detect changes in the window size on Windows computers.

How do you detect changes in window size on Windows?

like image 602
Jeff Welling Avatar asked Jun 01 '12 20:06

Jeff Welling


1 Answers

Since I don't think you can subclass console windows (and thus catch WM_SIZE messages), you may just have to poll GetConsoleScreenBufferInfo.

EDIT: Upon further investigation (not tested!), it might also be doable without polling using ReadConsoleInput. Summary: Call SetConsoleMode to turn on window input events. From a different thread, wait for the console input handle to become signaled using WaitForSingleObject or a similar function. Read all pending console events; the presence of window buffer size events means something's resized your console window.

like image 132
ChrisV Avatar answered Oct 06 '22 09:10

ChrisV