using system;
using system.collections.generic;
using system.componentmodel;
using system.drawing;
using system.data;
using system.text;
using system.windows.forms;
using system.diagnostics;
using system.runtime.interopservices;
using system.io;
using system.drawing.design;
namespace hcdl
///
public intptr start(string filenamestr)
trycatch}}
/// /// 確保應用程式嵌入此容器
///
///
///
}/// /// 應用程式結束執行時要清除這裡的標識
///
///
///
///
public void stop()
catch (exception)}}
#region 屬性
///
/// /// 標識內嵌程式是否已經啟動
///
#endregion 屬性
#region win32 api
[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);
public static intptr setwindowlong(handleref hwnd, int nindex, int dwnewlong)
return setwindowlongptr64(hwnd, nindex, dwnewlong);
}[dllimport("user32.dll", entrypoint = "setwindowlong", charset = charset.auto)]
public static extern intptr setwindowlongptr32(handleref hwnd, int nindex, int dwnewlong);
[dllimport("user32.dll", entrypoint = "setwindowlongptr", charset = charset.auto)]
public static extern intptr setwindowlongptr64(handleref hwnd, int nindex, int 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, uint wparam, uint lparam);
[dllimport("user32.dll", setlasterror = true)]
private static extern intptr getparent(intptr hwnd);
[dllimport("user32.dll", entrypoint = "showwindow", setlasterror = true)]
static extern bool showwindow(intptr hwnd, int ncmdshow);
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;
private const int sw_hide = 0; //
private const int sw_shownormal = 1; //
private const int sw_normal = 1; //
private const int sw_showminimized = 2; //
private const int sw_showmaximized = 3; //
private const int sw_maximize = 3; //
private const int sw_shownoactivate = 4; //
private const int sw_show = 5; //
private const int sw_minimize = 6; //
private const int sw_showminnoactive = 7; //
private const int sw_showna = 8; //
private const int sw_restore = 9; //
private const int sw_showdefault = 10; //
private const int sw_max = 10; //
#endregion win32 api
/// /// 將指定的程式嵌入指定的控制項
///
catch (exception)
trycatch (exception)
trycatch (exception)
}[dllimport("user32.dll", entrypoint = "sendmessage")]
private static extern int sendmessage(intptr hwnd, int msg, intptr wparam, string lparam);
const int wm_settext = 0x000c;
}}
showform sf = new showform(this, "僅供內部使用" + system.guid.newguid().tostring());
*************************====
**:
在winform嵌入外部應用程式
應朋友要求,需要將乙個第三方應用程式嵌入到本程式winform視窗,以前在vb6時代做過類似的功能,其原理就是利用windows api中findwindow函式找到第三方應用程式控制代碼,再利用setparent函式,將該控制代碼設定為本視窗的子視窗。網上搜尋大部分都是利用system.diagn...
qt呼叫外部exe
startdetached啟動的libfx.exe跟你的程序沒關係,你的程式關了它還可以繼續執行 qstring strfile tr e f libfx.exe qprocess pprocess new qprocess this pprocess startdetached strfile s...
c 呼叫外部exe程式
c 呼叫外部exe程式,首先要 using system.diagnostics 然後開啟乙個新process system.diagnostics.processstartinfo p null system.diagnostics.process proc p new processstarti...