c# 嵌入一个外部程序 如何让这个外部程序窗口最大化

下面是一个最大化按钮代码当abcd程序是主窗口时代码有效但abcd程序嵌入到aa程序中就无效有人说此时要用FindWindowEx但试了几次不成功有高手给个代码吗?aa是... 下面是一个最大化按钮代码 当abcd程序是主窗口时 代码有效 但abcd程序嵌入到aa程序中就无效
有人说此时要用 FindWindowEx 但试了几次不成功 有高手给个代码吗?
aa是主程序 abcd是被嵌入到aa中 该怎么写代码?

private void 最大ToolStripMenuItem_Click(object sender, EventArgs e)
{
IntPtr mainHandle = FindWindow(null, "abcd");
if (mainHandle != null)
{
SetForegroundWindow(mainHandle);
SendMessage(mainHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0); // 最大化
}
}
调用 嵌入最好 请给出代码 感觉你跑题了
你这个太复杂了 先来一个调用的最大化吧 简洁点 就像我上面那个多简单

我的项目中有form1 有个panel 打开外部程序abcd.exe到panel中
另我点了abcd.exe程序的窗口最小化后 abcd.exe程序就找不到了 我想在form1中增加同abcd.exe专门绑定的最小 还原 最大 关闭 4个按钮 用来专门操作程序abcd.exe窗口

谢!请给出代码 主要是最大化按钮 其它按钮还可在abcd.exe程序窗口中按 就是最小化后程序再无法最大化了
展开
 我来答
专家小龙
推荐于2016-06-02 · TA获得超过276个赞
知道小有建树答主
回答量:248
采纳率:66%
帮助的人:60.6万
展开全部
问一句,你是调用还是直接嵌入?下面是直接嵌入的,你改改,这是我以前用到的

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WinWordControl
{
public class DocumentInstanceException : Exception
{}

public class ValidDocumentException : Exception
{}

public class WordInstanceException : Exception
{}

public class WinWordControl : System.Windows.Forms.UserControl
{

[DllImport("user32.dll")]
public static extern int FindWindow(string strclassName, string strWindowName);

[DllImport("user32.dll")]
static extern int SetParent( int hWndChild, int hWndNewParent);

[DllImport("user32.dll", EntryPoint="SetWindowPos")]
static extern bool SetWindowPos(
int hWnd, // handle to window
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags // window-positioning options
);

[DllImport("user32.dll", EntryPoint="MoveWindow")]
static extern bool MoveWindow(
int爃Wnd,
int X,
int Y,
int爊Width,
int爊Height,
bool燽Repaint
);

const int SWP_DRAWFRAME = 0x20;
const int SWP_NOMOVE = 0x2;
const int SWP_NOSIZE = 0x1;
const int SWP_NOZORDER = 0x4;

private Word.Document document;
private static Word.ApplicationClass wd = null;
public static int wordWnd = 0;
private static string filename = null;
private static bool deactivateevents = false;

/// <summary>
/// needed designer variable
/// </summary>
private System.ComponentModel.Container components = null;

public WinWordControl()
{
InitializeComponent();
}

/// <summary>
/// cleanup Ressources
/// </summary>
protected override void Dispose( bool disposing )
{
CloseControl();
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// !do not alter this code! It's designer code
/// </summary>
private void InitializeComponent()
{
//
// WinWordControl
//
this.Name = "WinWordControl";
this.Size = new System.Drawing.Size(440, 336);
this.Resize += new System.EventHandler(this.OnResize);
}
#endregion

/// <summary>
/// Preactivation
/// It's usefull, if you need more speed in the main Program
/// so you can preload Word.
/// </summary>
public void PreActivate()
{
if(wd == null) wd = new Word.ApplicationClass();
}

/// <summary>
/// Close the current Document in the control --> you can
/// load a new one with LoadDocument
/// </summary>
public void CloseControl()
{
/*
* this code is to reopen Word.
*/

try
{
deactivateevents = true;
object dummy=null;
document.Close(ref dummy, ref dummy, ref dummy);
document.Application.Quit(ref dummy, ref dummy, ref dummy);
deactivateevents = false;
}
catch
{
}
}

/// <summary>
/// catches Word's close event
/// starts a Thread that send a ESC to the word window ;)
/// </summary>
/// <param name="doc"></param>
/// <param name="test"></param>
private void OnClose(Word.Document doc, ref bool chancel)
{
if(!deactivateevents)
{
chancel=true;
}
}

/// <summary>
/// catches Word's open event
/// just close
/// </summary>
/// <param name="doc"></param>
private void OnOpenDoc(Word.Document doc)
{
OnNewDoc(doc);
}

/// <summary>
/// catches Word's newdocument event
/// just close
/// </summary>
/// <param name="doc"></param>
private void OnNewDoc(Word.Document doc)
{
if(!deactivateevents)
{
deactivateevents=true;
object dummy = null;
doc.Close(ref dummy,ref dummy,ref dummy);
deactivateevents=false;
}
}

/// <summary>
/// catches Word's quit event
/// normally it should not fire, but just to be shure
/// safely release the internal Word Instance
/// </summary>
private void OnQuit()
{
//wd=null;
}
zhangsonglin_c
高粉答主

2015-07-31 · 醉心答题,欢迎关注
知道大有可为答主
回答量:3.7万
采纳率:83%
帮助的人:7003万
展开全部
在浏览器中,最大化播放窗口,都是用的重新打开一个窗口,你也可以这样。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式