title: How to update a tab's contents after a TCM_SETCURSEL message
body: <p>I'm trying to change a tab in a page control in another application's window using the WinAPI.</p>
  
  <p>I sent a TCM_SETCURSEL message to the page control, that did change the tab but didn't changed the tab contents. Ex: The Pagecontrol is on tab 0, I send a TCM_SETCURSEL Index: 1 to the page control, the page control is now on tab 1, but keep showing tab 0's contents instead of tab 1's.</p>
  
  <p>I have tried:</p>
  
  <ul>
  <li>send a WM_PAINT to tab 1 after the TCM_SETCURSEL.</li>
  <li>send a WM_NCPAINT to the tab 1 after the TCM_SETCURSEL.</li>
  <li>to send a WM_NOTIFY + TCN_SELCHANGING before the TCM_SETCURSEL and a WM_NOTIFY + TCN_SELCHANGE after it to the page control.</li>
  <li>do the above to the page control's parent.</li>
  </ul>
  
  <p>I'm using delphi 2010 and the target application is also a delphi app.</p>
  
  <p>This is the last code iteration, which sends the notifications to the page control's parent:</p>
  
  <pre><code>procedure ChangeTab(PageControlHandle: HWND; TabIndex: Integer);
  var
    Info: TNMHdr;
  begin
    Info.hwndFrom := PageControlHandle;
    Info.idFrom := GetWindowLongPtr(PageControlHandle, GWL_ID);
    Info.code := TCN_SELCHANGING;
    if SendMessage(GetParent(PageControlHandle), WM_NOTIFY, PageControlHandle, lParam(@Info)) &lt;&gt; 0 then
      raise Exception.Create('Page control didn''t allow tab to change.');
  
    if SendMessage(PageControlHandle, TCM_SETCURSEL, TabIndex, 0) = -1 then
      raise Exception.Create('Failed to change tab.');
  
    Info.code := TCN_SELCHANGE;
    SendMessage(GetParent(PageControlHandle), WM_NOTIFY, PageControlHandle, lParam(@Info))
  end;
  </code></pre>
  
  <p>When I click on tab 1 WinSpy shows that it receives these messages:</p>
  
  <pre><code>&lt;000001&gt; 001D0774 S WM_WINDOWPOSCHANGING lpwp:0018F308
  &lt;000002&gt; 001D0774 R WM_WINDOWPOSCHANGING
  &lt;000003&gt; 001D0774 S WM_CHILDACTIVATE
  &lt;000004&gt; 001D0774 R WM_CHILDACTIVATE
  &lt;000005&gt; 001D0774 S WM_WINDOWPOSCHANGED lpwp:0018F308
  &lt;000006&gt; 001D0774 R WM_WINDOWPOSCHANGED
  &lt;000007&gt; 001D0774 S WM_WINDOWPOSCHANGING lpwp:0018EF7C
  &lt;000008&gt; 001D0774 R WM_WINDOWPOSCHANGING
  &lt;000009&gt; 001D0774 S WM_NCPAINT hrgn:00000001
  &lt;000010&gt; 001D0774 R WM_NCPAINT
  &lt;000011&gt; 001D0774 S WM_ERASEBKGND hdc:33011920
  &lt;000012&gt; 001D0774 R WM_ERASEBKGND fErased:True
  &lt;000013&gt; 001D0774 S WM_WINDOWPOSCHANGED lpwp:0018EF7C
  &lt;000014&gt; 001D0774 R WM_WINDOWPOSCHANGED
  &lt;000015&gt; 001D0774 P WM_PAINT hdc:00000000
  &lt;000016&gt; 001D0774 S WM_CTLCOLORSTATIC hdcStatic:FB01097B hwndStatic:001507D0
  &lt;000017&gt; 001D0774 R WM_CTLCOLORSTATIC hBrush:261011F7
  &lt;000018&gt; 001D0774 S WM_CTLCOLORSTATIC hdcStatic:FB01097B hwndStatic:001507D0
  &lt;000019&gt; 001D0774 R WM_CTLCOLORSTATIC hBrush:261011F7
  &lt;000020&gt; 001D0774 S WM_CTLCOLORSTATIC hdcStatic:530112DB hwndStatic:000608C2
  &lt;000021&gt; 001D0774 R WM_CTLCOLORSTATIC hBrush:261011F7
  &lt;000022&gt; 001D0774 S WM_CTLCOLORSTATIC hdcStatic:530112DB hwndStatic:000608C2
  &lt;000023&gt; 001D0774 R WM_CTLCOLORSTATIC hBrush:261011F7
  &lt;000024&gt; 001D0774 S WM_DRAWITEM idCtl:395458 lpdis:0018F728
  &lt;000025&gt; 001D0774 R WM_DRAWITEM fProcessed:False
  &lt;000026&gt; 001D0774 S WM_CTLCOLOREDIT hdcEdit:FB01097B hwndEdit:000808A8
  &lt;000027&gt; 001D0774 R WM_CTLCOLOREDIT hBrush:3810149A
  &lt;000028&gt; 001D0774 S WM_CTLCOLOREDIT hdcEdit:FB01097B hwndEdit:000808A8
  &lt;000029&gt; 001D0774 R WM_CTLCOLOREDIT hBrush:3810149A
  &lt;000030&gt; 001D0774 S WM_DRAWITEM idCtl:526504 lpdis:0018F728
  &lt;000031&gt; 001D0774 R WM_DRAWITEM fProcessed:False
  &lt;000032&gt; 001D0774 S WM_CTLCOLORSTATIC hdcStatic:530112DB hwndStatic:001A06F2
  &lt;000033&gt; 001D0774 R WM_CTLCOLORSTATIC hBrush:261011F7
  &lt;000034&gt; 001D0774 S WM_CTLCOLORSTATIC hdcStatic:530112DB hwndStatic:001A06F2
  &lt;000035&gt; 001D0774 R WM_CTLCOLORSTATIC hBrush:261011F7
  </code></pre>