PDA

View Full Version : DefWindowProc Pauses MAME on Resize


Kong
03-19-2014, 10:33 PM
In MAME if you resize/move the window then the game will pause. This is bad for score mode where we want to be in control of pauses.

This is caused by Windows. It is not in the MAME code but in the code of Windows.

I've googled the problem and some people say creating an additional thread will solve this. I do not know how to try that. I know mame is already multithreaded. Not sure if there is more than one way to do it or what.



The pause is caused by DefWindowProc in window.c.
DefWindowProc is the default windows process that handles all window messages that the program does not handle itself.

What needs to happen is in
case WM_SYSCOMMAND:

Something like this needs to be added

if (cmd == SC_SIZE)
{
//insert custom size code here.
}

if (cmd == SC_MOVE)
{
//insert custom move code here.
}

Can anyone help me with that? I want to override DefWindowProc and handle size and move myself.

If not then I will have to disable move and size in score mode.

Thanks.

Seahawk
03-19-2014, 11:36 PM
In your mame source, in src/osd/windows/window.c, line 1258 in the latest build on mamedev.org

is the function which handles all the Windows messages for the window.

LRESULT CALLBACK winwindow_video_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam)

This is where you'd define your handlers for various windows messages.
I don't see anything in that function regarding SC_SIZE or SC_MOVE, I think you're using the wrong command list, windows messages are prefixed WM, see here (http://msdn.microsoft.com/en-us/library/windows/desktop/ff468922%28v=vs.85%29.aspx).

It is a large function, currently the MAME team has this as part of the handler
1340 // pause the system when we start a menu or resize
1341 case WM_ENTERSIZEMOVE:
1342 window->resize_state = RESIZE_STATE_RESIZING;
1343 case WM_ENTERMENULOOP:
1344 winwindow_ui_pause_from_window_thread(window->machine(), TRUE);
1345 break;
1346
1347 // unpause the system when we stop a menu or resize and force a redraw
1348 case WM_EXITSIZEMOVE:
1349 window->resize_state = RESIZE_STATE_PENDING;
1350 case WM_EXITMENULOOP:
1351 winwindow_ui_pause_from_window_thread(window->machine(), FALSE);
1352 InvalidateRect(wnd, NULL, FALSE);
1353 break;

with the size operation defined, so it's not jumping to DefWindowProc in the Windows API.

http://www.mamedev.org/source/src/osd/windows/window.c.html

Kong
03-19-2014, 11:54 PM
I am using window.c in mame 152.

SC_MOVE and SC_SIZE were not there until I added them.

Add this to line 1351 inside case WM_SYSCOMMAND:


if (cmd == SC_SIZE)
return 0;

if (cmd == SC_MOVE)
return 0;


And you will block drag and resize because you are preventing DefWindowProc from running.

Seahawk
03-20-2014, 12:06 AM
Your post sounds odd, is it a reply to me, or additional information to your OP?

Regardless, because the case is handled, so you won't trigger the default case of DefWindowProc.

I more meant this line that I quoted
winwindow_ui_pause_from_window_thread(window->machine(), TRUE);

is implied through the comment and function name, to stop everything, so maybe set to FALSE instead.

We may not be looking at the same source.

Kong
03-20-2014, 12:30 AM
We already tried that in 2011 :bulgy-eyes:

http://www.retrouprising.com/showthread.php?t=11269&page=3

My last post was a reply to your post.

I am positive that DefWindowProc is causing the pause.
I think the only two ways to interrupt it are
1. Use multiple threads - I don't really know what this means.
2. Add SC_MOVE and SC_SIZE and add your own custom code to handle those basic windows functions. I don't know how to do that either. But removing DefWindowProc removes the move and size functions.

Can you take look at this please
Win32 Loopless Window Size / Move / Code / [b2f2e2] (http://sourceforge.net/p/win32loopl/code/ci/default/tree/)

Seahawk
03-20-2014, 12:37 AM
Ha! That's hilarious to fall for the same trap again. I guess I should stick to embedded devices :D.

I'll look into it.

Kong
04-06-2014, 11:47 AM
Hawk any chance to look at the loopless window link?

Seahawk
04-07-2014, 05:11 AM
I've written a simple Opengl application for it and am working on integrating it. I'm not super familiar with the Windows API (all my code for college classes and job had to be OS neutral) so I'm having to pick this up while I go along.

Kong
07-27-2014, 03:42 PM
Hawk any luck?

I have added most of code to 154. About to just disable move and resize in score mode unless someone has a better solution.

---------- Post added at 01:39 PM ---------- Previous post was at 01:38 PM ----------

I think this will fix it but I don't know how to implement it.
Win32 Loopless Window Size / Move / Code / [b2f2e2] (http://sourceforge.net/p/win32loopl/code/ci/default/tree/)

---------- Post added at 03:42 PM ---------- Previous post was at 01:39 PM ----------

FINALLY!!

All pauses can be disabled.

Question should pause be disabled in all score mode games or only in games where it would have a benefit?