• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualRavnock

Posted 16 March 2013 - 06:41 PM

You're not checking the return value from your CreateWindowEx call (a run in your debugger with a breakpoint set at your ShowWindow call would have told you that you didn't have a valid HWND here).  Also, some of your CreateWindowEx parameters are wrong - please review the documentation at http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680%28v=vs.85%29.aspx and correct them before continuing any further with this.

If it worked on one PC it was certainly by accident rather than by design.

I am trying to shift my project to my other computer. I think I have the compiler set up properly. Initially, I thought it was DX causing the issue, but I narrowed it down to WinMain(..). Here is the code:

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    // not needed any more
wc.lpszClassName = "WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
"WindowClass",
"Our Direct3D Program",
WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
0, 0,    // the starting x and y positions should be 0
int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
NULL,
NULL,
hInstance,
NULL);
//return 0;//exits without crashing
ShowWindow(hWnd, nCmdShow);
return 0;//it will crash here
// set up and initialize Direct3D
GameEngine.initD3D(hWnd,hInstance);

//init the environment here.

// enter the main loop:
UINT ExitMessage=GameEngine.MainLoop();

return ExitMessage;
}



Notice the 2 return lines arround ShowWindow(..)? That's how I came to the conclusion it had something to do with showing the window. I believe it's the creation that's actually causing the problem, but I don't know what could cause it to work on one machine and not another. Perhapse I don't have the correct SDK (VC) or I don't have my compiler set up correctly????

If I am not wrong...WS_EX_TOPMOST is an extended style, the extended styles shoud be in the first parameter and the "normal" styles in the fourth

So it should be CreateWindowEx(WS_EX_TOPMOST,  "WindowClass", "Our Direct3D Program", WS_POPUP,...

Probably the WS_EX_TOPMOST is being interpreted wrong and there is a conflict with the WS_POPUP

### #1Ravnock

Posted 16 March 2013 - 01:42 PM

You're not checking the return value from your CreateWindowEx call (a run in your debugger with a breakpoint set at your ShowWindow call would have told you that you didn't have a valid HWND here).  Also, some of your CreateWindowEx parameters are wrong - please review the documentation at http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680%28v=vs.85%29.aspx and correct them before continuing any further with this.

If it worked on one PC it was certainly by accident rather than by design.

I am trying to shift my project to my other computer. I think I have the compiler set up properly. Initially, I thought it was DX causing the issue, but I narrowed it down to WinMain(..). Here is the code:

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    // not needed any more
wc.lpszClassName = "WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
"WindowClass",
"Our Direct3D Program",
WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
0, 0,    // the starting x and y positions should be 0
int(SCREEN_WIDTH),int( SCREEN_HEIGHT),    // set the window size
NULL,
NULL,
hInstance,
NULL);
//return 0;//exits without crashing
ShowWindow(hWnd, nCmdShow);
return 0;//it will crash here
// set up and initialize Direct3D
GameEngine.initD3D(hWnd,hInstance);

//init the environment here.

// enter the main loop:
UINT ExitMessage=GameEngine.MainLoop();

return ExitMessage;
}



Notice the 2 return lines arround ShowWindow(..)? That's how I came to the conclusion it had something to do with showing the window. I believe it's the creation that's actually causing the problem, but I don't know what could cause it to work on one machine and not another. Perhapse I don't have the correct SDK (VC) or I don't have my compiler set up correctly????

If I am not wrong...WS_EX_TOPMOST is an extended style, the extended styles shoud be in the first parameter and the "normal" styles in the second

So it should be CreateWindowEx(WS_EX_TOPMOST, WS_POPUP,...

Probably the WS_EX_TOPMOST is being interpreted wrong and there is a conflict with the WS_POPUP

PARTNERS