Continuing from here, I'm still trying to figure out how to get Allegro to spawn its window on my primary monitor (the monitor with the Windows taskbar on it) by default.
I'm using the following code to set up the display-
al_set_new_display_adapter(n); ALLEGRO_DISPLAY* display = al_create_display(w, h);
I've got 4 monitors, so as expected, it crashes for values of n outside of 0, 1, 2, and 3.
I don't have a way to get the ID of the primary monitor yet, but assuming I did, passing the value to al_set_new_display_adapter still won't work right.
Only values of 0 and 1 work, and 2 and 3 spawn the window in unknown space- not on any monitor. I can see the thumbnail of the window if I hover over the icon on the taskbar, but the window itself isn't visible anywhere.
Any ideas? If I'm making a professional game, I definitely want the window to spawn in valid space, and on the primary monitor if possible.
]]>Are you able to return the screen coordinates of the spawned window? Then you can know whether one was spawned above where you expected it instead of to the right, etc.
]]>I figured out how to retrieve the window position, and the result was completely unexpected.
For values of n, this is the window position I got.
0: 2160, 135 (valid, center of non-primary monitor)
1: -1680, 135 (valid, center of non-primary monitor)
2: -720, 32792 (invalid)
3: -720, 32792 (invalid)
Not sure what's going on here, but it looks like something in Allegro overflowed.
Fortunately, I learned I can also use al_set_window_position to put the window in valid space, since it appears that 0, 0 will always be the upper-left coordinate of the primary monitor.
However, I'd also like to note here that al_get_window_position doesn't return the same value that you previously set it to in al_set_window_position. If I set the window position to 100, 100, and then retrieve the window position again, I get 103, 125. I'm using Allegro 5.0.7, so I'm not sure if this has been fixed in the latest release. (I think this was reported once already.)
]]>Easiest way to get it fixed is to send a patch.
]]>What's the proper way to submit a patch? I've never done it before, so for now I guess I'll drop it here.
I made a change to _al_win_set_window_position in wwindow.c, making it account for the window border. Now al_set_window_position and al_get_window_position are consistent with each other, both referring to the upper left corner of the client area instead of the upper left corner of the window itself.
Tomorrow I'll try and see what's up with those other weird coordinates regarding the display adapter.
]]>I tested your patch and with the code below the window flies off screen (up and to the left).
It actually looks like this was fixed the opposite way in git already. It uses to top left corner of the window decoration. So your patch just mismatched with get... in git.
]]>Yeah, I was pretty sure the get/set window position was already fixed in git. The other problem however I'm not so sure.
]]>I have yet to test the following code (I only have one monitor) but, in theory, it should position a misplaced window properly:
]]>
Trent:
The code you posted combined with the patch I posted does not move the window for me.
Maybe one of the Windows functions is returning something unexpected on different versions of Windows? (I'm on Windows 7 Pro)
Aaron:
I tried your code, but I got the following error. I'm not sure what it means.
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Side note- I had to change HMODULE user32 = LoadLibrary("user32.dll"); to HMODULE user32 = LoadLibrary((LPCWSTR)L"user32.dll"); because my IDE was yelling at me about it. Not sure if that's what's causing the problem or not.
]]>If you're using MSVC you should be able to just use MonitorFromWindow directly. The extra fluff I have in that method can then be ignored...
As far as the ESP problem, it looks like a calling convention problem. Why it does that, I'm not sure. Just try it using MonitorFromWindow directly instead of using LoadLibrary and company.
]]>