how to center a window
gogomon

I'm using openlayer under windows and cant figured out how to center the window in the middle of the screen when in windowed mode, can somebody point me in the right direction pls.

ReyBrujo

That is not possible with the current Allegro library. You will have to write your own Window Class to handle the position, or recompile the Allegro library.

gogomon

is there anyway i can use the function to get a handle and call a function that will center the window and pass the HWND as reference?. I never programmed with windows so I dont really know.

Richard Phipps

Some code by Spellcaster:

1// the window initially starts at 32,32.
2// This will center the window on the desktop
3void center_window()
4{
5#ifdef ALLEGRO_WINDOWS
6 HWND wnd = win_get_window();
7 HWND desktop = GetDesktopWindow();
8 RECT wndRect, desktopRect;
9 int w , h , dw, dh;
10 
11 GetWindowRect( wnd , &wndRect );
12 GetWindowRect( desktop , &desktopRect );
13 w = wndRect.right - wndRect.left;
14 h = wndRect.bottom - wndRect.top;
15 dw = desktopRect.right - desktopRect.left;
16 dh = desktopRect.bottom - desktopRect.top;
17 
18 MoveWindow( wnd , ( dw - w ) / 2 , ( dh - h ) / 2 , w , h , TRUE );
19#endif
20}

You'll need to add #include <winalleg.h> after your #include <alleg.h> line

Matthew Leverton

Doesn't the Allegro window start up centered or does OpenLayer somehow change that?

changelog said:

Changes from 4.1.17 to 4.1.18 (January 2005)
Tore Halse made the Allegro window always appear centred in Windows.

gogomon

not sure, but thanks for the code richard exactly what i was looking for. Thx again

Felipe Maia

OpenLayer changes that somehow.

Thomas Fjellstrom

I'll bet its AllegroGL changing it, AGL replaces ALOT of allegro's code. It is a separate driver after all.

Thread #586493. Printed from Allegro.cc