Jump to content

  • Log In with Google      Sign In   
  • Create Account


[Win32] [solved] CreateWindowEx returns error 1407


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 molehill mountaineer   Members   -  Reputation: 593

Like
0Likes
Like

Posted 27 September 2012 - 04:02 AM

Hello fellow coders,

Can any of you spot what I'm missing here? I'm trying to create a win32 window but falling flat on my face, it's kind of embarrassing really Posted Image
After the call to CreateWindowEx() I'm getting error 1407 which stands for "Cannot find window class".
This leads me to believe that I'm filling in the class structure incorrectly, even though registerClass() doesn't seem to fail.

EDIT: parameters were in the wrong order

bool Window::initialize(HINSTANCE p_instance, UINT p_showCommand)
{
tstring className = _T("solipsistWindow");
//define and register window class
WNDCLASSEX windowClass;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WindowProc;
windowClass.cbClsExtra = NULL;
windowClass.cbWndExtra = NULL;
windowClass.hInstance = p_instance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_CROSS);
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //+1 to differentiate between background and scrollbar
windowClass.lpszClassName = className.c_str();
windowClass.lpszMenuName = NULL;
if(!RegisterClassEx(&windowClass))
{
  MessageBox(NULL, _T("failed to register window class"), _T("Fatal error"), MB_OK);
  return false;
}

m_windowHandle = CreateWindowEx(WS_EX_CLIENTEDGE,
		 m_windowTitle.c_str(),
		 className.c_str(), //window class
		 WS_OVERLAPPEDWINDOW, //window style
		 CW_USEDEFAULT,   //x
		 CW_USEDEFAULT,   //y
		 m_width,  
		 m_height,
		 NULL,	 //parent
		 NULL,	 //window
		 p_instance,  
		 NULL);	 //lParam

if(m_windowHandle == NULL)
{
  DWORD errorCode = GetLastError();
  tstringstream errorMessage;
  errorMessage << _T("Failed to create window after registering window class. Error code ");
  errorMessage << errorCode;

  MessageBox(NULL, errorMessage.str().c_str() , _T("Fatal Error"), MB_OK);
  return false;
}
ShowWindow(m_windowHandle, p_showCommand);
UpdateWindow(m_windowHandle);
setInitialized(true);
return true;
}


Sponsor:

#2 Endurion   Crossbones+   -  Reputation: 3329

Like
0Likes
Like

Posted 27 September 2012 - 05:44 AM

What's a tstring?
What type is className?
Also, are you compiling in Multi-Byte or Unicode?
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#3 molehill mountaineer   Members   -  Reputation: 593

Like
0Likes
Like

Posted 27 September 2012 - 01:34 PM

What's a tstring?
What type is className?
Also, are you compiling in Multi-Byte or Unicode?



tstring is defined as either wstring or regular string object depending on whether or not unicode is being used.
classname is a wstring (as are all tstrings because I'm using Unicode character set)

defines for tstring in file defines.h which is included by the window wrapper
#ifndef DEFINES_H
#define DEFINES_H
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <tchar.h> //used for _T() macro
#include <string>
#include <sstream>

//widestring support
#if defined(UNICODE) || defined(_UNICODE)

#define tstring std::wstring
#define tstringstream std::wstringstream

#else

#define tstring std::string
#define tstringstream std::stringstream

#endif

#endif


Edited by molehill mountaineer, 27 September 2012 - 01:39 PM.


#4 Ripiz   Members   -  Reputation: 529

Like
2Likes
Like

Posted 27 September 2012 - 01:45 PM

Your parameters are in wrong order, window's title and class's name to be precise, see MSDN: http://msdn.microsof...0(v=vs.85).aspx

Edited by Ripiz, 27 September 2012 - 01:46 PM.


#5 molehill mountaineer   Members   -  Reputation: 593

Like
1Likes
Like

Posted 27 September 2012 - 03:01 PM

That did the trick, should have spotted that sooner! Thanks man - reputation++




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS