Jump to content
  • Advertisement
Sign in to follow this  
playboiLX

RegisterClassEx Issues [Solved]

This topic is 3083 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

Alright, to start it has been about a year since I have touched programming and I am trying to get reacquainted with it. As such I am restarting with the basics, but when working on the window wrapper class, I ran into some issues with registering the class.

When attempting to call RegisterClassEx, it fails here during runtime; I have stepped it through the debugger and all of the pointers are valid when populating the class.

Below is the method where I am running into the issues. If someone could provide some insight as to when the WNDCLASSEX does not register correctly, I would greatly appreciate it. Thank you in advance!


bool CWindow::Initialize(LPCTSTR hTitle, int iWidth, int iHeight)
{
// Inform log of window creation
CLog::InfoMessage("Creating window.");

// Create local variables
WNDCLASSEX hWndClass;

// Populate window class
hWndClass.cbSize = sizeof(WNDCLASSEX);
hWndClass.style = CS_DBLCLKS;
hWndClass.lpfnWndProc = (WNDPROC)CWindow::StaticWndProc;
hWndClass.cbClsExtra = 0;
hWndClass.cbWndExtra = 0;
hWndClass.hInstance = this->m_hInstance;
hWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
hWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
hWndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
hWndClass.lpszMenuName = NULL;
hWndClass.lpszClassName = L"WindowClass";

// Register the window class
if(RegisterClassEx(&hWndClass) == false)
{
// Failed to register class, inform log
CLog::ErrorMessage("Failed to register window class.");

// Method failed
return false;
}

// Register the member fields
this->m_iWidth = iWidth;
this->m_iHeight = iHeight;

// Create the window
this->m_hWnd = CreateWindowEx(0, L"WindowClass", hTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
this->m_iWidth,
this->m_iHeight,
NULL,
NULL,
this->m_hInstance,
this);

// Check is window was created
if(this->m_hWnd == NULL)
{
// Inform log of window creation
CLog::ErrorMessage("Failed to create the window.");

// Method failed
return false;
}

// Display the window
ShowWindow(this->m_hWnd, SW_SHOW);
UpdateWindow(this->m_hWnd);

// Method succeeded
return true;
}


[Edited by - playboiLX on July 3, 2010 5:29:52 PM]

Share this post


Link to post
Share on other sites
Advertisement
You forgot to initialize the hIconSm field:

hWndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

If that doesn't help, try using GetLastError().

Share this post


Link to post
Share on other sites
Also break before calling RegisterClass and check that each member of the structure is correctly filled. e.g make sure hWndClass.hInstance is not 0 or something.

Share this post


Link to post
Share on other sites
Thank you both for your input. I knew that I was missing something, I just didn't realize that it was that small of an error. So thank you Gage64 for pointing out the missing field and empirical2 for the suggestion of checking properties before registering the class.

Share this post


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

  • 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!