Original Post
Hi Guys,
Share your views and comments on this windows class.
If it works for you great.
The CWindow.h
//---------------------CWindow.h------------------------------//
#ifndef __Window_H_
#define __Window_H_
#include <windows.h>
class CWindow
{
public:
HWND hWnd;
HINSTANCE hInstance;
int Width, Height;
void Create(HINSTANCE hinstance, char* title, char* classname, int width, int height);
int CheckMessages();
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
#endif
CWindow.cpp
//---------------------CWindow.h------------------------------//
#include "CWindow.h"
void CWindow::Create(HINSTANCE hinstance, char* title, char* classname, int width, int height)
{
hInstance = hinstance;
Width = width;
Height = height;
WNDCLASSEX winclass;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_OWNDC;
winclass.lpfnWndProc = WndProc;
winclass.cbClsExtra = NULL;
winclass.cbWndExtra = NULL;
winclass.hInstance = hInstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = classname;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&winclass);
hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, classname, title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
Width, Height, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
}
int CWindow::CheckMessages()
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
return -1;
}
return 0;
}
LRESULT CALLBACK CWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE : DestroyWindow(hwnd);
break;
case WM_DESTROY : PostQuitMessage(0);
break;
default : break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
If there are any problems with the class please tell me what they are... so we can give the beginners a chance to concentrate more on DirectX than all the bulky window code.
Basically it's for playing around with Direct3d while learning the API. it runs in window mode and take the width and height from the user.
The game loop is then initialized as this.
//-----------------------Game Loop----------------------------//
CWindow Window;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdLine, int CmdShow)
{
Window.Create(hInstance, "Window", "mywindow", 640, 480);
while(1)
{
if(Window.CheckMessages() == -1)
break;
}
//-----------------------Game Loop----------------------------//
---DirectXSA---
Lachdannan Corp.
www.lachdannan.za.net
[edited by - Armadon on April 21, 2004 12:39:31 AM]
[edited by - Armadon on April 21, 2004 12:53:14 AM]