why this error occurs?

I started to learn about directx from this tutorial:
http://www.rastertek.com/dx10tut02.html

I was writing my own code and if I make sth wrong I just rewrite it as it is shown in tutorial
however, strange problem occurs, my program fails at creating window (creating hwnd)
I commented the code where error is thrown

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
void SystemClass::InitializeWindows(int &ScreenWidth,int &ScreenHeight){
	WNDCLASSEX wc;
	DEVMODE dmScreenSettings;
	int posX,posY;

	m_AppHandle=this;

	m_hInstance = GetModuleHandle(NULL);

	m_AppName = L"engine";

	wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = m_hInstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_WINLOGO);
	wc.hIconSm       = wc.hIcon;
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = m_AppName;
	wc.cbSize        = sizeof(WNDCLASSEX);

	RegisterClassEx(&wc);

	ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	ScreenHeight = GetSystemMetrics(SM_CYSCREEN);

	if(FULL_SCREEN){
		memset(&dmScreenSettings,0, sizeof(dmScreenSettings));
		dmScreenSettings.dmSize = sizeof (dmScreenSettings);
		dmScreenSettings.dmPelsHeight = (unsigned long)ScreenHeight;
		dmScreenSettings.dmPelsWidth = (unsigned long)ScreenWidth;
		dmScreenSettings.dmBitsPerPel = 32;
		dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

		posX=posY=0;
	}
	else{
		ScreenWidth = 800;
		ScreenHeight = 600;

		posX= (GetSystemMetrics(SM_CXSCREEN)-ScreenWidth)/2;
		posY= (GetSystemMetrics(SM_CYSCREEN)-ScreenHeight)/2;
	}

	m_hwnd=CreateWindowEx (WS_EX_APPWINDOW,m_AppName,m_AppName, WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_POPUP,posX,posY,ScreenWidth,ScreenHeight,NULL,NULL,m_hInstance,NULL);

	if(!m_hwnd){ //I added this if statement, and after i start debugging it  enters this statement and shows me that message box
		MessageBox(NULL,NULL,NULL,NULL);
		return;
	}
	ShowWindow(m_hwnd, SW_SHOW);
	SetForegroundWindow(m_hwnd);
	SetFocus(m_hwnd);

	ShowCursor(false);
	return;
}


I basically copied from word to word tutorial (only some variables have different name), still error occurs
is it my fault or what? (I compiled code provided by tutorial on bottom of the page and it works fine)
I tried using GetLastError() function, but its equal to NOERROR
Last edited on
did i make any mistake in the code?
..
Are you trying to create a fullscreen window with the borders? Maybe you're making a window too big for your screen, considering borders are extra-space-consuming?
i've set FULL_SCREEN to false
btw could it be problem with libraries?
do i need some special library to include?
I rewrote whole code this time no meesage box is shown, but still window isn't created
here are files what i have done:
http://www.2shared.com/file/8kp0v780/files.html
can some1 dl them and compile and check what happened?
There is a problem here:
1
2
3
4
5
6
7
8
9
10
11
12
13
LRESULT CALLBACK WndProc (HWND hwnd,UINT msg, WPARAM wParam, LPARAM lParam){
	switch (msg){
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
	m_ApplicationHandle->MsgHandler(hwnd, msg, wParam,lParam); //Problem here.
	}
	return 0;
}


we need to remember to pass back whatever the m_ApplicationHandle->MsgHandler(hwnd, msg, wParam,lParam); returns.

1
2
3
4
5
6
7
8
9
10
11
12
13
LRESULT CALLBACK WndProc (HWND hwnd,UINT msg, WPARAM wParam, LPARAM lParam){
	switch (msg){
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
	return m_ApplicationHandle->MsgHandler(hwnd, msg, wParam,lParam); //like this
	}
	return 0;
}



Threre is also a **FATAL** flaw here :
(I think you only put this text in to see if
the windows was being created but you are doing it wrong!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	else{
		ScreenWidth = 800;
		ScreenHeight = 600;

		posX = (GetSystemMetrics(SM_CXSCREEN)-ScreenWidth)/2;
		posY = (GetSystemMetrics(SM_CYSCREEN)-ScreenHeight)/2;
	}

	m_hwnd = CreateWindowEx (WS_EX_APPWINDOW, AppName, AppName, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, posX, posY, ScreenWidth, ScreenHeight, NULL, NULL, m_hInstance, NULL);

	if (m_hwnd = NULL) //**HERE - I think you mean if (m_hwnd == NULL) // Stop getting = and == confused
	{
		MessageBox(NULL,L"Failed to do function CreateWindowEx",NULL,NULL);
	}
	

LOL
i was so tired that day, I didn't even notice that i I haven't typed that one moar '=' char



thanks for taking your time to check my code
i would never notice that problem was in loop
Topic archived. No new replies allowed.