|
dan neely wrote: excel completely embedded
I thought you may be able to do something like this but not sure how in c#
|
|
|
|
|
You can, you'd have to use DllImport.
You could first use SetWindowLong to remove the caption bar / border. Then use FindWindow to get a handle to the program you want to embed (or start the process yourself), then finally a call to SetParent to set the parent window of the external application to a panel or something inside your own application.
A simple test is to set the parent window of Internet Explorer to something like Notepad.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
The way you're post suggests it, you can't. You have no control over how the code of another app runs, and for the most part, how a foreign window behaves.
But, as the other poster said, it is possible to host the window of another app in your own application and control the mouse visibility in your own window. Though, using this technique can cause problems for the app being hosted. You may run into drawing problems in the hosted app, or other issues.
You need to create a window in your app, like a Panel control in a form. Just keep it a light-weight control. Then you need to get the window handle of the main window of the application and call a Win32 function called SetParent to change that window's parent to your Panel control's window. For example:
[DllImport("user32.dll", EntryPoint = "SetParent", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndParent);
private void button1_Click(object sender, EventArgs e)
{
Process p = Process.Start("Notepad.exe");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, panel1.Handle);
}
|
|
|
|
|
Does that include things like merging the captured applications menus into the host? The VB I'd seen a few years ago was IIRC several hundred lines. I'm wondering if it did more, or was just a stereotypical codethulu.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
dan neely wrote: or was just a stereotypical codethulu.
A couple hundred lines?? You probably got it right with this statement!
Even under VB6, I did this with just about a couple dozen lines of code.
dan neely wrote: Does that include things like merging the captured applications menus into the host?
All it does is make the hosted app window render inside the control window. It doesn't merge menus with the host window at all. The Desktop window is normally the parent window, in a sense anyway. All you're doing is stealing the parent role away from the desktop.
|
|
|
|
|
DaveyM69 managed to identify what my problem was in a post down thread and I got it working.
TTBOM this is a lower level of integration than the VB code I was messing with. The hosted apps menus were merged into the hosting apps menu strip. I don't recall if there were any other differences besides the hosted app appearing as a fixed control (that part could've been done like your sample but pinned so it couldn't be moved I guess...).
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Wow - I didn't know that was possible!
Tried it and it works perfectly. 5'd
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: Wow - I didn't know that was possible!
So you haven't seen this[^]
|
|
|
|
|
No, that one passed me by somehow, thanks for the link
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
You are welcome
|
|
|
|
|
Yeah, it's kind of cool, but I've run into a couple of apps over the years that didn't like it when you did this. Rendering got all screwed up in those apps. Never did find a work around for it.
|
|
|
|
|
something on your sample isn't working for me in 2k8. The SetParent call causes notepad to disappear but it's not showing up embedded in the panel either.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Well, I can tell you it works on 2000 and XP. I haven't had cause to use it on Vista or 2008.
|
|
|
|
|
*sigh*
I'm running in XP. Did you do anything other than adding the 2 using directives, dragging the button and panel onto the form and wiring up the event and dllimport?
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Nope. That's all I did.
OK. This is weird. It works on my home dev machine, but not on my work laptop. I think it might be because of a patch that was installed. My dev machine is about 6 months behind in patches .
|
|
|
|
|
It was invisible on my (Vista) system briefly until I made the panel a reasonable size - then it suddenly appeared.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
didn't help on my XP system even with the app sized to 1600x1200 I've got whatever the MSDN standard version was as of mid summer.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
I just tried it on my XP machine and it didn't show. The problem was Notepad remembers it's last size and location and it assumes that relative to the hwnd's top left.
Using SetWindowPos sorts it. This will make it the same size as the panel and at point 0,0.
private void button1_Click(object sender, EventArgs e)
{
Process p = Process.Start("Notepad.exe");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, panel1.Handle);
SetWindowPos(
p.MainWindowHandle,
IntPtr.Zero,
0, 0,
panel1.Width, panel1.Height,
0u);
}
[DllImport("user32.dll", EntryPoint = "SetParent", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndParent);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int X, int Y,
int cx, int cy,
uint uFlags);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: The problem was Notepad remembers it's last size and location and it assumes that relative to the hwnd's top left.
Mine too. Test app was loading on the left monitor, notepad on the right before being captured.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Try SetWindowPos a coule of replies down here[^].
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Here is a sample application that shows how to host other windows: Window Tabifier[^]
|
|
|
|
|
thanks guys, but since the videowindow cant be hosted/tabbed, and has to be fullscreen, ive sort of given up
But thanks anyway
|
|
|
|
|
I have edited project options Build-> "Conditional compilation symbols" /define:CLASSTEST
In my main function i have>>
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
#if (CLASSTEST)
Console.WriteLine("works");
#else
Console.WriteLine("not defined");
#endif
I have tried project build, rebuild solution etc and the #if section is not recognized in IDE code completion does not evaluate statement
build configuration also has debug
Any ideas on what is going on?
|
|
|
|
|
remove the /Define:
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
How can I add a button when run time? and if there is a button in the form, how can it added next to it? Could you help me,please?
Thanks in advance.
|
|
|
|