|
So it works the first time you call it, but not the second time? hmmm... does not sound logical to me.
perhaps you have an issue elsewhere. maybe your GetForegroundWindow() is not returning the correct handle (just an example)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You're right, could be something like that. But why would it fail only in Vista? I will debug it carefully when I can...
|
|
|
|
|
The thing you have to remember is that the user should always be in control of the PC. In the good old days of windows 95, any app could bring itself to the front to alert the user. After a while this created all kinds of problems because you would be typing away and other apps would be grabbing focus all over the place and interrupting your typing, (often catching your key presses and causing unexpected behaviour)
The powers that be realised that this was wrong and decided to fix it. So they changed things so apps couldn't bring them selves to the front, and instead just flashed the toolbar.
this is great except there are some people that still want to slam their apps to the foreground, so these people started working out ways round the restrictions (like the one you have used). Microsoft take note of these hacks and fix the problem for the next version.
The short story is that you should never be forcefully taking focus from what the user is doing. That is why vista doesn't support it. Instead you should flash the toolbar and wait for the user to respond to your app.
Simon
|
|
|
|
|
Thanks, Simon. Yes, these days I've read some explanations like yours and I knew why Microsoft made these changes.
I don't want to bring my own app to the foreground, but windows that were already open (by the user himself) before my app run. It's just as if the user would have pressed Alt+Tab and then interacted with those windows, only that my app automates this.
And the fact is that, if I want the window to be active, I can, in a messy way. As a last resort, I could set foreground window, and then move the mouse down and click the taskbar to activate the flashing window or something. But I don't think that's the way things must be done, and Microsoft should allow programmers to easily bring windows to the front (because, if not, they will do it anyway but in the hard way).
|
|
|
|
|
Hi,
I did some automation to have two apps exchange some data. It used the whole range of Get/SetForeGroundWindow, SendKeys, SendInput, and what have you. It runs fine on both XP and Vista, never had any trouble with it. I did develop on Vista (my main machine runs Vista, and I like it!), and it worked on XP right away. I just don't know if the reverse would also have worked right away.
I did implement automatic retries and a range of checks, e.g. after each SetForeGroundWindow, I wait some msec, then check by reading the title of the result of GetForeGroundWindow, to make absolutely sure I wasn't sending keyboard/mouse actions to the wrong app (the user, not me, might be touching the system while this automation is running).
BTW: I did not use AttachThreadInput, I hadn't even heard of it.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you, I'll implement retries as well, maybe the problem can be solved with some delays here and there and SetForegroundWindow works after all...
I'll let you all know when I can test it, maybe next week. Thanks!
|
|
|
|
|
Well, now it works. I added some delays and a retries policy (as you suggested), and now the above code works on both Windows XP and Vista.
Thank you all!
|
|
|
|
|
Hi,
I am trying to traverse all email from Inbox Folder of outlook but after 672 email I got an exception "Spacified cast is not valid" Even Inbox has more than 1600 emails.
My code is like
Microsoft.Office.Interop.Outlook.Items MyItem=mItem.Items;
MyItem.Sort("Received", false);
foreach(Microsoft.Office.Interop.Outlook.MailItem item in MyItem)
{
....
....
}
Please tell me what is the problem?
|
|
|
|
|
Chances are that you've got something in your Received folder that isn't a MailItem. When you iterate through the items, you do an implicit cast. Change the declaration of item to a base class, and check if it's a MailItem in the loop. If it is, cast and work with it as normal. If it isn't, continue iterating
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Please tell me how to do that?
|
|
|
|
|
It appears that Outlook's interface isn't type safe. Yuck. Try something like this:
foreach(object item in MyItem)
{
if(item is Microsoft.Office.Interop.Outlook.MailItem)
{
...
...
}
}
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Thank you for idea but not able to traverse MyItem...
|
|
|
|
|
But the code in your original post does that. All that I changed in the foreach loop was the type of the variable. You have just replaced the foreach loop (not the first two lines of your code), right?
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Thank you very much, its working
|
|
|
|
|
I have a byte[] of jpg image of size 1.5 kb, is there any method in C# to compress this byte[] further.
I tried by GZip class but actually its size has increased, i found that GZip class is unable to compress jpg image byte[].
Can anyone suggest me any more method.
This is actually needed bcoz the image has to be stored i smart card application and i have limited scope to allot space.
Thanx
|
|
|
|
|
Of course a general compression as used in ZIP can't do any better on images than the specialized JPEG compression that knows and understands what it is dealing with.
If you want a smaller file, you need to throw away some of the information; here are two ideas:
- reduce the number of colors
- reduce the image size
Yes, I know, both will reduce image quality as well.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
For extreme requirements like this, it may justify splitting the byte array into chunks, and using a custom compression algorithm for each chunk.
For example, you may find a run of several hundred pixels with the same value, which would compress nicely with run-length encoding: The single pixel value plus a repetition factor.
Other chunks may have different types of regularity you can exploit, such as a repeated block pattern.
The compressed image will end up as a list of chunks, each with a byte identifier (that gives the compression type for that chunk) followed by that chunk's data. To decompress, go through the chunks, read the byte identifier, then execute the corresponding code to reconstruct that chunk.
|
|
|
|
|
I had an in-process dll (built in Vs2008) which is injected in IE.
I want to create a pipe which should be continuously available for other application.
How can I create a pipe in c# and how can I make it available to the dll.
|
|
|
|
|
Hi everyone!
...From what I can understand, it's that the whole C# Plugin Architecture thing isn't as good as I thought it would be.
I first came up with an idea to (somehow) develop my application in such a way that it would be possible to add functionality at a later time without actually having to go back into the main application project and edit/add code to it, and to also be able to add ANY feature at all (limited only to the imagination.) I would have liked to simply create a DLL (or whatever) and send it to a user and say "Hey man, add this to the "MyApplication" directory and then open "MyApplication". But, out of the 9 articles I've read online, it's become quite apparent that you cannot do that. In order to make a "plugin" work with your program, you must tell your program to look for it. In other words, your program will be 'expecting' "this" plugin. And if you try to open a different plugin that isn't described in your application, it won't work.
I think I might be a little crazy, but I also think that I'm right, going by the 9 articles I've read in the past week. Unless I've misunderstood all 9 articles...
Can anyone please shed a little light on this for me?
Thanks,
schizophrenic PrOgRaMmEr (formerly jase, jt and jay)
|
|
|
|
|
Yes, your application must know about plugins. But if those plugins conform to a common interface, then your application will know what to do with them.
When I wrote a plugin system a couple of years back it used interfaces. The main application would scan a directory for DLL's, use reflection to see what interfaces they implemented, and if they used the interface I was expecting, then I would load the DLL and use it.
I'm pretty sure there are articles on this site describing a similar method...
|
|
|
|
|
Yay thanks for your quick reply!
So, if my application 'knows' about plugins that conform to a particular interface for example a "Drawing Interface"...? I could create plugins that enable the user to View a photo and another to Edit a photo..? I mean, my application only needs to know what "type" of plugin it will be, correct? Not "exactly" what it will do?
Thanks for yout time
|
|
|
|
|
Yes thats pretty much it.
I think this article might help: Plug-ins in C#[^]
|
|
|
|
|
Thanks for your help HuntingWabbits That article was very helpful. Much appreciated.
jase
|
|
|
|
|
schizophrenic.prOgrAmmEr wrote: C# Plugin Architecture
You might also want to take a look at the Managed Extensibility Framework http://www.codeplex.com/MEF[^]
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hmmm... That's very interesting. I'm always on CodePlex, I'm surprised I haven't already found it. Thanks for that Wes Aday!
I'm reading about it now and will check it out. Oh the excitement!!
|
|
|
|