|
Hy,
I need to lunch a console application from a C# Windows Forms application. I have done something like that
Process serverProcess=new Process();
serverProcess.StartInfo.FileName = "wserver2";
serverProcess.StartInfo.UseShellExecute = true;
serverProcess.StartInfo.CreateNoWindow = false;
this.serverProcess.Start();
The code works fine, but I need a console to appear when the serverProcess is started and this process should appear in that console.
|
|
|
|
|
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = "console.exe";
ps.Arguments = "";
ps.CreateNoWindow = false;
ps.UseShellExecute = false;
ps.RedirectStandardInput = true;
ps.RedirectStandardOutput = true;
ps.RedirectStandardError = true;
Process proc = new Process();
proc.StartInfo = ps;
proc.Start();
string line = proc.StandardOutput.ReadLine();
proc.Close();
I know nothing , I know nothing ...
|
|
|
|
|
nhack wrote: The code works fine
Is wserver2 a console application?
What do you mean by works fine as I assume you are asking the question because it isn't working fine!
Alan.
|
|
|
|
|
wserver2 is a console application and it works fine because i connect to it (it is a ssl server). My problem is that i want to see the output of the server in a new console window.
|
|
|
|
|
Hi,
I can't see anything wrong with the Process code. Are you missing any important command line switches? When the process is started from Windows Explorer does it display a console window?
Alan.
|
|
|
|
|
Yes, when the server is started from Explorer it displays a console window. If a lunch my Form application from the console the output is printed on the console, but what i want is to open a new console and to print the output from the server process on the new console.
|
|
|
|
|
I know that get and set is widely used in C#, e.g.
public class test
{
private int a = 2;
public int example
{
get {return a;}
set {a=value;}
}
}
above code is same as (I think)
public class test
{
public int a = 2;
}
but I believe that get/set should have more advantages, anyone can give me one hint for that?
thanks
|
|
|
|
|
Because they allow you to perform special handling when a value is set or got. They offload the validation checking away from main methods, keeping the main code 'clean'. Additionally, they let you provide calculated values, so that you don't have to call UpdateProperty() - you can just put the code in the get method. Also, you can properties to interface declarations
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
I used it in my router project ...
when ever I add router or computer I call the set method like this :
ObjectsCounter.Routers = 5;
here is my code :
class ObjectsCounter
{
private static int routers;
public static int Routers
{
set {
routers += value;
}
get {
return routers;
}
}
}
of course you can call it like that too :
ObjectsCounter.Routers += 5;
I know nothing , I know nothing ...
|
|
|
|
|
Alo,
Que esta' la differencia entre algun y alguno. O esta' la differencia???
Chow
Troy
|
|
|
|
|
Properties have a special use if your making a custom control with custom properties.
#region Color HighlightColor
private Color highlightColor = Color.Yellow;
[DefaultValue(typeof(Color), "Yellow")]
public Color HighlightColor
{
get { return highlightColor; }
set
{
if (highlightColor != value)
{
highlightColor = value;
this.Invalidate();
}
}
}
public bool ShouldSerializeHighlightColor()
{
return highlightColor != Color.Yellow;
}
public void ResetHighlightColor()
{
HighlightColor = Color.Yellow;
}
#endregion
here's one from a control i'm working on... the attribute for defaultvalue and the ShouldSerialize##"Property Name" Reset##"Property Name" functions are specially called by the visual studio ide... so when you have your control on the designer, and you play with a setting... you can do stuff like right click it and hit "Reset"... also the shouldSerialze function is checked for if the designer needs to save that setting to the .designer.cs file. This way the designer doesnt have to serialze a dozen default values... which probably improves performance or whatnot... looks nicer to when you gotta go in the designer file... i forget if the defaultvalue attribute means so when you type a value in the propertygrid, that if its the default value in that attribute, that the ide shows regular font or bold, that you changed it from default,...
So properties are nice if your making a custom control. Otherwise, properties are handy for controlling what comes in and leaves your class...
like have a getOnly type property like:
public int Something {
get { return something; }
}
or here's checking input:
public string SomeOtherThing {
get { return someOtherThing; }
set
{
if (!String.IsNullOrEmpty(value))
someOtherThing = value;
}
}
.... so i see your point... i mean in C++ the method was with functions to do the same job. So the only advantage of a property is that the IDE can draw a nice little icon when it detects one in your class... like i mean intellisense... other then that, and all programmers already expect to play with properties to set settings, that they have no purpose. Practically a bloated feature if we just look at C# as the language... but ya, their good for the vs.net designer when plopping controls on a form :P
|
|
|
|
|
|
The obvious one is that you can make the set private.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
C# is an Object Oriented Language, or at least it purports to be.
get/set, as you call it, or Properties, as they should be called, are a fundamental part of the .NET implementation of the principals of OOP.
Take a look at this[^] for a clearer explanation than I could give in a reasonable space.
You can use C# to program in a non-OOP way but you are better off learning what OOP is all about and trying to adhere to its principals.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
http://www.sourceforge.net/
is this site still working ? can any one browse it ?
I got bad request
sorry for this Question , but I have no friends around me , to ask them ...
you are my only
I know nothing , I know nothing ...
|
|
|
|
|
it does not work for the moment
|
|
|
|
|
thank you
I know nothing , I know nothing ...
|
|
|
|
|
Stark DaFixzer wrote: but I have no friends around me
hmm, well, may be make this[^] your friend. You see it[^] knows the status of website
|
|
|
|
|
thank you yusuf , it's very useful for me ....
Shokarn ....
I know nothing , I know nothing ...
|
|
|
|
|
... please please please please give me a working code sample that uses SendInput to SIMULATE the movement of a mouse on a x64 vista system:
1. move mouse to screen location 200,100
2. mouse down
3. move the mouse down 12 (to 200,112)
4. mouse up
it seems like such a trivial task but is clearly one that i have not been able to master. i have searched the internet high and low, found a gazillion articles on the subject, tried 9 different samples (all failed), and have spent a minimum of 100 hours on this problem. I've learned a lot but the idea of running 32-bit DLL's on a 64-bit computer is still way over my head ... i need help desperately.
I have been able to get it to work using SetCursorPos and mouse_event but those methods actually steal the mouse from the user and make him VERY grumpy
Thank you oh so VERY MUCH in advance!
|
|
|
|
|
IceWater42 wrote: 1. move mouse to screen location 200,100
2. mouse down
3. move the mouse down 12 (to 200,112)
4. mouse up
Uhh, this is nice and all, but if the user is moving the mouse in the same window that this code is sending messages to, it'll fail to do what you want since the real mouse will be mixing in it's messages with yours. The only way to prevent that is to stop the user from using the mouse at all while you send your mouse messages. Again, a very ugly solution.
|
|
|
|
|
yes ... i agree it is ugly. I think by now i have tried ALL the ugly ways of doing it. That is why i posted the plea for help ... i keep hoping for a prettier solution.
Through trial-and-error these past 2 weeks, i have seen the ugly side-effects of many of the researched "solutions" ... none of which were very User-Friendly. Add in the complications of 64-bit hardware with 32-bit DLLs and (for me) the task is daunting.
That is why i posted my plea ... i was hoping that there actually might be a reasonably good way to do it, and that one of the very creative people here would show me how.
Maybe there still is a glimmer of hope, thanks to the time and effort of FocusedWolf, below.
|
|
|
|
|
IceWater42 wrote: Maybe there still is a glimmer of hope, thanks to the time and effort of FocusedWolf, below.
Your only congratulating him becuase he wrote your entire project for you. Too bad too. You've skipped the part where you learn how Windows works internally.
I've already found ways in which that code will break. When your users find them too, have fun trying to diagnose the problems and work around them.
|
|
|
|
|
AAAAAAAAAAAANd course failed, exam missed. enjoy the retake :P
|
|
|
|
|
hmm i think i tried using sendinput and found it sucked. I like using send message because you dont need to actually move the mouse about to click... you can send the coordinates of where a click is to occur... much more sexy right. Their might be problems or something with some windows and i think i had to have the window focused to get it to actually work.... unfortunatelly its not as nice as when doing sendmessage with keystrokes because in that case theirs no need to have the window focused... good for my bot... had it in the background doing stuff while i used the computer lol...
anyway here's what i had for using sendmessage (i think i had code for sendinput and deleted it because while it worked, it required both focus of the window and ownership of the moues cursor):
<br />
using System;<br />
using System.Text;<br />
using System.Runtime.InteropServices;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
using System.Threading;<br />
<br />
namespace MouseKeyboardLibrary<br />
{<br />
public class MouseSimulatorMessenger<br />
{<br />
<br />
[DllImport("user32.dll")]<br />
static extern IntPtr GetForegroundWindow();<br />
<br />
[DllImport("user32.dll")]<br />
private static extern int SetForegroundWindow(IntPtr hWnd);<br />
<br />
<br />
<br />
<br />
<br />
static IntPtr? handle = IntPtr.Zero;<br />
public IntPtr? Handle<br />
{<br />
get { return handle; }<br />
set { handle = value; }<br />
}<br />
<br />
#region Windows API Code<br />
<br />
private static IntPtr MakeLParam(int LoWord, int HiWord)<br />
{<br />
return (IntPtr)((HiWord << 16) | (LoWord & 0xffff));
}<br />
<br />
const int WM_LBUTTONDOWN = 0x0201;<br />
const int WM_LBUTTONUP = 0x0202;<br />
<br />
const int WM_MBUTTONDOWN = 0x207;<br />
const int WM_MBUTTONUP = 0x208;<br />
<br />
const int WM_RBUTTONDOWN = 0x0204;<br />
const int WM_RBUTTONUP = 0x0205;<br />
<br />
[return: MarshalAs(UnmanagedType.Bool)]<br />
[DllImport("user32.dll", SetLastError = true)]<br />
static extern bool SendMessageA(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);<br />
<br />
<br />
<br />
private static int MouseButtonDownInteger(MouseButton button)<br />
{<br />
switch (button)<br />
{<br />
case MouseButton.Left:<br />
return WM_LBUTTONDOWN;<br />
<br />
case MouseButton.Middle:<br />
return WM_MBUTTONDOWN;<br />
<br />
case MouseButton.Right:<br />
return WM_RBUTTONDOWN;<br />
}<br />
<br />
throw new ArgumentException("button");<br />
}<br />
<br />
private static int MouseButtonUpInteger(MouseButton button)<br />
{<br />
switch (button)<br />
{<br />
case MouseButton.Left:<br />
return WM_LBUTTONUP;<br />
<br />
case MouseButton.Middle:<br />
return WM_MBUTTONUP;<br />
<br />
case MouseButton.Right:<br />
return WM_RBUTTONUP;<br />
}<br />
<br />
throw new ArgumentException("button");<br />
}<br />
<br />
#endregion<br />
<br />
#region Methods<br />
<br />
public void MouseDown(MouseButton button, int x, int y)<br />
{<br />
<br />
if(handle.HasValue)<br />
SendMessageA(handle.Value, MouseButtonDownInteger(button), 0, MakeLParam(x, y));<br />
else<br />
throw new ArgumentNullException("handle");<br />
<br />
}<br />
<br />
public void MouseUp(MouseButton button, int x, int y)<br />
{<br />
<br />
if (handle.HasValue)<br />
SendMessageA(handle.Value, MouseButtonUpInteger(button), 0, MakeLParam(x, y));<br />
else<br />
throw new ArgumentNullException("handle");<br />
<br />
}<br />
<br />
public void MouseDown(MouseButtons button, int x, int y)<br />
{<br />
switch (button)<br />
{<br />
case MouseButtons.Left:<br />
MouseDown(MouseButton.Left, x, y);<br />
break;<br />
case MouseButtons.Middle:<br />
MouseDown(MouseButton.Middle, x, y);<br />
break;<br />
case MouseButtons.Right:<br />
MouseDown(MouseButton.Right, x, y);<br />
break;<br />
}<br />
}<br />
<br />
public void MouseUp(MouseButtons button, int x, int y)<br />
{<br />
switch (button)<br />
{<br />
case MouseButtons.Left:<br />
MouseUp(MouseButton.Left, x, y);<br />
break;<br />
case MouseButtons.Middle:<br />
MouseUp(MouseButton.Middle, x, y);<br />
break;<br />
case MouseButtons.Right:<br />
MouseUp(MouseButton.Right, x, y);<br />
break;<br />
}<br />
}<br />
<br />
public void Click(MouseButton button, int x, int y)<br />
{<br />
IntPtr oldFocus = GetForegroundWindow();<br />
<br />
MouseDown(button, x, y);<br />
<br />
Thread.Sleep(200);<br />
<br />
MouseUp(button, x, y);<br />
<br />
SetForegroundWindow(oldFocus);<br />
}<br />
<br />
public void Click(MouseButtons button, int x, int y)<br />
{<br />
switch (button)<br />
{<br />
case MouseButtons.Left:<br />
Click(MouseButton.Left, x, y);<br />
break;<br />
case MouseButtons.Middle:<br />
Click(MouseButton.Middle, x, y);<br />
break;<br />
case MouseButtons.Right:<br />
Click(MouseButton.Right, x, y);<br />
break;<br />
}<br />
}<br />
<br />
public void DoubleClick(MouseButton button, int x, int y)<br />
{<br />
Click(button, x, y);<br />
<br />
Thread.Sleep(200);<br />
<br />
Click(button, x, y);<br />
}<br />
<br />
public void DoubleClick(MouseButtons button, int x, int y)<br />
{<br />
switch (button)<br />
{<br />
case MouseButtons.Left:<br />
DoubleClick(MouseButton.Left, x, y);<br />
break;<br />
case MouseButtons.Middle:<br />
DoubleClick(MouseButton.Middle, x, y);<br />
break;<br />
case MouseButtons.Right:<br />
DoubleClick(MouseButton.Right, x, y);<br />
break;<br />
}<br />
}<br />
<br />
#endregion<br />
}<br />
}<br />
|
|
|
|
|