You didn't say how you're writing your application but if you're using OpenCV's builtin GUI from HighGUI, Sareth is correct in how to handle it. Be advised though that the GUI interface that HighGUI supports is quite limited. To have any "reasonable" application other than small test cases, you probably want to explore other alternatives.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.