title: Error on SetWindowPos
body: <p>I'm trying to write simple code for changing an application (notepad) windows position. Notepad should be running in background (only 1 instance).</p>
  
  <p>I am using <code>Process::GetProcessesByName( "notepad")</code> to get the process ID,
  and <code>myProcess-&gt;MainWindowHandle</code> to get the notepad windows handle.</p>
  
  <p>Now I am trying to change window size by passing the HWND handle to SetWindowPos,</p>
  
  <p>I am not sure how to correctly do it (searched the web didn't find a clear newbie-answer)</p>
  
  <p>1st I tried:</p>
  
  <pre><code>HWND hwnd =  myProcess-&gt;MainWindowHandle;
               SetWindowPos(hwnd , 
                   HWND_TOP, 
                   100, 
                   100, 
                   0, 0,          // Ignores size arguments. 
                   SWP_NOSIZE); 
  </code></pre>
  
  <p>This got me</p>
  
  <pre><code>Compile error:  error C2440: 'initializing' : cannot convert from 'System::IntPtr' to 'HWND'
  </code></pre>
  
  <p>Then I tried casting and passing as reference:</p>
  
  <pre><code>HWND hwnd =  (HWND)&amp;myProcess-&gt;MainWindowHandle;
  SetWindowPos(&amp;hwnd , 
           HWND_TOP, 
           100, 
           100, 
           0, 0,          // Ignores size arguments. 
           SWP_NOSIZE); 
  
         }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Compile error:  error C2664: 'SetWindowPos' : cannot convert parameter 1 from 'HWND *' to 'HWND'
  </code></pre>
  
  <p>See below for complete code:</p>
  
  <pre><code>#include "StdAfx.h"
  #include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;  
  
  #using &lt;System.dll&gt;
  using namespace System;
  using namespace System::Diagnostics;
  int main()
  {
  
        array&lt;Process^&gt;^myProcesses = Process::GetProcessesByName( "notepad");
        if ( myProcesses-&gt;Length == 0 )
              Console::WriteLine( "Could not find notepad processes on local computer." );
        Collections::IEnumerator^ myEnum = myProcesses-&gt;GetEnumerator();
        while ( myEnum-&gt;MoveNext() )
        {
           Process^ myProcess = safe_cast&lt;Process^&gt;(myEnum-&gt;Current);
           Console::Write( "Process Name : {0}  Process ID : {1}  HandleCount : {2}\n", myProcess-&gt;ProcessName, myProcess-&gt;Id, myProcess-&gt;HandleCount );
           Console::Write( "Main window Title : {0}  MainWindowHandle : {1}", myProcess-&gt;MainWindowTitle, myProcess-&gt;MainWindowHandle );
  
  //HWND hwnd =  myProcess-&gt;MainWindowHandle; //1st try
       //          SetWindowPos(hwnd , 
    //               HWND_TOP, 
    //               100, 
    //               100, 
    //               0, 0,          // Ignores size arguments. 
    //               SWP_NOSIZE); 
  
          HWND hwnd =  (HWND)&amp;myProcess-&gt;MainWindowHandle;//2nd try
          SetWindowPos(&amp;hwnd , 
                   HWND_TOP, 
                   100, 
                   100, 
                   0, 0,          // Ignores size arguments. 
                   SWP_NOSIZE); 
  
                 }
        }   
  }
  </code></pre>