Can anybody tell me what is wrong with my window creation? This function is being called from within the main function, and it all compiles and runs fine. However, the window which is rendered is not a window at all, but just a big white square.
Here is my window creation function:
/**
* handles everything for initialising a window
*
* @param hInst unique handle of window instance
* @param hPrevInst legacy parameter for copying memory from other instance into this one
* @param cmdLine commands application is started with
* @param cmdShow specifies how program should be displayed (maximised, minimized, or hidden)
*/
int Window::Init (HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmdLine, int cmdShow)
{
// name of application
static TCHAR appName[] = TEXT ("App");
// contains window class information
WNDCLASSEX wndC;
// window handle
HWND hWnd;
// define the windows class information
wndC.cbSize = sizeof (WNDCLASSEX); // specifies the size of the structure (in bytes)
wndC.style = CS_HREDRAW | CS_VREDRAW; // employs window class style to redraw if any resizing occurs
wndC.lpfnWndProc = WndProc; // pointer to the window procedure function
wndC.cbClsExtra = 0; // number of extra bytres to allocate for window class
wndC.cbWndExtra = 0; // number of extra bytes to allocate per window instance
wndC.hInstance = hInst; // handle to instnace conatining window procedure for this class
wndC.hIcon = NULL; // handle to large 32x32 (shown when alt + tab)
wndC.hCursor = LoadCursor (NULL, IDC_ARROW); // handle to class cursor resource
wndC.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // handle to class background brush (for painting background)
wndC.lpszMenuName = NULL; // pointer to string with name of class menu (no default menu)
wndC.lpszClassName = appName; // specifies windows class name
wndC.hIconSm = NULL; // handle to small 16x16 icon (top left corner of window)
// registers window class with system, will terminate is parameter is invalid
if (!RegisterClassEx (&wndC)) return 0;
// rect used for defining window
RECT wndRc;
// calculate size of window based on entire client window size
wndRc.left = 0;
wndRc.top = 0;
wndRc.right = 800;
wndRc.bottom = 600;
long tStyle = 0;
// style chosen based on whether this window is fullscreen
if (mFullScreen)
tStyle = WS_POPUP;
else
{
tStyle = WS_OVERLAPPEDWINDOW;
// calculates required size of window rectangle, based on desired client-rectangle size
AdjustWindowRect (&wndRc, tStyle, FALSE);
}
// now class is registered, we create a window with it
hWnd = CreateWindowEx (0, appName, appName, WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
wndRc.right - wndRc.left, wndRc.bottom - wndRc.top, NULL, NULL, hInst, NULL);
// check we have a valid handle
if (hWnd == NULL) return 0;
// show window and update it (cmdShow allows user to specify whether they want window to start maximised, minimised, etc.)
ShowWindow (hWnd, cmdShow);
UpdateWindow (hWnd);
// if we fail to create the direct x device send an error message and terminate
if (DirectDraw::GetInstance()->CreateDevice (hWnd, 800, 600, mFullScreen) != 1)
{
MessageBox (hWnd, "Failed to create surfaces", "Error", MB_OK);
return 0;
}
// adds rectangle to the specified window's update region (portion of window to be redrawn)
InvalidateRect (hWnd, NULL, TRUE);
return 1;
}
Courtesy of Arx and Tenfour in the comments to my post, the problem was simply that I was setting the style of my window class to ‘WS_POPUP’ which is obviously not suitable outside of a full screen window.