winform的简单功能讨论,顶者有分

q198708wyp 2011-11-07 10:56:54
我想做个实现启动的exe添加到自己的控件中,比如说我启动酷狗音乐盒,添加到textbox控件,调整大小遮挡住酷狗的标题栏,自己再加个标题栏,让它看起来更像自己的东西。winform c# 。
...全文
176 26 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
yukai08621 2011-11-08
  • 打赏
  • 举报
回复
很有创意的想法
freemangood 2011-11-08
  • 打赏
  • 举报
回复
楼主实现了,就公布一下代码么

也不枉这么多人支持啊!
Daqing 2011-11-08
  • 打赏
  • 举报
回复
通过API的setwindows可以实现,测试有的可以,有的不行。如果你的exe可包含在窗体中,可以考虑做控件,然后组合在一个mainfrom里
 public partial class RunExeFile : Form
{
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;}
}

public RunExeFile()
{
InitializeComponent();

this.exeName = @"C:\sqlitebrowser_200_b1_win\SQLite Database Browser 2.0 b1.exe";// @"E:\其他资料\金蝶K3 V10.2报表系统用户手册.pdf";

try
{

// Start the process
process = System.Diagnostics.Process.Start(this.exeName);

// Wait for process to be created and enter idle condition
process.WaitForInputIdle();

// Get the main handle
appWin = process.MainWindowHandle;

}

catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Error");
}

// Put it into this form
SetParent(appWin, this.Handle);

// Remove border and whatnot
// SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);
// Move the window to overlay it on this window
MoveWindow(appWin, 0, 0, this.Width-10, this.Height, true);

this.FormClosed += new FormClosedEventHandler(Form_FormClosed);
this.Resize += new EventHandler(Form_Resize);
}
private void Form_FormClosed(object sender, FormClosedEventArgs e)
{
try
{
process.Kill();
}
catch { }
}

private void Form_Resize(object sender, EventArgs e)
{
if (this.appWin != IntPtr.Zero)
{
MoveWindow(appWin, 0, 0, this.Width-10, this.Height, true);
}
//base.OnResize(e);
}

private void ShowPDF_FormClosing(object sender, FormClosingEventArgs e)
{
Graphics gs = this.CreateGraphics();
gs.DrawRectangle(new Pen(new SolidBrush(Color.Black)), new Rectangle(new Point(0, 0), new Size(this.Width, this.Height)));

if (MessageBox.Show("是否关闭!", "information", MessageBoxButtons.OKCancel) == DialogResult.OK)
{

e.Cancel = false;
}
else
{
e.Cancel = true;
this.Enabled = true;
}
}



}
-汪帆- 2011-11-08
  • 打赏
  • 举报
回复
使用平台调用,将.exe窗体嵌入.net窗体
http://blog.csdn.net/bigeyescat/article/details/5966540
Just4life 2011-11-08
  • 打赏
  • 举报
回复
楼主描述问题的能力不是很强

获取启动的进程的句柄(这个得加一个监视的功能了),之后移动窗体并拦截最大化,最小化,标题栏上的操作
gaozqq 2011-11-08
  • 打赏
  • 举报
回复
有那功夫都快开发出一个了!
幸福小6 2011-11-08
  • 打赏
  • 举报
回复
这个监视exe启动的,会不会被当做病毒干掉啊?
LZ野心很大.
congplayer 2011-11-08
  • 打赏
  • 举报
回复
lz野心大了
q198708wyp 2011-11-08
  • 打赏
  • 举报
回复
本人 已经实现了,这个分数看来只能浪费一半了 没有一个答案让我满意,实现的效果,和我问题中描述的一样
hudenq 2011-11-07
  • 打赏
  • 举报
回复
来看热闹的
mm393439135 2011-11-07
  • 打赏
  • 举报
回复
楼上这位朋友 你能给出代码么
z405158579 2011-11-07
  • 打赏
  • 举报
回复
获取桌面酷狗的程序名.exe 然后在winform启动代码里添加获取到桌面的酷狗程序 当你点击你的exe,
酷狗跟随启动,你的exe设置为可拖放大小,让酷狗出现在你的txtbox文本框里
donet菜鸟 2011-11-07
  • 打赏
  • 举报
回复
句柄..
q198708wyp 2011-11-07
  • 打赏
  • 举报
回复
哪位大哥能帮到我 我给他300分
至尊贱客 2011-11-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 juliohuang 的回复:]
楼主野心很大啊
[/Quote]

楼主想把腾讯的精神发扬光大啊
黄亮 2011-11-07
  • 打赏
  • 举报
回复
楼主野心很大啊
支持海贼王 2011-11-07
  • 打赏
  • 举报
回复
如果你想用的软件,如酷狗,支持插件,那你开发一个插件,用酷狗启动,那样做没问题。如果你直接要这样拿过来不可能的。
Bullatus 2011-11-07
  • 打赏
  • 举报
回复
挡住?那是不是也要处理最小化/最大化/移动呢?
如何被启动的程序不是你的程序,那就有的你忙了
q198708wyp 2011-11-07
  • 打赏
  • 举报
回复
会的支支招啊,会的话,就不来问了啊
tanghuawei 2011-11-07
  • 打赏
  • 举报
回复
呵呵,确实不太清楚这样的实际意义
加载更多回复(5)

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧