title: SendMessage vs. WndProc
body: <p>I'm trying to extend <code>TextBox</code> control to add watermarking functionality. The example I've found on CodeProject is using imported SendMessage function.</p>
  
  <pre><code>[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
  static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
  
  void SetWatermark()
  {
      SendMessage(this.Handle, 0x1501, 0, "Sample");
  }
  </code></pre>
  
  <p>I'm wondering why not use protected WndProc instead</p>
  
  <pre><code>void SetWatermark()
  {
      var m =new Message() { HWnd = this.Handle, Msg = 0x1501, WParam = (IntPtr)0, LParam = Marshal.StringToHGlobalUni("Sample") };
      WndProc(ref m);
  }
  </code></pre>
  
  <p>Both seem to work fine. Almost all examples I've seen on internet use <code>SendMessage</code>function. Why is that? Isn't <code>WndProc</code> function designed to replace <code>SendMessage</code>?</p>
  
  <p>P.S. I don't know right to convert <code>string</code> to <code>IntPtr</code> and found that <code>Marshal.StringToHGlobalUni</code> works ok. Is it right function to do this?</p>