title: WinAPI ShowWindow fails even though CreateWindowEx seemingly succeeds
body: <p>I am having trouble using <strong>CreateWindowEx</strong>. If I set the final parameter (LPVOID lpParam) to NULL and use the returned window handle in a call to <strong>ShowWindow</strong>, the window displays everything fine. However, I need to pass in a pointer to the class that I will be modifying based off of some of the operating system messages that I intercept. When I try to do that, by specifying the <strong>lpParam</strong> as <strong>this</strong>, my returned handle is apparently garbage because passing it into <strong>ShowWindow</strong> causes: "An unhandled exception was encountered during a user callback."</p>
  
  <p>I have no idea how to debug this, so I am stuck.</p>
  
  <p>The address that is pointed to remains the same between passing it in and pulling it back out.</p>
  
  <p>I did not define a WM_PAINT case.</p>
  
  <p>WM_CREATE handler:</p>
  
  <pre><code>case WM_CREATE:
  {
  
              // get screen resolution
              HWND desktop = GetDesktopWindow();
              RECT R;
              GetWindowRect(desktop, &amp;R);
              int width = R.right - R.left;
              int height = R.bottom - R.top;
  
              HWND loading_image;
              loading_image = CreateWindowEx(0,L"Static",L"Image", SS_CENTERIMAGE | SS_BITMAP | WS_CHILD | WS_VISIBLE,0,0,width,height,hwnd,(HMENU)ID_IMAGE3,g_hInst,NULL); 
              SetClassLong(loading_image,GCL_STYLE,CS_HREDRAW | CS_VREDRAW);
              HBITMAP bitmap = (HBITMAP)LoadImage(NULL,L"loadingscreen.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
              SendMessage(loading_image,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)bitmap);
  
              progressbar = CreateWindowEx(0, PROGRESS_CLASS, (LPTSTR)NULL, WS_CHILD | PBS_SMOOTH | WS_VISIBLE, width/2-400,100,800,20,hwnd,(HMENU)0,g_hInst,NULL);
              SendMessage(progressbar,PBM_SETSTEP,20,NULL);
  
              CREATESTRUCT* cs = (CREATESTRUCT*)lParam;
              app = (D3DApp*)cs-&gt;lpCreateParams;
              return 0;
  }
  </code></pre>
  
  <p>The WindowProc call goes bad on a 70 msg (WM_WINDOWPOSCHANGING). It doesn't go bad on prior messages: WM_NCCALCSIZE, WM_CREATE, WM_PARENTNOTIFY, WM_SIZE, WM_SIZE, or WM_SHOWWINDOW, although WM_SHOWWINDOW is handled just before WM_WINDOWPOSCHANGING, so I'm guessing WM_WINDOWPOSCHANGING is just a result of WM_SHOWWINDOW getting passed.</p>