GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2009-Jan-13

Title: GLBASIC_HWND()
Post by: MrTAToad on 2009-Jan-13
I've noticed that if you change from window to full screen and back again (or you change screen resolutions), GLBASIC_HWND() returns an invalid handle.
Title: Re: GLBASIC_HWND()
Post by: Kitty Hello on 2009-Jan-13
What code did you use? It's almost impossible.
Title: Re: GLBASIC_HWND()
Post by: MrTAToad on 2009-Jan-13
I use the following to centre a window :

Code (glbasic) Select
FUNCTION CentreWindow:
INLINE
#ifdef WIN32
struct __RECT desk;
struct __RECT window;
HWND hWnd;

hWnd=(HWND) GLBASIC_HWND();
::GetWindowRect(::GetDesktopWindow(),&desk);
if (::GetWindowRect(hWnd,&window)==0)
{
}

::SetWindowPos(hWnd,HWND_NOTOPMOST,(desk.right-(window.right-window.left)) / 2, (desk.bottom-(window.bottom-window.top)) / 2, 0, 0, SWP_NOSIZE);
#endif
ENDINLINE
ENDFUNCTION


which centres a window to the current desktop window.

I find that after a screen resolution change (especially from window to full screen and then back to window again), the second GetWindowRect fails (GetLastError() at this point would return a value of 1400 - ERROR_INVALID_WINDOW_HANDLE), which, of course means the window cant be centred.