title: WIN32 C Properly using SetWindowLongPtr and GetWindowLongPtr
body: <p>Yes this is a homework assignment and I'm completely stumped.</p>
  
  <p>So I've made a struct and two windows:</p>
  
  <pre><code>typedef struct thingy {
  int count;
  TCHAR* MSG;
  COLORREF colour; };
  </code></pre>
  
  <p>The windows have:</p>
  
  <pre><code>wndclass.lpfnWndProc = WndProc;
  wndclass.cbClsExtra = sizeof(thingy*);
  wndclass.cbWndExtra = sizeof(thingy*);
  </code></pre>
  
  <p>I need one window to display 0 and the next to display 1 using this struct stored in the clsextra using SetWindowLongPtr and GetWindowLongPtr/SetClassLongPtr and GetClassLongPtr</p>
  
  <p>Count of course has to be initialized to 0 for the FIRST window but not for the second and I have no idea how to do this. Only one WndProc can be used to do this.</p>
  
  <pre><code>static thingy* mythingy = (thingy*)GetWindowLongPtr(hwnd, 0);
  char buf[128];
  int num = GetClassLongPtr(hwnd, 0);
  static boolean set = false;
  
      case WM_CREATE:
      if (!set) {
          mythingy = (thingy*)malloc(sizeof(thingy));
          mythingy-&gt;count = 0;
          mythingy-&gt;colour = RGB(0, 0, 0);
          mythingy-&gt;MSG = TEXT("Hello Windows!");
          set = true;
      }
      if (lParam != NULL) {
          SetClassLongPtr(hwnd, 0, (LONG)mythingy-&gt;count);
      }
      mythingy-&gt;count++;
      SetWindowLongPtr(hwnd, 0, (LONG)mythingy);
      return 0;
  
  case WM_PAINT:
      hdc = BeginPaint(hwnd, &amp;ps);
  
      GetClientRect(hwnd, &amp;rect);
  
      DrawText(hdc, mythingy-&gt;MSG, -1, &amp;rect,
          DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  
      sprintf_s(buf, "%d", num);
      TextOut(hdc, 0, 0, LPCWSTR(buf), 1);
  
      EndPaint(hwnd, &amp;ps);
      return 0;
  </code></pre>
  
  <p>Right now both windows display 1 and I'm struggling to see why it isn't doing what I want as I can't find anything on Google about how to use these two functions or when I need to be calling them.</p>
  
  <p>Window: 0x000a0528
  count = 0
  Add to class data</p>
  
  <p>Window: 0x001f099a
  count = 1
  Add to class data</p>
  
  <p>From the paint method I get the data and both of them are 1.</p>