-
Okay, so here is my first attempt at a main window.
Code:
BOOL CreateMainWindow(char* title, int width, int height)
{
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left =(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
hInstance = GetModuleHandle(NULL);
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
WC_DIALOG, // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
return TRUE;
}
The only issue with this, is that the X button at the top right doesn't work! Why?
Also, Can someone explain more to me about the device context? Do I need one for this main window? Or do I only need a device context when I'm drawing things, like in our OpenGL frame I want to create.
-
WM_CLOSE should call DestroyWindow() [WM_DESTROY] which will clean up and call PostQuitMessage().
As you have no processing in these handlers I would pass them on to the DefWindowProc(). ie remove the WM_CLOSE and I think it will work.
As you have not followed correct switch/case/break syntax there are probably other errors (where DefWindowProc() is/ is not called after the message is/is not processed).
DCs and OpenGL......
Seen these?
http://nehe.gamedev.net/data/lessons....asp?lesson=01
-
Definately, I used those to get a milkshape model loader and such running. They don't really explain the win32 part too much, but I'll look again at it.