Maximizing a Win32 window on creation

Started by
8 comments, last by Kest 15 years, 3 months ago
I'm doing the standard Win32 DirectX thing with CreateWindowEx() to run my game in windowed mode, and can't find any way to maximize the window in a way that simulates someone clicking the "maximize" button on the title bar. I can easily set the window size correctly, but unless it's really maximized, the user can click in the very top right and top left of the screen to focus the window behind it. Likewise, while it's not really maximized, the user can move the window around by dragging the title bar. If I press the maximize button, both of these things are disabled. Since many programs start up truly maximized, there must be some way to cause this to happen? Thanks for any help.
Advertisement
Check http://msdn.microsoft.com/en-us/library/ms632619(VS.85).aspx for WM_CREATE and use ShowWindow(hWnd, SW_MAXIMIZE) to maximize the window.
I searched nearly all of GameDev before posting, and saw this solution come up several times. It changes the size of the window, but it doesn't truly maximize it. The user can still click in the corners of the window to focus windows under it, as well as drag the window around by the title bar, both of which are not possible when a window is really maximized.

Is there any way to actually maximize it?
Hmm.. If it truly is a window created with CreateWindowEx it should maximize properly.

Perhaps posting a snippet of your code would help?
I think you're confusing maximized with fullscreen.

A maximized window occupies the full desktop area (besides the taskbar), but still has its borders and caption showing.

You basically want the window appear full screen without any borders or caption?
In that case you need to specify WS_POPUP and WS_VISIBLE only. Beware that you need to find a different way to return to windowed mode again since there won't be any size buttons in the caption.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

How about calling ShowWindow() after CreateWindow returns? Does that make any difference?
I appreciate everyone's time on this.

Quote:Original post by Endurion
I think you're confusing maximized with fullscreen.

A maximized window occupies the full desktop area (besides the taskbar), but still has its borders and caption showing.

Yeah, that's what I want. If you're running windows, reach up and try to drag the title bar of any maximizable program. Now click the maximize button and try again. See the difference? That's the only difference I can't overcome. The window is the right size, but it's not actually maximized, which can be verified by dragging the title bar.

It's not an end of the world problem, but it seems like there would be some way to do it properly.

Quote:Original post by Evil Steve
How about calling ShowWindow() after CreateWindow returns? Does that make any difference?

I tried that as well. It changes the size correctly, but the window can still be unfocused by clicking too far into the top left/right corner, and it can be dragged by the title.
You could try using SetWindowPlacement
ShowWindow should do it.. that's how I do it in all my programs, and there's never any problems. I can't drag any of them when maximized. Do you use any extensions for extra window buttons, or have multiple screens with some third-party driver or similar?

Try just creating a window in a test-program, and see if you get the same behavior. The following works correctly for me:
#include <windows.h>LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {	WNDCLASSEX wc;	HWND hWnd;	MSG msg;		ZeroMemory(&wc, sizeof(wc));	wc.cbSize = sizeof(wc);	wc.lpszClassName = TEXT("TestClass");	wc.hInstance = hInstance;	wc.lpfnWndProc = WndProc;	wc.hCursor = LoadCursor(NULL, IDC_ARROW);	wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);	RegisterClassEx(&wc);		hWnd = CreateWindowEx(		0,		TEXT("TestClass"),		TEXT("Title"),		WS_OVERLAPPEDWINDOW,		CW_USEDEFAULT,		CW_USEDEFAULT,		500,		400,		NULL,		NULL,		hInstance,		NULL	);		//ShowWindow(hWnd, nCmdShow);	ShowWindow(hWnd, SW_SHOWMAXIMIZED);		while(GetMessage(&msg, NULL, 0, 0) > 0) {		TranslateMessage(&msg);		DispatchMessage(&msg);	}		UnregisterClass(TEXT("TestClass"), hInstance);		return 0;}LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {	switch(msg) {		case WM_DESTROY:			PostQuitMessage(0);		break;	}		return DefWindowProc(hWnd, msg, wParam, lParam);}
Okay, I think I've got my mess sorted out. I started out trying to use WS_MAXIMIZE in the creation function, but it didn't work. Then I removed the WS_MAXIMIZEBOX style from the window, because I didn't want it resizable (clicking it caused a resize event). Then I tried to use ShowWindow(WindowHandle, SW_MAXIMIZE), and it didn't work because WS_MAXIMIZEBOX was missing. I guess you can't disable the button without disabling the window state.

After adding WS_MAXIMIZEBOX back in, ShowWindow(WindowHandle, SW_MAXIMIZE) seems to work correctly.

Thanks to all of you for beating a dead horse, until it came back to life, and realized it was an idiot for dying there.

This topic is closed to new replies.

Advertisement