updating window coordinates in real time

Hi to everyone, today I stumbled upon the following problem, using glut and Windows:
I have a window on screen for which I store the screen coordinates of the window, like: left, top, right, bottom. I show these coordinates on screen. I’d like to update these coordinates pixel by pixel as the user reshapes or moves the window.
For reshaping, there is the reshape callback, so no problemo there. But what about moving the window? I tried doing the update in the display callback, but the coordinates update as soon as I release the mouse button.
Has anyone stumbled upon this before? I thought after that I could use glutMotionFunc or PassiveMotionFunc callbacks, but these require that the mouse is within the window (not in the window border). Thanks for your time.

This is pretty easy to do when using the win32 api, but there is no way to have glut do it for you, so as long as you use glut the answer is no.


well, there is a sneaky way to do it under win32, using window sub-classing. use this code at your own risk :slight_smile:

#include <windows.h>
#include "glut.h"
// for glut's window proc
WNDPROC oldWndProc;
// our new window proc
LRESULT CALLBACK newWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    RECT* rect;
    switch( uMsg )
        case WM_MOVING:
            // watch out, moving rect!
            rect = (RECT*)lParam;
    return CallWindowProc( oldWndProc, hwnd, uMsg, wParam, lParam );
int main( int argc, char** argv )
    // typical glut setup here, nothing unusual	
    glutInit( &argc, argv );
    glutInitDisplayMode( ... );
    glutInitWindowSize( ... );
    glutInitWindowPosition( ... );
    glutCreateWindow( argv[0] );
    // !!! sneaky part !!!
    // find our window
    // note the name matches the window title
    HWND hWnd = FindWindow( NULL, argv[0] );
    if( hWnd )
        // sub-class the window proc
	oldWndProc = (WNDPROC)GetWindowLongPtr( hWnd, GWL_WNDPROC );
	if( oldWndProc )
	    SetWindowLongPtr( hWnd, GWL_WNDPROC, (LONG)newWndProc );
    // and the rest is completely as usual
    // ...

Thanks guys. I guess I have to think about it because in the end this is supposed to be a beginners program, talking about viewports and windows, so I don’t know how much I want to put in win32 api calls in there (it might scare people off). I’ll think about it but thanks for the options :slight_smile: