How to start new browser window in cpecified location whith cpecified size
Posted
by Pritorian
on Stack Overflow
See other posts from Stack Overflow
or by Pritorian
Published on 2010-03-19T15:46:37Z
Indexed on
2010/03/21
15:01 UTC
Read the original article
Hit count: 441
Hi all! I create a new instance and trying to resize new instance of browser like this:
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool GetWindowInfo(IntPtr hwnd, ref tagWINDOWINFO pwi);
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct tagRECT
{
/// LONG->int
public int left;
/// LONG->int
public int top;
/// LONG->int
public int right;
/// LONG->int
public int bottom;
}
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct tagWINDOWINFO
{
/// DWORD->unsigned int
public uint cbSize;
/// RECT->tagRECT
public tagRECT rcWindow;
/// RECT->tagRECT
public tagRECT rcClient;
/// DWORD->unsigned int
public uint dwStyle;
/// DWORD->unsigned int
public uint dwExStyle;
/// DWORD->unsigned int
public uint dwWindowStatus;
/// UINT->unsigned int
public uint cxWindowBorders;
/// UINT->unsigned int
public uint cyWindowBorders;
/// ATOM->WORD->unsigned short
public ushort atomWindowType;
/// WORD->unsigned short
public ushort wCreatorVersion;
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool UpdateWindow(IntPtr hWnd);
private void button2_Click(object sender, EventArgs e)
{
using (System.Diagnostics.Process browserProc = new System.Diagnostics.Process())
{
browserProc.StartInfo.FileName = webBrowser1.Url.ToString();
browserProc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
int i= browserProc.Id;
tagWINDOWINFO info = new tagWINDOWINFO();
info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
browserProc.Start();
GetWindowInfo(browserProc.MainWindowHandle, ref info);
browserProc.WaitForInputIdle();
string str = browserProc.MainWindowTitle;
MoveWindow(browserProc.MainWindowHandle, 100, 100, 100, 100, true);
UpdateWindow(browserProc.MainWindowHandle);
}
}
But I get an "No process is associated with this object". Could anyone help? Or mb other ideas how to run new browser window whith specified size and location?
© Stack Overflow or respective owner