Jump to content
  • Advertisement
Sign in to follow this  
JClayton

Derived Class Error

This topic is 5141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class that wraps the windows message handler and creation routines and it uses this function to create a window:
void CWND::CreateWnd(HINSTANCE instance)
{
  DWORD		   dwExStyle;
	DWORD		   dwStyle;
	HWND       hwnd;
  WNDCLASSEX wc;
  
  RECT windowRect;
	windowRect.left   = (long)0;
	windowRect.right  = (long)m_width;
	windowRect.top    = (long)0;
	windowRect.bottom = (long)m_height;
   
  // Setup the windows class
  wc.cbSize          = sizeof(WNDCLASSEX);
  wc.style           = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc     = CWND::MessageRouter;
  wc.cbClsExtra      = 0;
  wc.cbWndExtra      = 0;
  wc.hInstance       = instance;
  wc.hIcon           = LoadIcon(NULL, IDI_APPLICATION);
  wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground   = (HBRUSH)GetStockObject(BLACK_BRUSH);
  wc.lpszClassName   = m_className;
  wc.hIconSm         = LoadIcon(NULL, IDI_WINLOGO);  
  
  // register the class
  if (!RegisterClassEx(&wc))
  { 
    MessageBox(NULL, "Class Registration Failed!", "ERROR!", MB_OK | MB_ICONEXCLAMATION); 
  }
  else
  { 
    // save the class
    m_wndClass = wc;
  }
	
	if(m_fullscreen)
	{
	  BeginFullscreen(m_width, m_height, m_bpp);
    dwExStyle = WS_EX_APPWINDOW;
		dwStyle = WS_POPUP;	
	}
	else
	{
    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		dwStyle = WS_OVERLAPPEDWINDOW;
	}
	 
	// Adjust Window To True Requested Size
	AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
 
  // Create the window
  hwnd = CreateWindowEx(dwExStyle, m_className, m_className, dwStyle | 
    WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, m_width, m_height, NULL, NULL, 
      instance, this);                     
  
  // Check to see if window creation failed
  if(!hwnd)
  { 
    MessageBox(NULL, "Window Creation Failed!", "ERROR!", MB_OK | MB_ICONEXCLAMATION); 
  }
  else
  { 
    // Show and update the window
    ShowWindow(hwnd, SW_SHOW);
    SetForegroundWindow(hwnd);
    SetFocus(hwnd);
    UpdateWindow(hwnd);
  }
  
  // store instance
  m_instance = instance;
}
However, when I create a child class that inherits the class CWND and attempt to embed this in a function it crashes and/or seg-faults. Here is a sample derived class like the one I am attempting to use:
class Test : public CWND {
  public:
    Test(LPCSTR className, int width, int height, int bpp, bool fullscreen) :
      CWND(className, width, height, bpp, fullscreen) {}
    
    void Blah(HINSTANCE instance)
    {
      CreateWnd(instance);
    }
};

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!