void TEST_minimize_window() { char *routine = "TEST_minimize_window"; printf(testing, routine); //First with a valid window Window win = active_window(); assert(minimize_window(win, TRUE)); assert(minimize_window(win, FALSE)); activate_window(win); //Then with an invalid window assert(minimize_window(20, TRUE) == FALSE); assert(minimize_window(20, FALSE) == FALSE); printf(done, routine); }
LRESULT CALLBACK winwindow_video_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam) { LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA); win_window_info *window = (win_window_info *)ptr; // we may get called before SetWindowLongPtr is called if (window != NULL) { assert(GetCurrentThreadId() == window_threadid); update_minmax_state(window); } // handle a few messages switch (message) { // paint: redraw the last bitmap case WM_PAINT: { PAINTSTRUCT pstruct; HDC hdc = BeginPaint(wnd, &pstruct); draw_video_contents(window, hdc, TRUE); if (win_has_menu(window)) DrawMenuBar(window->hwnd); EndPaint(wnd, &pstruct); break; } // non-client paint: punt if full screen case WM_NCPAINT: if (!window->fullscreen || HAS_WINDOW_MENU) return DefWindowProc(wnd, message, wparam, lparam); break; // input: handle the raw mouse input case WM_INPUT: if (win_use_raw_mouse) win_raw_mouse_update((HRAWINPUT)lparam); break; // syskeys - ignore case WM_SYSKEYUP: case WM_SYSKEYDOWN: break; // pause the system when we start a menu or resize case WM_ENTERSIZEMOVE: window->resize_state = RESIZE_STATE_RESIZING; case WM_ENTERMENULOOP: winwindow_ui_pause_from_window_thread(TRUE); break; // unpause the system when we stop a menu or resize and force a redraw case WM_EXITSIZEMOVE: window->resize_state = RESIZE_STATE_PENDING; case WM_EXITMENULOOP: winwindow_ui_pause_from_window_thread(FALSE); InvalidateRect(wnd, NULL, FALSE); break; // get min/max info: set the minimum window size case WM_GETMINMAXINFO: { MINMAXINFO *minmax = (MINMAXINFO *)lparam; minmax->ptMinTrackSize.x = MIN_WINDOW_DIM; minmax->ptMinTrackSize.y = MIN_WINDOW_DIM; break; } // sizing: constrain to the aspect ratio unless control key is held down case WM_SIZING: { RECT *rect = (RECT *)lparam; if (video_config.keepaspect && !(GetAsyncKeyState(VK_CONTROL) & 0x8000)) constrain_to_aspect_ratio(window, rect, wparam); InvalidateRect(wnd, NULL, FALSE); break; } // syscommands: catch win_start_maximized case WM_SYSCOMMAND: { // prevent screensaver or monitor power events if (wparam == SC_MONITORPOWER || wparam == SC_SCREENSAVE) return 1; // most SYSCOMMANDs require us to invalidate the window InvalidateRect(wnd, NULL, FALSE); // handle maximize if ((wparam & 0xfff0) == SC_MAXIMIZE) { update_minmax_state(window); if (window->ismaximized) minimize_window(window); else maximize_window(window); break; } return DefWindowProc(wnd, message, wparam, lparam); } // track whether we are in the foreground case WM_ACTIVATEAPP: in_background = !wparam; break; // close: cause MAME to exit case WM_CLOSE: if (multithreading_enabled) PostThreadMessage(main_threadid, WM_USER_REQUEST_EXIT, 0, 0); else mame_schedule_exit(Machine); break; // destroy: clean up all attached rendering bits and NULL out our hwnd case WM_DESTROY: (*draw.window_destroy)(window); window->hwnd = NULL; return DefWindowProc(wnd, message, wparam, lparam); // self redraw: draw ourself in a non-painty way case WM_USER_REDRAW: { HDC hdc = GetDC(wnd); mtlog_add("winwindow_video_window_proc: WM_USER_REDRAW begin"); window->primlist = (const render_primitive_list *)lparam; draw_video_contents(window, hdc, FALSE); mtlog_add("winwindow_video_window_proc: WM_USER_REDRAW end"); ReleaseDC(wnd, hdc); break; } // self destruct case WM_USER_SELF_TERMINATE: DestroyWindow(window->hwnd); break; // fullscreen set case WM_USER_SET_FULLSCREEN: set_fullscreen(window, wparam); break; // minimum size set case WM_USER_SET_MINSIZE: minimize_window(window); break; // maximum size set case WM_USER_SET_MAXSIZE: maximize_window(window); break; // set focus: if we're not the primary window, switch back // commented out ATM because this prevents us from resizing secondary windows // case WM_SETFOCUS: // if (window != win_window_list && win_window_list != NULL) // SetFocus(win_window_list->hwnd); // break; // everything else: defaults default: return DefWindowProc(wnd, message, wparam, lparam); } return 0; }
static int complete_create(win_window_info *window) { TCHAR *t_title; RECT monitorbounds, client; int tempwidth, tempheight; HMENU menu = NULL; HDC dc; assert(GetCurrentThreadId() == window_threadid); // get the monitor bounds monitorbounds = window->monitor->info.rcMonitor; // create the window menu if needed #if HAS_WINDOW_MENU if (win_create_menu(&menu)) return 1; #endif // create the window, but don't show it yet t_title = tstring_from_utf8(window->title); if (t_title == NULL) return 1; window->hwnd = CreateWindowEx( window->fullscreen ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX, TEXT("MAME"), t_title, window->fullscreen ? FULLSCREEN_STYLE : WINDOW_STYLE, monitorbounds.left + 20, monitorbounds.top + 20, monitorbounds.left + 100, monitorbounds.top + 100, NULL,//(win_window_list != NULL) ? win_window_list->hwnd : NULL, menu, GetModuleHandle(NULL), NULL); free(t_title); if (window->hwnd == NULL) return 1; // set a pointer back to us SetWindowLongPtr(window->hwnd, GWLP_USERDATA, (LONG_PTR)window); // adjust the window position to the initial width/height tempwidth = (window->maxwidth != 0) ? window->maxwidth : 640; tempheight = (window->maxheight != 0) ? window->maxheight : 480; SetWindowPos(window->hwnd, NULL, monitorbounds.left + 20, monitorbounds.top + 20, monitorbounds.left + tempwidth + wnd_extra_width(window), monitorbounds.top + tempheight + wnd_extra_height(window), SWP_NOZORDER); // maximum or minimize as appropriate if (window->startmaximized) maximize_window(window); else minimize_window(window); adjust_window_position_after_major_change(window); // show the window if (!window->fullscreen || window->fullscreen_safe) { // finish off by trying to initialize DirectX; if we fail, ignore it if ((*draw.window_init)(window)) return 1; if (video_config.mode != VIDEO_MODE_NONE) ShowWindow(window->hwnd, SW_SHOW); } // clear the window dc = GetDC(window->hwnd); GetClientRect(window->hwnd, &client); FillRect(dc, &client, (HBRUSH)GetStockObject(BLACK_BRUSH)); ReleaseDC(window->hwnd, dc); return 0; }