Yeah I managed to figure that out (after cursing Charles Petzold and describing what he can do with his book in gory detail).
Full screen looks different than maximized. Is maximized not too hard to do?
mw
Yeah I managed to figure that out (after cursing Charles Petzold and describing what he can do with his book in gory detail).
Full screen looks different than maximized. Is maximized not too hard to do?
mw
Blucast Corporation
In CreateWindow? Add the WS_MAXIMIZE flag.Is maximized not too hard to do?
Outside CreateWindow?
Anyway Charlez Petzold's books only teach the basics, and some slightly advanced things, but once you know in general how Windows programming works, you'll have to refer to MSDN's Windows API reference constantly.Code:ShowWindow( hwndMain, SW_MAXIMIZE );
I added WS_MAXIMIZE like this:
WS_OVERLAPPED | WS_MAXIMIZE,
And I changed the width/height back to CW_USEDEFAULT as well.
But it doesn't maximize it...
Is that where I'm supposed to put it?
mw
Blucast Corporation
Yes. It seems to work for me.
That creates a maximized window (not a fullscreen one).Code:hwndMain = CreateWindow( wc.lpszClassName,TEXT("Basic Windows API Program"), WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_MAXIMIZE, 0,0,300,200,0,0,hInst,0);
Why does everything in WinAPI have to be such a f***ing fight to get working?
I still can't get it to work... Does this effect it:
ShowWindow (hwndMain, iCmndShow);
mw
Blucast Corporation
Try commenting that line and see.
It may be a good idea to post your whole code, or zip it up and upload it somewhere. Or replicate the problem with a smaller piece of code, then post it.
Here's my WinMain:
Code:int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, hPrevInstance, PSTR szCmdline, int iCmdShow) { MSG msg; WNDCLASS wc; wc.style = CD_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_BOOTICON)); wc.hbrBackground = (HBRUSH) GetSTockObject (BLACK_BRUSH); wc.lpszMenuName = NULL wc.lpszClassName = szAppName; if (!RegisterClass (&wc)) { MessageBox (NULL, TEXT ("ERROR! Window registration failed!", szAppName, MB_ICONERROR); return (0); } hwndMain = CreateWindow (szAppName, TEXT ("Game!"), WS_MAXIMIZE | WS_VISIBLE | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hwndMain) { MessageBox (NULL, TEXT ("ERROR! Window creation failed!", szAppName, MB_ICONERROR); return (0); } /* Button creation here*/ ShowWindow (hwndMain, iCmdShow); UpdateWindow (hwndMain); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; }
Blucast Corporation
Ah, your one makes it go fullscreen. I think the difference is that you use WS_OVERLAPPED, while I use WS_OVERLAPPEDWINDOW.
My window doesn't even go fullscreen. It displays my window as if I had left out the WS_MAXIMIZE entirely (ie: default size).
WS_OVERLAPPED doesn't display the minimize/maximize/close buttons at the very top right of the window. As far as I can tell, it doesn't effect the window size.
Anyway, even if I enter WS_OVERLAPPEDWINDOW instead it has the same effect on the window size (ie: none).
mw
Blucast Corporation
Would my window procedure effect the window size? I can't figure this out... :-(
The only things I do in my winproc is:
01) draw a bitmap on the background (WM_CREATE)
02) resize the bitmap to fill the background (WM_PAINT)
And that's about it. I haven't tried the WM_SIZE yet because I wanted to get the damn window to work properly... :-(
mw
Blucast Corporation
Hmm, if it's not too much trouble, could you post your whole code for your main source file? I want to try running and compiling it to see if the same problem occurs here.
I include my own icon and bitmap as resources.
Even when I change ShowWindow to:
ShowWindow (hwndMain, WS_MAXIMIZE)
It *still* shows the window in default size.
mw
Code:#include <windows.h> #include "resource.h" //prototypes: LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); //global variables: static TCHAR szAppName[] = TEXT ("GAME!"); static RECT rect; static HBITMAP hBitmapMain; HWND hwndMain, hwndNew, hwndLoad, hwndOptions, hwndQuit; HDC hdc, hdcBitmapMem; MSG msg; WNDCLASS wc; BITMAP bitmap; PAINTSTRUCT ps; int btnHeight = 30; int btnWidth = 110; int cxScreen; int cyScreen; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, hPrevInstance, PSTR szCmdline, int iCmdShow) { wc.style = CD_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (GetModuleHandle (NULL), MAKEINTRESOURCE (IDI_BOOTICON)); wc.hbrBackground = (HBRUSH) GetSTockObject (BLACK_BRUSH); wc.lpszMenuName = NULL wc.lpszClassName = szAppName; if (!RegisterClass (&wc)) { MessageBox (NULL, TEXT ("ERROR! Window registration failed!", szAppName, MB_ICONERROR); return (0); } hwndMain = CreateWindow (szAppName, TEXT ("Game!"), WS_MAXIMIZE | WS_VISIBLE | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hwndMain) { MessageBox (NULL, TEXT ("ERROR! Window creation failed!", szAppName, MB_ICONERROR); return (0); } GetClientRect (hwndMain, &rect); hwndNew = CreateWindow (TEXT ("button"), TEXT ("New Game"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, (rect.right - (2 * btnWidth)) / 3, 500 btnWidth, btnHeight, hwndMain, (HMENU) IDB_NEWGAMEBUTTON, GetModuleHandle (NULL), NULL); hwndLoad = CreateWindow (TEXT ("button"), TEXT ("Load Game"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, ((rect.right - (2 * btnWidth)) / 3) - btnWidth, 500, btnWidth, btnHeight, hwndMain, (HMENU) IDB_LOADGAMEBUTTON, GetModuleHandle (NULL), NULL); hwndNew = CreateWindow (TEXT ("button"), TEXT ("Options"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, (rect.right - (2 * btnWidth)) / 3, 600, btnWidth, btnHeight, hwndMain, (HMENU) IDB_OPTIONSBUTTON, GetModuleHandle (NULL), NULL); hwndNew = CreateWindow (TEXT ("button"), TEXT ("Quit"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, ((rect.right - (2 * btnWidth)) / 3) - btnWidth, 600, btnWidth, btnHeight, hwndMain, (HMENU) IDB_QUITBUTTON, GetModuleHandle (NULL), NULL); ShowWindow (hwndMain, iCmdShow); UpdateWindow (hwndMain); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: cxScreen = GetSystemMetrics (SM_CXSCREEN); cyScreen = GetSystemMetrics (SM_CYSCREEN); hBitmapMain = (HBITMAP) LoadImage (GetModuleHandle (NULL), MAKEINTRESOURCE (IDB_BITMAP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); if (!hBitmapMain) { MessageBox (hwnd, TEXT ("ERROR! Could not load window background!"), szAppName, MB_ICONERROR); } return (0); case WM_SIZE: return (0); case WM_COMMAND: switch (wParam) { case IDB_NEWGAMEBUTTON: return (0); case IDB_LOADGAMEBUTTON: return (0); case IDB_OPTIONSBUTTON: return (0); case IDB_QUITBUTTON: PostQuitMessage (0); return (0); } return (0); case WM_PAINT: hdcBitmapMem = CreateCompatibleDC (NULL); SelectObject (hdcBitmapMem, hBitmapMain); GetObject (hBitmapMain, sizeof (BITMAP), &bitmap); hdc = BeginPaint (hwnd, &rect); StretchBlt (hdc, 0, 0, rect.right, rect.bottom, hdcBitmapMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, MERGECOPY); DeleteDC (hdcBitmapMem); EndPaint (hwnd, &ps); return (0); case WM_DESTROY: PostQuitMessage (0); return (0); } return DefWindowProc (hwnd, message, wParam, lParam); }
Last edited by Lionmane; 10-13-2005 at 09:48 PM.
Blucast Corporation
You use the iCmdShow from the WinMain(). What value is in it?
Maximise is 3
Check Winuser.h for other values.
Try adding a
ShowWindow(hwnd,SW_SHOWMAXIMIZED);
to your WM_CREATE
I have found that when a window is first created, it will be created a default size.
During the create/init it will send a size msg to maximise the window.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
Ok, just for fun I did this:
This:Code:hwndMain = CreateWindow (szAppName, TEXT ("Game!"), WS_MAXIMIZE | WS_VISIBLE | WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
And this:Code:ShowWindow (hwndMain, WS_MAXIMIZE); UpdateWindow (hwndMain);
And it *STILL* shows the window in the default size.Code:case WM_CREATE: ShowWindow (hwndMain, WS_MAXIMIZE);
So something is wrong here...
mw
Last edited by Lionmane; 10-14-2005 at 09:37 AM.
Blucast Corporation
Is there something wrong with my hwnd references? They don't look right, but when I try to change them I get errors...
mw
Blucast Corporation