views:

327

answers:

2

I want to invalidate the window when it's created. How can I do that? calling InvalidateRect during WM_CREATE doesn't work.

The thing is I call SetWindowLongPtr in WM_CREATE and set GWLP_USERDATA. WM_PAINT looks for some pointer in USER_DATA but the first time I receive WM_PAINT the data isn't apparently still there so it doenst paint my stuff.

Also tried this:

#define MyDefinedMsg (WM_APP+1)
//...//
case WM_CREATE:
  //...//
  SetWindowLongPtr(hWnd,GWLP_USERDATA,ptr);
  PostMessage(hWnd,MyDefinedMsg,0,0);

  break;
case MyDefinedMsg: 
  InvalidateRect(hWnd,NULL,TRUE);
  break;

but did not work.

Thanks in advance

+3  A: 
  1. Your window is already invalid when it is created
  2. PostMessage puts a message in the queue so is likely to arrive after the regular creation messages (WM_CREATE/WM_SIZE/WM_PAINT etc).

If your painting is failing due to GWLP_USERDATA being NULL then something else is happening...

Andrew Grant
Thank you very much. It was a dumm painting problem, but I was sure it had to do with invalidating, don't know why :)
Franco
WM_PAINT generally only happens when there are no other messages in the queue: http://msdn.microsoft.com/en-us/library/dd145213(VS.85).aspx
Mark Ransom
+1  A: 

Try ::UpdateWindow(...) after ::CreateWindow(...) call instead sending your message.

bb