Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see at least two errors.</p> <p>First, you register the class with</p> <pre><code>windowClass.hInstance = hI; </code></pre> <p>but when you create the window, you pass a different <code>HINSTANCE</code>:</p> <pre><code>m_hWnd = CreateWindowEx(dwExStyle, className, title, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(NULL), this); // ^^^^^^^^^^^^^^^^^^^^^ </code></pre> <p>The <code>HINSTANCE</code> parameters must match in order for the class to be found. You should use <code>hI</code> in both places.</p> <p>Second, your code uses the <code>m_hWnd</code> member before it is initialized.</p> <pre><code>return DefWindowProc(m_hWnd, uMsg, wParam, lParam); </code></pre> <p>When the window receives the <code>WM_NCCREATE</code> message, <code>m_hWnd</code> has not yet been initialized. It doesn't get initialized until the <code>CreateWindowEx</code> returns. You need to get the correct window handle to <code>DefWindowProc</code>. One way is to pass the <code>hWnd</code> parameter from <code>windowproc</code> through to <code>handlemessage</code>. Another is to add</p> <pre><code>m_hWnd = hWnd; </code></pre> <p>in your <code>if(uMsg == WM_NCCREATE)</code>.</p> <p>Notice that your code assumes that if <code>GWLP_USERDATA</code> is nonzero, then <code>m_hWnd</code> is valid. However, you did nothing to actually make this assumption valid. Between the receipt of the <code>WM_NCCREATE</code> message and the completion of <code>CreateWindowEx</code>, you have a nonzero <code>GWLP_USREDATA</code> but <code>m_hWnd</code> is not initialized.</p> <p>The way to debug this is to set a breakpoint on your window procedure and step through it. When stepping through the handling of the <code>WM_NCCREATE</code> message, you should have noticed that <code>m_hWnd</code> is not initialized.</p> <p>There is a third bug in this code, which you would eventually stumble across once you get the window created: You never set <code>m_hWnd</code> back to <code>NULL</code> when the window is destroyed.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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