how do I make a line reflect off the border?

I am working on my first OpenGL application and I need to make a line look like it is ‘reflecting’ off the boundary as if it were a mirror whenever the line is about to cross the window’s boundary.

I know I need to determine when the line is about to cross the boundary, but how do I do this?

Anyone???