- 博客(0)
- 资源 (3)
- 收藏
- 关注
如何在容器中显示.exe文件
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.Runtime.InteropServices;
namespace exe_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Process process = null;
IntPtr appWin;
private string exeName = "";
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern long GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
//private static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
private static extern bool PostMessage(IntPtr hwnd, uint Msg, long wParam, long lParam);
private const int SWP_NOOWNERZORDER = 0x200;
private const int SWP_NOREDRAW = 0x8;
private const int SWP_NOZORDER = 0x4;
private const int SWP_SHOWWINDOW = 0x0040;
private const int WS_EX_MDICHILD = 0x40;
private const int SWP_FRAMECHANGED = 0x20;
private const int SWP_NOACTIVATE = 0x10;
private const int SWP_ASYNCWINDOWPOS = 0x4000;
private const int SWP_NOMOVE = 0x2;
private const int SWP_NOSIZE = 0x1;
private const int GWL_STYLE = (-16);
private const int WS_VISIBLE = 0x10000000;
private const int WM_CLOSE = 0x10;
private const int WS_CHILD = 0x40000000;
public string ExeName
{
get
{
return exeName;
}
set
{
exeName = value;
}
}
private void button1_Click(object sender, EventArgs e)
{
this.exeName = @"calc.exe";
try
{
process = System.Diagnostics.Process.Start(this.exeName);
process.WaitForInputIdle();
System.Threading.Thread.Sleep(150);
appWin = process.MainWindowHandle;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Error");
}
SetParent(appWin, this.splitContainer1.Panel2.Handle);
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
}
}
}
2011-12-05
可跑一分钟的进度条
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;
namespace 滚动条
{
public partial class Form1 : Form
{
private Random _random;
public Form1()
{
InitializeComponent();
label4.Visible = true;
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
_random = new Random();
}
private void timer1_Tick(object sender, EventArgs e)
{
////int length = 111111111;
////if (progressBar1.Minimum + length >progressBar1.Value++)
////{
//// progressBar1.Minimum = 0;
////}
////else
////{
//// progressBar1.Minimum += length;
////}
//int length = 10;
//if (progressBar1.Value < progressBar1.Maximum)
//{
// progressBar1.Value = progressBar1.Value + length;
//}
int length = 10;
if (progressBar1.Value < progressBar1.Maximum)
{
progressBar1.Value = progressBar1.Value + length;
label4.Text = progressBar1.Value.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
2011-12-05
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人