Based in this example i'm wanting create a Modal Dialog Form inside new desktop created by CreateDesktop api. Until now i'm able to show Modal Dialog Form inside new desktop, but i don't know how create a background window with screenshot for also show inside new desktop together Modal Dialog Form.
So, someone can help me with this task?
Thank you to all.
DlgMain.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
namespace ScreenLockerDemo
{
public partial class DlgMain : Form
{
public DlgMain()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);
[DllImport("user32.dll")]
public static extern bool CloseDesktop(IntPtr handle);
[DllImport("user32.dll")]
public static extern bool SetThreadDesktop(IntPtr hDesktop);
[DllImport("user32.dll")]
public static extern IntPtr GetThreadDesktop(int dwThreadId);
[DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId();
enum DESKTOP_ACCESS : uint
{
DESKTOP_NONE = 0,
DESKTOP_READOBJECTS = 0x0001,
DESKTOP_CREATEWINDOW = 0x0002,
DESKTOP_CREATEMENU = 0x0004,
DESKTOP_HOOKCONTROL = 0x0008,
DESKTOP_JOURNALRECORD = 0x0010,
DESKTOP_JOURNALPLAYBACK = 0x0020,
DESKTOP_ENUMERATE = 0x0040,
DESKTOP_WRITEOBJECTS = 0x0080,
DESKTOP_SWITCHDESKTOP = 0x0100,
GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP),
}
private void buttonLockScreen_Click(object sender, EventArgs e)
{
// old desktop's handle, obtained by getting the current desktop assigned for this thread
IntPtr hOldDesktop = GetThreadDesktop(GetCurrentThreadId());
// new desktop's handle, assigned automatically by CreateDesktop
IntPtr hNewDesktop = CreateDesktop("RandomDesktopName", IntPtr.Zero, IntPtr.Zero, 0, (uint)DESKTOP_ACCESS.GENERIC_ALL, IntPtr.Zero);
// switching to the new desktop
SwitchDesktop(hNewDesktop);
// running on a different thread, this way SetThreadDesktop won't fail
Task.Factory.StartNew(() =>
{
// assigning the new desktop to this thread - so the Modal Dialog Form will be shown in the new desktop)
SetThreadDesktop(hNewDesktop);
Background Bkgfrm = new Background();
Bkgfrm.Show();
DlgLock DialogLock = new DlgLock();
DialogLock.ShowDialog(Bkgfrm);
}).Wait(); // waits for the task to finish
// end of modal form
// if got here, the form is closed => switch back to the old desktop
SwitchDesktop(hOldDesktop);
// disposing the secure desktop since it's no longer needed
CloseDesktop(hNewDesktop);
}
}
}
DlgLock.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ScreenLockerDemo
{
public partial class DlgLock : Form
{
public DlgLock()
{
InitializeComponent();
}
private void buttonClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
Background.cs
namespace ScreenLockerDemo
{
public partial class Background : Form
{
public Background()
{
InitializeComponent();
}
private void print(Bitmap BM, PaintEventArgs e)
{
Graphics graphicsObj = e.Graphics;
graphicsObj.DrawImage(BM, 60, 10);
// graphicsObj.Dispose();
}
public void Background_Load(object sender, EventArgs e)
{
Paint += new PaintEventHandler(Background_Paint);
}
private void Background_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = Screen.PrimaryScreen.Bounds;
int color = Screen.PrimaryScreen.BitsPerPixel;
PixelFormat pf;
pf = PixelFormat.Format32bppArgb;
Bitmap BM = new Bitmap(rect.Width, rect.Height, pf);
// Bitmap BM = new Bitmap(Image.FromFile(#"C:\Users\NZT48\Desktop\ScreenLockerDemo\bin\Debug\1.jpg"), rect.Width, rect.Height);
Graphics g = Graphics.FromImage(BM);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
Bitmap bitamp = new Bitmap(BM);
print(bitamp, e);
}
private void Background_Shown(object sender, EventArgs e)
{
// Paint += new PaintEventHandler(Background_Paint);
}
}
}
Related
I tried to make my own autoclicker. Everything went fine.
But when i press the button it only changes status from off to on.. but nothing happens.
I tried very long time to check for errors but i didnt find any.
This is my script so if you find any errors please tell me!
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace BetaClicker
{
public partial class form1 : Form
{
[DllImport(dllName:"user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
private const int LEFTUP = 0x0004;
private const int LEFTDOWN = 0x0002;
public form1()
{
InitializeComponent();
}
private void clicktimer_Tick(object sender, EventArgs e)
{
Random rnd = new Random();
int maxcps = (int)Math.Round(1000.0 / (trackBar1.Value + trackBar2.Value * 0.2));
int mincps = (int)Math.Round(1000.0 / (trackBar1.Value + trackBar2.Value * 0.4));
try
{
clicktimer.Interval = rnd.Next(mincps, maxcps);
}
catch
{
//Ignored
}
bool mousdown = MouseButtons == MouseButtons.Left;
if (mousdown)
{
mouse_event(dwFlags:LEFTDOWN, dx:0,dy:0,cButtons:0,dwExtraInfo:0);
Thread.Sleep(millisecondsTimeout: rnd.Next(1, 6));
mouse_event(dwFlags: LEFTUP, dx: 0, dy: 0, cButtons: 0, dwExtraInfo: 0);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text.Contains("on"))
{
clicktimer.Start();
button1.Text = "Toggle: off";
}
else
{
clicktimer.Stop();
button1.Text = "Toggle: on";
}
}
}
}
I can suggest you to change the portion of code where you click with the following:
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(LEFTDOWN | LEFTUP, X, Y, 0, 0);
I think that your problem is that you start clicking but always in the position of the screen at the coordinates (0, 0) so nothing happens.
Also you don't actually need a timeout from the LEFTDOWN action and the LEFTUP one
If you don't want to click where your cursor is just set X and Y with your desired values (coordinates)
What I am trying to do is just set my from, that has a picture box on it, to be the top most object on my computer and stay that way. I have tried to use f.topmost = true; but if when I click on something my form is no longer top most.
I am running my form from a dll (code of dll is below). I have also tried to add in a on load even to my form, which also did nothing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace pic
{
public class Class1
{
[DllImport("user32.dll", SetLastError = true)]
private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public const int GWL_EXSTYLE = -20;
public const int WS_EX_LAYERED = 0x80000;
public const int WS_EX_TRANSPARENT = 0x20;
public const int LWA_ALPHA = 0x2;
public const int LWA_COLORKEY = 0x1;
Form f = new Form();
public void t(int LocalX, int LocalY, string PicLocal, byte transparency)
{
f.Load += new EventHandler(ProgramViwer_Load);
Bitmap bitmap;
// Form f = new Form();
f.BackColor = Color.White;
f.FormBorderStyle = FormBorderStyle.None;
f.Bounds = Screen.PrimaryScreen.Bounds;
bitmap = new Bitmap(PicLocal);
f.Size = new Size(bitmap.Size.Width, bitmap.Size.Height);
f.StartPosition = FormStartPosition.Manual;
f.SetDesktopLocation(LocalX, LocalY);
Application.EnableVisualStyles();
PictureBox PictureBox1 = new PictureBox();
PictureBox1.Location = new System.Drawing.Point(0, 0);
PictureBox1.Image = bitmap;
PictureBox1.Size = new System.Drawing.Size(bitmap.Size.Width, bitmap.Size.Height);
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
f.Controls.Add(PictureBox1);
f.AllowTransparency = true;
SetWindowLong(f.Handle, GWL_EXSTYLE,
(IntPtr)(GetWindowLong(f.Handle, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT));
// set transparency to 50% (128)
SetLayeredWindowAttributes(f.Handle, 0, transparency, LWA_ALPHA);
Color BackColor = Color.White;
f.TransparencyKey = BackColor;
f.Opacity = transparency / 255f;
Application.Run(f);
}
private void ProgramViwer_Load(object sender, EventArgs e)
{
f.TopMost = true;
}
}
}
Your problem is that other windows set their 'TopMost' property to true as well. It's not the cleanest solution but it should work.
new Thread(() =>
{
try
{
while (true)
{
this.TopMost = true;
Thread.Sleep(1);
}
}
catch (Exception ex) { }
}).Start();
I've WPF application which has one Main window on which I'm opening a Popup window. The problem I'm facing is the Popup window always stays on top. If I open some other application(any windows application) the main window goes into background but the Popup windows remain on top.However if I minimize the Mainwindow the Popup also minimizes.
Please help on overcoming this issue.
Update:
I am opening the Popup as below
myPopup.IsOpen = true;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
/// <summary>
/// Popup with code to not be the topmost control
/// </summary>
public class NonTopmostPopup : Popup
{
/// <summary>
/// Is Topmost dependency property
/// </summary>
public static readonly DependencyProperty IsTopmostProperty = DependencyProperty.Register("IsTopmost", typeof(bool), typeof(NonTopmostPopup), new FrameworkPropertyMetadata(false, OnIsTopmostChanged));
private bool? _appliedTopMost;
private bool _alreadyLoaded;
private Window _parentWindow;
/// <summary>
/// Get/Set IsTopmost
/// </summary>
public bool IsTopmost
{
get { return (bool)GetValue(IsTopmostProperty); }
set { SetValue(IsTopmostProperty, value); }
}
/// <summary>
/// ctor
/// </summary>
public NonTopmostPopup()
{
Loaded += OnPopupLoaded;
Unloaded += OnPopupUnloaded;
}
void OnPopupLoaded(object sender, RoutedEventArgs e)
{
if (_alreadyLoaded)
return;
_alreadyLoaded = true;
if (Child != null)
{
Child.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnChildPreviewMouseLeftButtonDown), true);
}
_parentWindow = Window.GetWindow(this);
if (_parentWindow == null)
return;
_parentWindow.Activated += OnParentWindowActivated;
_parentWindow.Deactivated += OnParentWindowDeactivated;
}
private void OnPopupUnloaded(object sender, RoutedEventArgs e)
{
if (_parentWindow == null)
return;
_parentWindow.Activated -= OnParentWindowActivated;
_parentWindow.Deactivated -= OnParentWindowDeactivated;
}
void OnParentWindowActivated(object sender, EventArgs e)
{
Debug.WriteLine("Parent Window Activated");
SetTopmostState(true);
}
void OnParentWindowDeactivated(object sender, EventArgs e)
{
Debug.WriteLine("Parent Window Deactivated");
if (IsTopmost == false)
{
SetTopmostState(IsTopmost);
}
}
void OnChildPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Debug.WriteLine("Child Mouse Left Button Down");
SetTopmostState(true);
if (!_parentWindow.IsActive && IsTopmost == false)
{
_parentWindow.Activate();
Debug.WriteLine("Activating Parent from child Left Button Down");
}
}
private static void OnIsTopmostChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var thisobj = (NonTopmostPopup)obj;
thisobj.SetTopmostState(thisobj.IsTopmost);
}
protected override void OnOpened(EventArgs e)
{
SetTopmostState(IsTopmost);
base.OnOpened(e);
}
private void SetTopmostState(bool isTop)
{
// Don’t apply state if it’s the same as incoming state
if (_appliedTopMost.HasValue && _appliedTopMost == isTop)
{
return;
}
if (Child == null)
return;
var hwndSource = (PresentationSource.FromVisual(Child)) as HwndSource;
if (hwndSource == null)
return;
var hwnd = hwndSource.Handle;
RECT rect;
if (!GetWindowRect(hwnd, out rect))
return;
Debug.WriteLine("setting z-order " + isTop);
if (isTop)
{
SetWindowPos(hwnd, HWND_TOPMOST, rect.Left, rect.Top, (int)Width, (int)Height, TOPMOST_FLAGS);
}
else
{
// Z-Order would only get refreshed/reflected if clicking the
// the titlebar (as opposed to other parts of the external
// window) unless I first set the popup to HWND_BOTTOM
// then HWND_TOP before HWND_NOTOPMOST
SetWindowPos(hwnd, HWND_BOTTOM, rect.Left, rect.Top, (int)Width, (int)Height, TOPMOST_FLAGS);
SetWindowPos(hwnd, HWND_TOP, rect.Left, rect.Top, (int)Width, (int)Height, TOPMOST_FLAGS);
SetWindowPos(hwnd, HWND_NOTOPMOST, rect.Left, rect.Top, (int)Width, (int)Height, TOPMOST_FLAGS);
}
_appliedTopMost = isTop;
}
#region P/Invoke imports & definitions
#pragma warning disable 1591 //Xml-doc
#pragma warning disable 169 //Never used-warning
// ReSharper disable InconsistentNaming
// Imports etc. with their naming rules
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
private const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOZORDER = 0x0004;
const UInt32 SWP_NOREDRAW = 0x0008;
const UInt32 SWP_NOACTIVATE = 0x0010;
const UInt32 SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */
const UInt32 SWP_SHOWWINDOW = 0x0040;
const UInt32 SWP_HIDEWINDOW = 0x0080;
const UInt32 SWP_NOCOPYBITS = 0x0100;
const UInt32 SWP_NOOWNERZORDER = 0x0200; /* Don’t do owner Z ordering */
const UInt32 SWP_NOSENDCHANGING = 0x0400; /* Don’t send WM_WINDOWPOSCHANGING */
const UInt32 TOPMOST_FLAGS =
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSENDCHANGING;
// ReSharper restore InconsistentNaming
#pragma warning restore 1591
#pragma warning restore 169
#endregion
}
Popups do - as far as i know - not suppot such a behavior, their intended usage is for ComboxBox-dropdowns and the like as far as i can tell. To realize something like that you can use a normal Window and set its Owner to the main window on which it should be dependent. This will cause the popup-window to stay on top of its owner & to minimize together with the owner.
e.g.
public class ChildWindow: Window
{
public ChildWindow(Window owner)
{
this.Owner = owner;
}
}
var popup = new ChildWindow(mainWindow);
popup.Show();
(Windows cannot be re-opened once closed, so to reuse a window you just have to Hide() it when the user tries to close it (handle Closing event and cancel using event args))
H.B. is correct - WPF Popup control was not intended do be not top-most. On the other hand - check out the following blog post on using user32 for achieving your goal:
http://chriscavanagh.wordpress.com/2008/08/13/non-topmost-wpf-popup/
Are you creating the PopUp using the WPF control? The way this control paints popup leads to the behaviour you are describing.
Consider creating a new Window showing the content you´d like to display.
Check the Window.Topmost property whitch is indicates that window should be always on top.
PopupWindow wnd = new PopupWindow();
wnd.ShowDialog();
This solved my problem.
PopupForm pf = new PopupForm();
pf.Owner = this;
pf.Topmost = false;
pf.ShowDialog()
By default popups were designed to behaves as you comment, to be topmost always. Altering this behavior using hacks or things like that will complicate your life since you will have to lead with some other problems that for sure will arise.
Anyway, too late, but may be this can help you or others:
https://chriscavanagh.wordpress.com/2008/08/13/non-topmost-wpf-popup/
Note that this has some issues.... read all the comments published there. Among other issues, it makes all childs to be non-topmost so comboboxes are affected. Comboboxes will have problems with it as they rely on having a topmost popup for when they are drop down, so if you have any combobox inside your popup it will break.
Also there are other problems related to the popup position, when you resize and then move the main window where the popup is it, popup remains in the same position.
People there are proposing some approaches for these issues. I don't know if all are resolved but you can give it a try or try to resolve them if it is up to you.
Other people trying to face with this are explaining their proposals here also (although none of them seems to be the perfect solution, it looks like there is not a perfect one, all of them have drawnbacks, but again as I have said, trying to alter the default behavior for which a thing was designed for will lead into continuous problems) :
WPF Popup ZOrder
Create your PopUp window modal to the parent control only, as demonstrated by Billy Holli and Brad Leach. That way it will stay on top of the application/window which opened the popup control, but will not stay on top of other windows/applications any longer.
Short Question:
How can I draw a copy of a hidden ActiveX control to a Bitmap?
Longer Question:
I have an ActiveX control which displays an Image. I would like to hide it behind something (example a panel), copy the display to a Bitmap so as to be able to process it (example access the pixels etc).
the trick is that you should use WM_PAINT
[Flags]
private enum DrawingOptions
{
PRF_CHECKVISIBLE = 0x00000001,
PRF_NONCLIENT = 0x00000002,
PRF_CLIENT = 0x00000004,
PRF_ERASEBKGND = 0x00000008,
PRF_CHILDREN = 0x00000010,
PRF_OWNED = 0x00000020
}
private const uint WM_PAINT = 0xF;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr dc, DrawingOptions opts);
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
using (Bitmap bm = new Bitmap(axChartSpace1.Width, axChartSpace1.Height))
{
using (Graphics g = Graphics.FromImage(bm))
{
IntPtr dc = g.GetHdc();
try
{
SendMessage(axChartSpace1.Handle, WM_PRINT, dc,
DrawingOptions.PRF_CLIENT |
DrawingOptions.PRF_NONCLIENT |
DrawingOptions.PRF_CHILDREN);
}
finally
{
g.ReleaseHdc();
}
bm.Save(#"C:\1.bmp");
}
}
}
I'm writing a windows forms application in C# whereby some windows utilities can be launched (e.g. CMD prompt, Registry editor, Events Viewer etc) and placed in an MdiClient control on the main form.
Everything is working great except that the scroll bars in the MdiClient control aren't automatically appearing when a child window falls beyond the MdiClient's borders. If the child windows were windows forms then I know that the MdiClient's scroll bars would automatically appear as expected. I've tried many things, including some complex workarounds.. and i'm beginning to think there must be something i'm completely overlooking.
I have attached some sample code below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
namespace MdiClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Windows.Forms.MdiClient mdiClient = new System.Windows.Forms.MdiClient();
mdiClient.Dock = DockStyle.Fill;
mdiClient.BackColor = Color.WhiteSmoke;
this.Controls.Add(mdiClient);
int processID = StartCMD();
AddToMDIClient(processID, mdiClient.Handle);
}
private int StartCMD()
{
int processID = -1;
using (Process process = new Process())
{
ProcessStartInfo startInfo = process.StartInfo;
startInfo.FileName = "cmd.exe";
try
{
process.Start();
processID = process.Id;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return processID;
}
private void AddToMDIClient(int processID, IntPtr mdiClientHandle)
{
try
{
Process process = Process.GetProcessById(processID);
int numberOfAttempts = 0;
while (string.IsNullOrEmpty(process.MainWindowTitle) && numberOfAttempts < 30)//max of 3 seconds
{
Thread.Sleep(100);
process.Refresh();
numberOfAttempts++;
}
if (!string.IsNullOrEmpty(process.MainWindowTitle))
{
SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 1, 1, 0, 0, TOPMOST_FLAGS);
SetParent(process.MainWindowHandle, mdiClientHandle);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
public const UInt32 TOPMOST_FLAGS = /*SWP_NOMOVE | */SWP_NOSIZE;
public const UInt32 SWP_NOSIZE = 0x0001;
}
}
The screenshot below shows that when the CMD window is moved so its borders are outside the borders of the MdiClient there are no scroll bars:
Please see this link for the image: http://picasaweb.google.com/lh/photo/75rMVJMCWRg_s_DFF6LmNg?authkey=Gv1sRgCIKRlsu8xuDh8AE&feat=directlink
Any help would be much appreciated!
Thanks,
Shady
Without the screenshot it is hard to say, but I think the way you create the MDIParanet is way too complicated.
private void Form1_Load(object sender, EventArgs e)
{
// System.Windows.Forms.MdiClient mdiClient = new System.Windows.Forms.MdiClient();
// mdiClient.Dock = DockStyle.Fill;
// mdiClient.BackColor = Color.WhiteSmoke;
// this.Controls.Add(mdiClient);
this.IsMdiContainer = true;
int processID = StartCMD();
AddToMDIClient(processID, mdiClient.Handle);
}
If you need the Client, you can filter it from Controls.
Another problem might be setting a MDIChild as TOP_MOST, I don't think that's a good combination.
I have been doing some testing and it work ok for me was long as I have Autoscroll = true in the forms properties.
Also, I noticed if you enlarge the form and move the command window to say the bottom right it will not show the scroll bars, it will only when you minimize the form past the command windows (see screenshots below)
Screenshot 1
http://picasaweb.google.com/lh/photo/rfwm-S8y06Fl3HFNshgj3g?feat=directlink
Screenshot 2
http://picasaweb.google.com/lh/photo/y6qkN9Jj19vDGFNkTuL4FQ?feat=directlink
Also, can you set on the Form's properties AutoScrollMinSize, so that you always have scroll bars in the form is smaller than the size set
Hope that helps
Josh