Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » how to center a window

Credits go to Richard Phipps for helping out!
This thread is locked; no one can reply to it. rss feed Print
how to center a window
gogomon
Member #7,481
July 2006

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
Moderator
January 2001
avatar

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.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

gogomon
Member #7,481
July 2006

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
Member #1,632
November 2001
avatar

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
Supreme Loser
January 1999
avatar

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
Member #7,481
July 2006

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

Felipe Maia
Member #6,190
September 2005
avatar

OpenLayer changes that somehow.

Thomas Fjellstrom
Member #476
June 2000
avatar

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

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: