Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ CreateWindowEx returns NULL
    primarykey
    data
    text
    <p>I'm trying to set up a simple window using C++, but my call to <code>CreateWindowEx</code> returns <code>NULL</code>. Most of the code I'm using comes from the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff381409%28v=vs.85%29.aspx" rel="nofollow">example</a> on the MSDN website. Nothing that I've tried has worked, and any help would be appreciated.</p> <p>Here is the code:</p> <pre><code>//Include the windows header #include &lt;Windows.h&gt; //Forward declaration of the WndProc function LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); //Main entry point int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { //Window class name const wchar_t windowName[] = L"Window Class"; //Set up window class WNDCLASS wnd; wnd.lpfnWndProc = WndProc; wnd.hInstance = hInstance; wnd.lpszClassName = windowName; //Register window class RegisterClass(&amp;wnd); //Create window //! This returns NULL HWND hWnd = CreateWindowEx( 0, windowName, L"Windows Programming", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); //Simple check to see if window creation failed if(hWnd == NULL) { //Pause system("PAUSE"); return -1; } //Show the window ShowWindow(hWnd, nCmdShow); //Main message loop MSG msg; while(GetMessage(&amp;msg, NULL, 0, 0)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } } //WndProc function LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hDc = BeginPaint(hWnd, &amp;ps); FillRect(hDc, &amp;ps.rcPaint, (HBRUSH) (COLOR_WINDOW + 1)); EndPaint(hWnd, &amp;ps); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, msg, wParam, lParam); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload