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.
I've tested to maximize this window with ShellExecute with ShowCommands.SW_MAXIMIZE parameter:
ShellExecute(IntPtr.Zero, "open", executablePath, executableParam, "", ShowCommands.SW_MAXIMIZE);
But when I clicked on the "restore" button of the window, there is the same problem, the window is flattened.
While the "restored" size isn't configured by manual resizing, the used value is specific for each applications.
Instead of ShellExecute, I use CreateProcess to specify a size :
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);
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.
I've checked the Windows Registry before and after changing this value, two keys are changed :
[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]
These keys contains hexa values (first key) :
before :
"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
after :
"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
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 SetWindowPos.
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"
http://help.wfu.edu/public/computers/standard-load-software/windows-7---set-default-window-size
http://www.tomshardware.co.uk/forum/28659-45-change-default-window-size
This answer is the final solution or there is a way to do it programmatically?
Thanks in advance.
EDIT :
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 GetForegroundWindow then with GetWindowPlacement I check if WINDOWPLACEMENT.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.
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...