Having Trouble with CreateWindowEx

This is a discussion on Having Trouble with CreateWindowEx within the Windows Programming forums, part of the Platform Specific Boards category; Code: s = WS_POPUP; xs = WS_EX_APPWINDOW; if(!(hwn = CreateWindowEx(xs,"OpenGL",WINDOW_NAME,s,0,0,rect.right-rect.left,rect.bottom-rect.top,NULL,NULL,hin,NULL))) { error[8] = true; exerror[8] = GetLastError(); } Given the ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    Having Trouble with CreateWindowEx

    Code:
    	s = WS_POPUP;
    	xs = WS_EX_APPWINDOW;
    	if(!(hwn = CreateWindowEx(xs,"OpenGL",WINDOW_NAME,s,0,0,rect.right-rect.left,rect.bottom-rect.top,NULL,NULL,hin,NULL))) {
    		error[8] = true;
    		exerror[8] = GetLastError();
    	}
    Given the above, the CreateWindowEx function is returning NULL, so hwn is set to null, MSDN says that I should use GetLastError to find extended information, but GetLastError is returning 0...

    I have triple checked all the parameters, they seem to be fine.

  2. #2
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Is OpenGL a registered class?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Yes, I even considered that OpenGL may have been registered by something eles, so I changed it to a more unique string. Still no luck.

  4. #4
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Don't you need to have a parent for WS_POPUP?

  5. #5
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    depends if you're going full screen or not I believe.

    If you are going fullscreen, WS_POPUP should work, but otherwise you'll want to use WS_OVERLAPPEDWINDOW for the style. Also make sure that the instance variable is valid and not null or something.

  6. #6
    Registered User
    Join Date
    Apr 2004
    Posts
    11
    I'm just a beginner and I had some "inexplicable" problems with CreateWindowEx failing - see my post and the eventual solution here

    Beginner Question: CreateWindowEx Fails.

    It may help you?

    dicky

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Its still not working, but im making progress.

    I dont think the instance is right. Let me post my code up to the part that this is not working.

    Code:
    	
    
    bool cWindowManager::CreateWin(int p_w, int p_h, int p_b) {
    	
    	//=============================================================================
    	//	Signal function callbacks, sends these signals to the sigproc function
    	//=============================================================================
    
    	signal(SIGSEGV, SignalProc);
    	signal(SIGTERM, SignalProc);
    	signal(SIGILL, SignalProc);
    
    	//=============================================================================
    	//	Default init window variables
    	//=============================================================================
    
    	hdc=NULL;
    	hwn=NULL;
    	hrc=NULL;
    
    	//=============================================================================
    	//	assign the width and height to variables
    	//=============================================================================
    	
    	width = p_w;
    	height = p_h;
    	bits = p_b;
    
    	//=============================================================================
    	//	Set the windows desired size
    	//=============================================================================
    
    	rect.left = 0;
    	rect.right = width;
    	rect.top = 0;
    	rect.bottom = height;
    
    	//=============================================================================
    	//	Grab an instance for the window
    	//=============================================================================
    	
    	if(!(hin = GetModuleHandle(NULL))) {
    		error[0] = true;
    		exerror[0] = GetLastError();
    	}
    	//=============================================================================
    	//	Setup the window style
    	//=============================================================================
    
    	wc.cbClsExtra =		0;
    	wc.cbWndExtra =		0;
    	wc.hbrBackground =	NULL;
    	wc.hCursor =		NULL;
    	wc.hIcon =			NULL;
    	wc.hInstance =		hin;
    	wc.lpfnWndProc =	(WNDPROC) WindowProc;
    	wc.lpszClassName =	"EndAgeOpenGLWindow";
    	wc.lpszMenuName =	NULL;
    	wc.style =			CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    
    	//=============================================================================
    	//	Register the window class
    	//=============================================================================
    
    	if(!RegisterClass(&wc)) error[1] = true;
    
    	//=============================================================================
    	//	Setup device mode
    	//=============================================================================
    
    	ss.dmSize =			sizeof(ss);
    	ss.dmPelsHeight =	height;
    	ss.dmPelsWidth =	width;
    	ss.dmBitsPerPel =	bits;
    	ss.dmFields =		DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    
    	//=============================================================================
    	//	go into fullscreen mode
    	//=============================================================================
    
    	int errorcode = ChangeDisplaySettings(&ss,CDS_FULLSCREEN);
    	switch(errorcode) {
    		case DISP_CHANGE_RESTART:
    			error[2] = true;
    			break;
    		case DISP_CHANGE_BADFLAGS:
    			error[3] = true;
    			break;
    		case DISP_CHANGE_BADPARAM:
    			error[4] = true;
    			break;
    		case DISP_CHANGE_FAILED:
    			error[5] = true;
    			break;
    		case DISP_CHANGE_BADMODE:
    			error[6] = true;
    			break;
    		case DISP_CHANGE_NOTUPDATED:
    			error[7] = true;
    			break;	
    	}
    	
    	//=============================================================================
    	//	setup window styles
    	//=============================================================================
    	
    	s = WS_OVERLAPPEDWINDOW;
    	xs = WS_EX_APPWINDOW;
    
    	//=============================================================================
    	//	Adjust the window rect
    	//=============================================================================
    
    	AdjustWindowRectEx(&rect,s,false,xs);
    
    	//=============================================================================
    	//	Create the window
    	//=============================================================================
    
    	if(!(hwn = CreateWindowEx(xs,"EndAgeOpenGLWindow",WINDOW_NAME,s,0,0,rect.right-rect.left,rect.bottom-rect.top,NULL,NULL,hin,NULL))) {
    		error[8] = true;
    		exerror[8] = GetLastError();
    	}
    Now, everytime I run the debugger hin starts with some junk value, after that segment it is set to 0x00400000. If I expand the hin variable one level in the watch window it says unused and has a bunch of numbers. Let me post a screenshot of the watch window.

    http://img64.photobucket.com/albums/...n/codeprob.png

    Its not returning NULL, so its not an error, I dont know what it is but I think it is the reason that CreateWindowEx dosent work.

    The only other thing I can think of is that the WindowProc function is in anoter source file and this file has an extern to it, but I dont see how that could matter.


    My system is a Laptop. Toshiba Satellite P25
    2.8 Ghz P4 HT
    800Mhz FSB
    512 Mb DDR RAM
    Geforce FX Go 32 Mb

    The system has a 17' widescreen display and it runs at 1440 x 900 resolution. This code is just a copy and paste from an old program and that program works fine with the code and the resolution, but I figured it was worth mentioning.

    I remain 'at a loss'...

    I ran a DXDIAG, nothing was flagged.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    So where is hin declared anyway?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    A member of the class cWindowManager

    Code:
    class cWindowManager {
    public:
    	cWindowManager();
    	bool CreateWin(int width, int height, int bits);
    	bool DestroyWin();
    	void SwapFrameBuffer();
    
    	int GetHeight() { return height; };
    	int GetWidth() { return width; };
    	int GetBits() { return bits; };
    
    private:
    	void	WriteError(short code);
    
    	ofstream	outfile;
    	int			width;
    	int			height;
    	int			bits;	
    	bool		error[MAX_WINDOW_ERRORS];
    	DWORD		exerror[MAX_WINDOW_ERRORS];
    	HDC			hdc;	//Device Context
    	HGLRC		hrc;	//Render Context
    	HWND		hwn;	//Window Handle
    	HINSTANCE	hin;	//Instance
    	RECT		rect;	//Screen Rectangle
    	WNDCLASS	wc;		//Window Class
    	DEVMODE		ss;		//Screen Settings
    	DWORD		s;		//Style
    	DWORD		xs;		//Extended Style
    	short		depth;	//Depthbuffer Specification
    	unsigned int pf;	//Pixel Format
    };

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    'Inexplicable' CreateWindow(Ex) failures are usually caused by a problem in the window procedure. Please post your window procedure. The fact that you have cast the window procedure function when it never needs casting sets off alarm bells.

    Common window procedure errors include using the wrong calling convention, returning a value other than 0 for WM_CREATE and not returning the value from DefWindowProc() for unhandled messages.

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    ok, the window proc is the problem, I put the DefWindowProc as the only one and the window was created.

    AHH, I finally got it.

    Code:
    LRESULT CALLBACK WindowProc(HWND p_hwn,UINT p_msg,WPARAM p_wparam,LPARAM p_lparam) {
    	GameClient->ProcessIO(p_hwn, p_msg, p_wparam, p_lparam);
    	return 0;
    }
    I just removed the return 0; and added a return statement before the ProcessIO call.

    Thanks for the help guys, im so glad that I finally got that fixed. Man, I looked at that code so many times and it never hit me that that was wrong.. whoops.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 11:44 AM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2003, 12:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21