   OOP + D3D
  I'm trying to group my D3D initialization code into classes to keep it more manageable.What would be a wise way to do this?So far I haveMain#include "WndClass.h"int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){//create window objectWndClass WinOb;WinOb.initWNDCLASSEX();WinOb.regCreateShowWin();WinOb.mainLoop();return 0;}WndClass.h#include <windows.h>#include <windowsx.h>#ifndef WNDCLASS_H_#define WNDCLASS_H_class WndClass {public://constructer & destructorWndClass();virtual ~WndClass();//initialize WNDCLASSEXvoid initWNDCLASSEX();//register, create, and show windowvoid regCreateShowWin();//Msg Handlingstatic LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);//main loopvoid mainLoop();private:WNDCLASSEX wc;MSG msg;protected:HWND hWnd;};#endif /* WNDCLASS_H_ */WndClass.cpp#include "WndClass.h"WndClass::WndClass() {// TODO Auto-generated constructor stub}WndClass::~WndClass() {// TODO Auto-generated destructor stub}void WndClass::initWNDCLASSEX(){wc.cbSize = sizeof(WNDCLASSEX);wc.style = CS_HREDRAW | CS_VREDRAW;wc.lpfnWndProc = WinProc;wc.hInstance = GetModuleHandle(NULL);wc.hCursor = LoadCursor(NULL, IDC_ARROW);wc.hbrBackground = (HBRUSH)COLOR_WINDOW;wc.lpszClassName = "DxWin";}void WndClass::regCreateShowWin(){RegisterClassEx(&wc);hWnd = CreateWindowEx(NULL,  "DxWin",  "Direct X Window",  WS_OVERLAPPEDWINDOW,  300,  300,  500,  400,  NULL,  NULL,  wc.hInstance,  NULL);ShowWindow(hWnd,SW_SHOW);}//main loopvoid WndClass::mainLoop(){while(TRUE){while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){//translate and dispatch messageTranslateMessage(&msg);DispatchMessage(&msg);//if WM_Quit, exit the while loopif(msg.message == WM_QUIT)break;/* * Game Code Here * */}}}//msg procLRESULT CALLBACK WndClass::WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){switch(message){case WM_DESTROY:{PostQuitMessage(0);return 0;}break;}return DefWindowProc(hWnd, message, wParam, lParam);}but when running this code no window displays. Also my direction I thought of was to do a parent-child relationship between WndClass and a D3D initilization class. Is there a wiser way to do this?   
  I don't see anything that would cause your window to not be shown but I noticed you aren't doing any error checking after each call to the windows API.  You should do some error checking to find out if any of the function calls are failing.Edit: You might also try calling ZeroMemory(&WinOb, sizeof(WinOb)) before you initialize your window class.  Some of values you don't use should be set to zero and without calling ZeroMemory, they could be garbage values which windows wont like.   ;  It worked with the addition of zero memory.Now back to the theory question.Does my approach of making the d3d class a child of the windows class seem logical?Also what is the a good windows error handling technique to display errors?if (RegisterClassEx(&wc)==0){  /*    Print Error  */};Quote:Original post by DenzinAlso what is the a good windows error handling technique to display errors?When things are system/windows specific I just check for possible rrors and then use messagebox to display the error and break from the current processes to try and prevent a crash.Typically when it comes to initialization code I wouldn't worry about toomuch cleanness and wouldn't worry at all about speed unless its taking more than a minute to initialize everything. The most aggressive error checking should be happining at this point to prevent possible errors at runtime.Personally I prefer to keep directx and my windows class seperate from eachother to future proofe for possible cross platform designs. really the onlything directx ever needs from the windows data is a handle, and maybe the width/height/bpp, but even those aren't needed as you can use a dx screen size of 1440x900 in a 640x480 window.I'm still refractoring my engine after each project and from the start to what it is now is a huge improvement. What I did was got directx and everything else working. Then with each prject/iteration I took portions of the code and found that I could wrap it into a function and eventually wrap portions into seperate classes that could be combined or completely ignored. 