|
Hi all,
please i need the win32 API function to know the fact that is desktop changed.
Thank you in advance.
naresh is testing the site.
|
|
|
|
|
I'm not sure the exact answer, but anytime you are looking for a Win32 API function, you should check out the site http://www.pinvoke.net/.
Hogan
|
|
|
|
|
Thank you very much guys.
i look around your hints and links.
hope it works.
naresh is testing the site.
|
|
|
|
|
Hi,
what changes on the desktop ?
AFAIK:
- the resolution, the pixel depth, ... that will fire a Paint event; see also
the SystemEvents class.
- the icons (new, renamed, moved,...): no event available
- the background image: no event available
Hope this helps
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Actually i need to send the image of my desktop to remote computer whenever desktop gets changes. So for this, the i am expecting a common event(for opening new window on the desktop ,selecting the desktop area,minimizing and maximizing any window over the dekstop) that can be caught in my application and at the same time it sends the desktops changed image to the remote computer. So plz any body have any idea?? Actually i know there happens a Paint System event, if so how can i handle this event in my application to know the changed state of my desktop??
Thank you in advance!!
naresh is testing the site.
|
|
|
|
|
How does one receive events in a C# windows service from a COM object that has been instantiated from a background thread whose ApartmentState == ApartmentState.STA? I’ve been able to received events from the COM object in a WinForm app when the thread sits in a loop sleeping and invoking System.Windows.Forms.Application.DoEvents(), i.e. pumping the message queue.
The thread that accesses the COM object is responsible for responding to requests by other objects to access the COM object, done through a queue + AutoResetEvent, and for handling events raised by the COM object in response to those requests.
Other posts/web sites have mentioned that STA threads require a message loop/pump. It seems like if the thread that accesses the COM object were able to call a method that could sleep + message pump + respond to requests to wake up, I’d be set. Is there such a beast/can such a thing be created? Is this the right kind of design?
Thanks,
Steve
|
|
|
|
|
My understanding of windows services is they are not on the windows message queue, so it is doubtful you would ever be able to receive those messages.
Ben
|
|
|
|
|
With some help from a coworker, I figured out how to do this.
The message loop can be run on the same thread as the COM object using ApplicationContext and Application.Run. Other objects can communicate to the thread via Invoke on a dummy Control created on the message loop thread.
<code>
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace TestMessageLoopWindowsService
{
internal class TestMessageLoop
{
internal void Start(EventLog eventLog)
{
if (eventLog == null)
throw new ArgumentNullException("eventLog");
this.eventLog = eventLog;
Thread messageLoopThread = new Thread(MessageLoopThread);
messageLoopThread.Name = "Message Loop Thread";
messageLoopThread.SetApartmentState(ApartmentState.STA);
messageLoopThread.Start();
Thread invokeOnToMessageLoopThread = new Thread(Invoker);
invokeOnToMessageLoopThread.Name = "Invoker";
invokeOnToMessageLoopThread.IsBackground = false;
invokeOnToMessageLoopThread.Start();
}
private EventLog eventLog;
private void MessageLoopThread()
{
ApplicationContext context = new ApplicationContext();
control = new Control();
control.HandleCreated += new EventHandler(control_HandleCreated);
control.CreateControl();
Application.Run(context);
}
private Control control;
private void control_HandleCreated(object sender, EventArgs e)
{
okToInvoke = true;
}
private volatile bool okToInvoke;
private void Invoker()
{
while (true)
{
if (okToInvoke)
{
EventHandler method = new EventHandler(InvokedOnMessageLoop);
control.Invoke(method);
}
Thread.Sleep(1000);
}
}
private void InvokedOnMessageLoop(object sender, EventArgs e)
{
eventLog.WriteEntry("InvokedOnMessageLoop runs on " + Thread.CurrentThread.Name);
}
}
}
</code>
|
|
|
|
|
This isn't a specific programming question but more so a request for someone to explain the purpose of StringBuilder class?
Whats the difference between a char[] and stringbuilder? Can I access elements in a stringbuilder the same way as I would with an array?
|
|
|
|
|
Do you use char[] instead of string? You should use StringBuilder if you are having many manipulations on a string because StringBuilder is faster. You can access individual characters as you would do in an array
|
|
|
|
|
The StringBuilder is used when you have a lot of string manipulation, such as appending text inside of a loop. It's benefit comes from the fact that it doesn't need to create a new string instance each time it appends. Take the following loop:
string result = String.Empty;
for (int i = 0; i <= 10000; i++)
{
result += String.Format("i = {0}\n", i);
} Each time through this loop, you are allocating a new instance of a string to hold the concatenated value. Changing this loop to:
StringBuilder resultBuilder = new StringBuilder();
for (int i = 0; i <= 10000; i++)
{
resultBuilder.AppendFormat("i = {0}\n", i);
}
string result = resultBuilder.ToString(); you don't have all of the string allocations.
You can't access the value of a StringBuilder in any meaningful way other than to call it's ToString() method, which retrieves the internal value as a string . However, once you have it as a string , you could access the string by individual character positions just like you would a char[] .
Remember, string in .NET is not really equivalent to a char[] even though you can do a lot of the same operations; it is a first class data type.
|
|
|
|
|
Scott Dorman wrote: You can't access the value of a StringBuilder in any meaningful way other than to call it's ToString() method
Are you sure? As I have written in my post stringbuilder has a property called Chars so can access individual characters
|
|
|
|
|
You can certainly access individual characters out of the internal string value using the Chars property, but I have never run across a situation where that is really useful. Usually StringBuilder is used to save on string allocations when performing a lot of string manipulation with the end result desired being the final string value. By accessing it a character at a time, it isn't much different than building up a char array.
|
|
|
|
|
Scott Dorman wrote: By accessing it a character at a time, it isn't much different than building up a char array
It's dynamic, and one can Insert.
|
|
|
|
|
True, but it seems like there would be better ways to interact with a char array.
|
|
|
|
|
Yeah, but if you want something like StringBuilder but which logically encapsulates "a dynamic array of chars" rather than "a string", would you write one? I wouldn't.
Borrowing from recent discussions of the using directive, one could do:
using CharArrayBuilder=System.Text.StringBuilder ;
|
|
|
|
|
Yes, I agree that it might not be very useful but the question was if it was possible to access individual chars to which you said no. That's why I wrote it
|
|
|
|
|
For example:
Just yesterday I was working on a simple program that reads a C Sharp source file line-by-line then checks and corrects the indentation and such.
After reading a line, I put it in a StringBuilder, then I do things like:
theline.Replace ( '\t' , ' ' ) ;
switch ( theline [ 0 ] ) { ... }
if ( theline [ 1 ] != ' ' ) { ... }
What I dislike about the StringBuilder (as implemented in .net 2 and earlier anyway), is:
A) There is no Clear() method, so I use theline.Remove ( 0 , theline.Length ) ;
B) There is no way to Set the string (after instantiation) other than Append()
Which means I have to use:
while ( ( inline = Infile.ReadLine() ) != null )
{
theline.Remove ( 0 , theline.Length ) ;
theline.Append ( inline ) ;
...
}
If anyone else has a better technique, pleast let me know.
(Does the .net 3 version have more functionality? I'd better check.)
|
|
|
|
|
Hi,
I am afraid they expect you create a new StringBuilder instance in these
situations; they would probably add "who cares about one more object, you have
two already (original string and final string)".
I would not be surprised if a new SB is actually faster than Remove+Append.
And I have the impression you would like to have File.ReadLineToStringBuilder()
avoiding the string object all together.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: I would not be surprised if a new SB is actually faster than Remove+Append.
Great, something else to try out. But I've got to believe a Clear(), which may simply set the Length...... Holy F-ing Dung! Length is not read-only!? Glory Hallelujah! Did no one else know this? Keeping it a secret? Ha ha! PIEBALD didn't RTFM?! Is that it? Well, I found out your little secret, there's no stopping me now!
It does seem to violate something though, Length is read-only for most objects.
Luc Pattyn wrote: And I have the impression you would like to have File.ReadLineToStringBuilder()
I could write a library function that reads the file character-by-character to simulate that, and I may still do so.
As the program stands, I compare the raw line with the resultant line to report which lines were modified, but that'll likely go away.
|
|
|
|
|
PIEBALDconsult wrote: Length is read-only for most objects
so Builders are a special breed...
Now you can still ponder the Length=0; Append(string); versus new SB(string); dilemma.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Well, I'd still rather not have to allocate a new array each time. And the array in use is already expanded to hold the longest line encountered so far (I do allocate it to hold twice my expected maximum, so maybe that's not too much of an issue).
So, I'm reusing the same instance.
And maybe I will fill it one character at a time, but I'm pondering the implementation.
|
|
|
|
|
Hi,
Does any one know of an application that records pixel movement of an application. I.e. take a movie on a application while you work on it.
|
|
|
|
|
Camtasia[^], from the good people who brought us SnagIt. And this[^] is a free alternative.
/ravi
|
|
|
|
|
Thanks,
I was more thinking on how to actually write the code to do it
|
|
|
|