title: Set specific size to application's window programmatically
body: <p>My program (C#) is a taskbar and in its menu I can launch applications, compatible XP to 8.1. I would like to start any applications with a specific window's size, because few applications (OpenOffice, LibreOffice...), start flattened when i launch them for the first time.</p>
  
  <p>I've tested to maximize this window with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx" rel="nofollow">ShellExecute</a> with <a href="http://www.pinvoke.net/default.aspx/shell32.shellexecute" rel="nofollow">ShowCommands.SW_MAXIMIZE</a> parameter: </p>
  
  <pre><code>ShellExecute(IntPtr.Zero, "open", executablePath, executableParam, "", ShowCommands.SW_MAXIMIZE);
  </code></pre>
  
  <p>But when I clicked on the "restore" button of the window, there is the same problem, the window is flattened.</p>
  
  <p>While the "restored" size isn't configured by manual resizing, the used value is specific for each applications.</p>
  
  <p>Instead of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx" rel="nofollow">ShellExecute</a>, I use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx" rel="nofollow">CreateProcess</a> to specify a size :</p>
  
  <pre><code>const uint NORMAL_PRIORITY_CLASS = 0x0020;
  STARTUPINFO si = new STARTUPINFO();
  si.dwY = 50;
  si.dwX = 50;
  si.dwXSize = 200;
  si.dwYSize = 800;
  si.dwFlags = 0x00000006; //STARTF_USESIZE + STARTF_USEPOSITION
  PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
  
  CreateProcess(programPath, programParams, IntPtr.Zero, IntPtr.Zero, true, NORMAL_PRIORITY_CLASS, IntPtr.Zero, null, ref si, out pi);
  </code></pre>
  
  <p>But there is one problem, we can launch an other OpenOffice/LibreOffice process with File->New->... In this case the application isn't launch by my program so my default size isn't applied.</p>
  
  <p>I've checked the Windows Registry before and after changing this value, two keys are changed :</p>
  
  <pre><code>[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU\reg]
  [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{CEBFF5CD-ACE2-4F4F-9178-9926F41749EA}\Count]
  </code></pre>
  
  <p>These keys contains hexa values (first key) : </p>
  
  <p>before :</p>
  
  <pre><code>"MRUListEx"=hex:00,00,00,00,04,00,00,00,01,00,00,00,05,00,00,00,03,00,00,00,02,\00,00,00,ff,ff,ff,ff
  </code></pre>
  
  <p>after : </p>
  
  <pre><code>"MRUListEx"=hex:01,00,00,00,00,00,00,00,04,00,00,00,05,00,00,00,03,00,00,00,02,\00,00,00,ff,ff,ff,ff
  </code></pre>
  
  <p>It isn't understandable to me, so I'm still searching if exist a programmatic way to specific window size of an application/all applications or an other specification to set into the Windows Registry. I'm not searching a solution to resize or move a window already launched like <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx" rel="nofollow">SetWindowPos</a>.</p>
  
  <p>But many websites explain there's just one solution to define the window's size: "drag the window to the size, then close the window and restart it"</p>
  
  <p><a href="http://help.wfu.edu/public/computers/standard-load-software/windows-7---set-default-window-size" rel="nofollow">http://help.wfu.edu/public/computers/standard-load-software/windows-7---set-default-window-size</a>
  <a href="http://www.tomshardware.co.uk/forum/28659-45-change-default-window-size" rel="nofollow">http://www.tomshardware.co.uk/forum/28659-45-change-default-window-size</a></p>
  
  <p>This answer is the final solution or there is a way to do it programmatically?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT :</strong> </p>
  
  <p>Actually, when a window is restored, I resize only the first time until the user kill it.
  My program keeps every window's handle in an object with a boolean initialized to false to specify if my window has been resized. I use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633505%28v=vs.85%29.aspx" rel="nofollow">GetForegroundWindow</a> then with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633518%28v=vs.85%29.aspx" rel="nofollow">GetWindowPlacement</a> I check if <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632611%28v=vs.85%29.aspx" rel="nofollow">WINDOWPLACEMENT</a>.flags == WindowPlacementFlag.WPF_NONE and if my boolean is always egals to false in that case I use GetWindowRect and SetWindowPos to set a specific size with the same position and assign my boolean to true. </p>
  
  <p>I think is a good solution, but I loose the saved position by user (I can do it when window's size is under a specific value but the problem still there) and we seen the resizing...</p>