Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

elendil67

Help with an object oriented window class

This topic is 5852 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 am making myself a window class as part of an engine, but it gives a runtime error. From debug information, it screws up at CreateWindowEx(). Does anyone know what I have done wrong? Thanks for your consideration.
    
	/////////////////////////////////////////////////////////////////////////

	// Name: Create()

	// Desc: Create() is a function to create a window.

	// Inpt: Width, height, fullscreen?, icon, handle to instance

	/////////////////////////////////////////////////////////////////////////

	int CWindow::Create(int width, int height, bool fullscreen, char *icon, HINSTANCE hInstance)
	{
		/////////////////////////////////////////////////////////////////////////

		// The style variable declared here will make the window a popup window

		// if the fullscreen variable is selected; if not, it will make an

		// overlapped window.

		/////////////////////////////////////////////////////////////////////////

		int style;

		if(fullscreen)
		{
			style = WS_POPUP;
		}
		else
		{
			style = WS_OVERLAPPEDWINDOW;
		}

		/////////////////////////////////////////////////////////////////////////

		// Fill in the window class with the values desired to make the window.

		/////////////////////////////////////////////////////////////////////////

		m_cWC.cbSize	    = sizeof(WNDCLASSEX);
		m_cWC.style		    = CS_HREDRAW | CS_VREDRAW;
		m_cWC.lpfnWndProc   = (WNDPROC)WndProc;
		m_cWC.cbClsExtra    = 0;
		m_cWC.cbWndExtra    = 0;
		m_cWC.hInstance     = hInstance;
		m_cWC.hIcon         = LoadIcon(NULL, icon);
		m_cWC.hCursor       = LoadCursor(NULL, IDC_ARROW);
		m_cWC.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
		m_cWC.lpszMenuName  = NULL;
		m_cWC.lpszClassName = "CWINDOW";
		m_cWC.hIconSm       = LoadIcon(NULL, icon);

		/////////////////////////////////////////////////////////////////////////

		// Register the class.

		/////////////////////////////////////////////////////////////////////////

		if(!RegisterClassEx(&m_cWC))
		{
			MessageBox(m_hWnd, "Could not register the window class.", "Error", MB_OK);

			return 1;
		}

		/////////////////////////////////////////////////////////////////////////

		// Create the window.

		/////////////////////////////////////////////////////////////////////////

		if(!(m_hWnd = CreateWindowEx(NULL,
								     "CWINDOW",
									 "CWindow",
									 style,
									 0, 0,
									 width, height,
									 NULL,
									 NULL,
									 hInstance,
									 NULL)))
		{
			MessageBox(m_hWnd, "Could not create the window.", "Error", MB_OK);

			return 1;
		}

		return 0;
	}
    
P.S. The problem is not from the whole window procedure thing, I have that cleared up. [edited by - elendil67 on December 1, 2002 5:09:25 PM]

Share this post


Link to post
Share on other sites
Advertisement
I don''t think it is returning - he said he gets a runtime error, and the debugging screws up at CreateWindowEx (i assume he means "it crashes there")

Share this post


Link to post
Share on other sites
Yes, I know my sig sucks. I''m trying to figure out how to replace it with a sig half the size.

I get an access violation right in CreateWindowEx(). I have no idea what it is. Thanks for your consideration.

Share this post


Link to post
Share on other sites
Does it work if you set the WndProc to DefWindowProc ? (I know you said its not, but thats all i can see could cause the problem)
I'd have to say that the suspect here if your WinProc - BTW, you shouldn't cast function pointers, if the compiler objects to it without the cast, then theres a 99% chance thats what the problem is.




[edited by - Evil Bill on December 1, 2002 7:16:46 PM]

Share this post


Link to post
Share on other sites
"m_cWC.hIcon = LoadIcon(NULL, icon);"

Is the first parameter really supposed to be NULL
if you want to load an icon different then the system ones ...

... don''t want to look it up right now, mainly
i''m under linux right now, and looking up windowsbecause functions under linux isn''t very good for my mood

Share this post


Link to post
Share on other sites
Yeah, the first parameter should be NULL for system icons, but if hes using a non-system icon, LoadIcon will fail, and return NULL - which is a valid value for the hIcon member of WNDCLASSEX

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!