|
Thank you Martin. It solves my other problem. But this is different. I dont want the notepad to bring to the foreground. I want to update the openned notepad file while it is in the background. Can you help me?
Thanks
|
|
|
|
|
Hello,
Member 514252 wrote: Thank you Martin
Member 514252 wrote: I dont want the notepad to bring to the foreground. I want to update the openned notepad file while it is in the background
OK, I understand your task and tried to find a solution, but have to admit that I didn't succeed.
What have I tried:
SendMessage in cmnbination with WM_SETTEXT.
[DllImport("user32.dll",EntryPoint="SendMessage", CharSet=CharSet.Auto)]
private static extern int SendMessage( int hwnd, int uMsg, int wParam, System.Text.StringBuilder lParam);
private const int WM_SETTEXT = 0x000c;
SendMessage((int)procNP[0].MainWindowHandle,WM_SETTEXT, myText.Length, new System.Text.StringBuilder(myText));
Had the effect, that the FileNameChanged (HeadlineText of the Notepad) changed, not the text itselfe.
Sorry for not really helping you.
P.S.:A dirty workaround could be to reset the Foregroundwindow to your actual application
SetForegroundWindow(procNP[0].MainWindowHandle);
System.Threading.Thread.Sleep(100);
SendKeys.SendWait("Hello World!");
SetForegroundWindow(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
What you have to check is if the notepad IsIconic (minimized).
If yes, the SendKeys will not work.
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
[System.Runtime.InteropServices.DllImport("user32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32")]
private static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
IntPtr handleNotePad = procNP[0].MainWindowHandle;
if(handleNotePad!=IntPtr.Zero)
{
bool wasIconic = IsIconic(handleNotePad);
if(wasIconic)
ShowWindow(handleNotePad, SW_SHOWNORMAL);
SetForegroundWindow(handleNotePad);
System.Threading.Thread.Sleep(100);
SendKeys.SendWait("Hello World!");
SetForegroundWindow(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
if(wasIconic)
ShowWindow(handleNotePad, SW_SHOWMINIMIZED);
}
All the best,
Martin
|
|
|
|
|
Thank you again for your effort Martin.
As you said, i tried SendMessage-ing WM_CHAR, it works for Notepad and Wordpad. But i couldnot write into Excel or Word file.
With SendKeys, I am able to send text to any window.
Is there anyway we can do to avoid showing the file?
JRK
|
|
|
|
|
Hi,
does anyone know how to make release builds in Express Edition? The toolbars have two BLANK combo boxes in the "Standard" toolbar where I would normally select the CPU target and the Debug/Release options.
I'm currently looking at a project I created in the full 2008 edition (Team Studio Edition actually) but it still seems to be missing on any newly created projects.
Is this a limitation of the Express Edition?
Regards,
Ray
|
|
|
|
|
Ctrl+Shift+B
If you run without debugging it uses the release build, if you run with debugging it uses the debug build. This caught me out several times, but now I'm back on the Pro edition so I don't care.
|
|
|
|
|
Ed.Poore wrote: This caught me out several times, but now I'm back on the Pro edition so I don't care.
You're what we call "One of the technology haves."
|
|
|
|
|
Pete O'Hanlon wrote: One of the technology haves
Is there some subtle meaning behind this that I'm missing?
|
|
|
|
|
When you had express edition you were in the have nots. Now you're not you're in the haves. Clear? As mud?
|
|
|
|
|
|
It isn't funny now though. If you've got to explain it, it's not funny.
|
|
|
|
|
That's it, thanks!
Strange that the toolbar has the combo's for Debug/Release but has it disabled!
Nice to discover my application runs 10x faster in release than debug [perhaps I have too many Trace.TraceWarnings in my code! ]
Regards,
Ray
|
|
|
|
|
Ray Hayes wrote: perhaps I have too many Trace.TraceWarnings in my code!
Hope its not like:
Trace.TraceWarning("Incrementing variable i");
i++;
Trace.TraceWarning("Incremented variable i");
|
|
|
|
|
Not quite, I'm processing some CVS logs and haven't yet handled branch tags - that was fine until the other day when someone added a branch at the route, so I had 23014 "warnings" being traced that a branch tag was being ignored....
That's the difference between <2seconds to process a 45Mb log file and 20seconds.... I was fairly happy with 20!
Regards,
Ray
|
|
|
|
|
How do you give a plugin access to all data and methods of the hosting application?
Is it possible to set a plugins/interfaces method to respond to a windows event?
|
|
|
|
|
You don't give a plugin access to the data and methods of the hosting application. Your host communicates with the plugin (which is the opposite way around). Typically, your application will provide some interfaces which your plugin may or may not implement. For instance:
public interface IDataWrapper
{
object State{ get ; set ; }
bool HasProcessed{ get; }
}
public interface IPlugin
{
void Start();
}
public class MyPlugin : IPlugin, IDataWrapper
{
private object _state;
private bool _isSuccessful = false;
public object State
{
get { return _state; }
set { _state = value; }
}
public bool HasProcessed
{
get { return _isSuccessful; }
}
public void Start()
{
}
}
Then, in your application you would load the plugin and do something like:
IPlugin plugin = LoadPlugin(...);
IDataWrapper wrapped = plugin as IDataWrapper;
if (wrapped != null)
{
wrapped.State = ...;
}
plugin.Start();
if (wrapped != null)
{
if (wrapped.HasProcessed)
{
...
}
}
|
|
|
|
|
Take a look at this[^] article, it provides a nice introduction.
|
|
|
|
|
The above article would be great if in c#. Could anyone rewrite?
ty
|
|
|
|
|
There used to be a combo box which allowed you to select the language.
To be honest it's not that difficult to translate from VB.NET to C# since the classes used are all the same.
|
|
|
|
|
Download the code, compile it and run it through the excellent .NET Reflector (from Lutz Roeder). Reflector allows you to change the language target, so you can see what it would be in C#.
|
|
|
|
|
hi all,
how to unload the form from memory through code?
regards,
thanks
|
|
|
|
|
|
I tried this but even after calling form.dispose() the code in form is being executed. I have used a thread and that is a background thread.
thanks
|
|
|
|
|
You may need to abort the thread. Probably the best thing is to have the thread listen for an event that you can raise from your parent thread and use that so it can suspend and or terminate itself cleanly without executing any running code.
Dave
|
|
|
|
|
|