|
I've just been playing around with this as your question interested me. There's a bit more to just setting the parent handle. This is what I came up with after a little research and testing, it will still need further work but it's a start:
using System;
using System.Runtime.InteropServices;
internal static class NativeMethods
{
public const int GWL_STYLE = -16;
public const int WS_VISIBLE = 0x10000000;
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("User32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("User32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
internal class ProcessWrapper
{
private Process process = null;
public ProcessWrapper(Process process)
{
this.process = process;
}
public void Close()
{
if (process != null)
process.CloseMainWindow();
}
public void PlaceInControl(Control control)
{
if (control != null && process != null)
{
while (
process.MainWindowHandle == IntPtr.Zero ||
!NativeMethods.IsWindowVisible(process.MainWindowHandle))
{
process.Refresh();
}
process.WaitForInputIdle();
NativeMethods.SetParent(process.MainWindowHandle, control.Handle);
NativeMethods.SetWindowLong(
process.MainWindowHandle,
NativeMethods.GWL_STYLE,
NativeMethods.WS_VISIBLE);
Resize(control.ClientRectangle);
}
}
public void Resize(Rectangle rectangle)
{
if (process != null)
NativeMethods.MoveWindow(
process.MainWindowHandle,
rectangle.X,
rectangle.Y,
rectangle.Width,
rectangle.Height,
true);
}
}
using System;
using System.Diagnostics;
using System.Windows.Forms;
public partial class FormMain : Form
{
private ProcessWrapper processWrapper;
public FormMain()
{
InitializeComponent();
FormClosing += new FormClosingEventHandler(FormMainFormClosing);
panel.Resize += new EventHandler(PanelResize);
processWrapper = new ProcessWrapper(Process.Start("calc.exe"));
processWrapper.PlaceInControl(panel);
}
private void PanelResize(object sender, EventArgs e)
{
if (processWrapper != null)
processWrapper.Resize(panel.ClientRectangle);
}
private void FormMainFormClosing(object sender, FormClosingEventArgs e)
{
if (processWrapper != null)
processWrapper.Close();
}
}
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
i have tried out and it works! but right now i am facing another problem! how do i adjust the panel width and height? I fixed my panel on the top left hand side with a width of 400px and height 400px. however after the button is being clicked, the exe appear but the position of the panel shifted. how do i ensure that the panel stays where it was as of before?
and also before the exe file is being displayed in the panel, it will pop up the exe first. how can i do it in such a way that it wont pop up and will be displayed immediately in the panel?
|
|
|
|
|
I'm trying to figure out how to pass pointers to variable length arrays. I can't seem to get this to work. Any help? It looks like this:
<pre>
class CHandler:
public int ReadFileBytes(string fileName, byte[] dataForReturn)
{
FileStream fs = File.OpenRead(fileName);
dataForReturn = new byte[fs.length];
fs.Read(dataForReturn, 0, dataForReturn.Length);
fs.Close();
int status = 1;
return status;
}
class DUser:
private void button_Click(...)
{
Read_File(fileName, byte[]dataForReturn);
}
public int Read_File(string fileName, Byte[]* data)
{
CHandler fio = new CHandler();
int result = fio.ReadFileBytes(fileName, data);
}
|
|
|
|
|
MichCl wrote: how to pass pointers to variable length arrays
Not in C#.
CHandler -- can it be static?
ReadFileBytes -- looks OK, but why not return the numbre of bytes read? (Or -1 on failure?)
Read_File -- out byte[] data (no asterisk)
button_Click -- should probably declare dataForReturn
|
|
|
|
|
|
For an app I'm working on, I want the user to be able to include wildcards when specifying the files to open from the command line, e.g. myapp C:\projects\*.cs .
But that causes trouble when I try to extract the path and filename (filespec) with System.IO.Path -- the wildcard characters cause Exceptions.
As a work around, I'm using the following, which works OK, but I doubt it's very robust:
private void
OpenFiles
(
string[] Paths
)
{
foreach ( string path in Paths )
{
int off = path.LastIndexOfAny ( new char[] { '\\' , ':' } ) + 1 ;
string p = off==0 ? ".\\" : path.Substring ( 0 , off ) ;
string f = path.Substring ( off ) ;
foreach ( string fn in System.IO.Directory.GetFiles ( p , f ) )
{
OpenFile ( fn ) ;
}
}
return ;
}
Does anyone here have a better solution to this?
|
|
|
|
|
That is basically it, I created this just the other day:
string folder="";
int i=pattern.LastIndexOf(@"\");
if (i>=0) {
folder=args.Substring(0,i);
pattern=pattern.Substring(i+1);
}
string[] files=Directory.GetFiles(folder, pattern);
Mind you it only accepts wildcards in the fillname itself, not in the folder path. If you need that, you'd have to code a recursive scan.
|
|
|
|
|
I think yours trims off the last backslash, which could be a problem if the only backslash is the first character e.g. \*.cs .
Luc Pattyn wrote: not in the folder path
Right, I don't need that (at this time). But I'm thinking about it.
P.S. What about C:*.cs ?
|
|
|
|
|
PIEBALDconsult wrote: What about C:*.cs ?
I don't care about that, I consider it a bad path, it should have a \ in there.
|
|
|
|
|
|
Not for me it isn't.
|
|
|
|
|
Well, I don't often use it myself, but it's easy enough to handle.
|
|
|
|
|
OK OK! I powered up an ALphaServer...
DIR SYS$SYSTEM:*.COM
|
|
|
|
|
Is it running Mono yet?
|
|
|
|
|
No; you know that OpenVMS is immune to virus.
And here's another example:
JB> def/sys/tra=(con,ter) C BADGER$DQA1:[000000.USERS.badger.]
JB> dir c:*.c
|
|
|
|
|
Message Removed
modified 10-Mar-12 10:10am.
|
|
|
|
|
See the 3rd reply on this[^] page.
/ravi
|
|
|
|
|
thanks , It's a good Lesson !
|
|
|
|
|
I created a RelayCommand:
public class RelayCommand<T> : ICommand
{
readonly Action<T> _execute = null;
readonly Predicate<T> _canExecute = null;
public RelayCommand(Action<T> execute)
: this(execute, null)
{
}
public RelayCommand(Action<T> execute, Predicate<T> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute((T)parameter);
}
public void Execute(object parameter)
{
_execute((T)parameter);
}
}
I have 2 questions:
I'm trying to have the command pass an enum to the action method:
private ICommand _PerformanceCommand;
public ICommand PerformanceCommand
{
get
{
if (_PerformanceCommand == null)
{
_PerformanceCommand = new RelayCommand<ViewCategory>(p => buttonClicked(ViewCategory.Peformance));
}
return _PerformanceCommand;
}
}
private ICommand _SettingsCommand;
public ICommand SettingsCommand
{
get
{
if (_SettingsCommand == null)
{
_SettingsCommand = new RelayCommand<ViewCategory>(p => buttonClicked(ViewCategory.Settings));
}
return _SettingsCommand;
}
}
and then
private void buttonClicked(ViewCategory args)
{
}
The code throws an exception in the command class on
public void Execute(object parameter)
{
_execute((T)parameter);
}
1) Not sure why it's null if the command is passing an enum value.
2) How can I refactor the relay command so that it can take a type, or not take a type. In other words
public class RelayCommand : ICommand
public class RelayCommand<T> : ICommand
Would I need to separate classes for this?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
search item from listview with id for exemple
in C#
|
|
|
|
|
Yeah, you're going to have to explain a bit more about what you're doing and why in order for us to help you. We have no idea what you're trying to do.
|
|
|
|
|
Just search through the underlying datasource using LINQ.
|
|
|
|
|
Hi All ,
how can I streaming video using c# ?? what library do I need to do this ?
Thank you
|
|
|
|
|
DirectShow.Net[^] can help you capture and stream video.
There are a number of other third party tools available.
|
|
|
|