• Advertisement
Sign in to follow this  

Window creation failed!

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

I am a beginner at win32 api and need some help... Here is the code: #include <windows.h> const char g_szClassName[]="my class"; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = g_szClassName; wc.lpszMenuName = NULL; wc.style = 0; if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window register failed!", "Error!", MB_OK | MB_ICONEXCLAMATION); return 0; } hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "Software", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if(hwnd==NULL) { MessageBox(NULL, "Window creation failed!", "Error!", MB_OK | MB_ICONEXCLAMATION); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } Why is it that it doesn't create a simple window? Seems to me that it is syntactically correct... Any help would be appreciated... THNX...

Share this post


Link to post
Share on other sites
Advertisement
Hey, put big chunks of code like that in between source tags like so.


//this will be inside a nice white box
std::cout<<"Hello! Use Source tags!;
//now close the source tag



You do that by this:
[ source] [ /source] (except take the space out between [ and source, and [ and /). This will make your code be easier to read for people helping you

Share this post


Link to post
Share on other sites
What kind of errors are you getting?

-AJ

Share this post


Link to post
Share on other sites
True.


default:
DefWindowProc(hwnd, msg, wParam, lParam);


should be


default:
return DefWindowProc(hwnd, msg, wParam, lParam);


Hope that helps. Next time post the errors you get to help us out.

Cheers
Jacob

Share this post


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

  • Advertisement