How can I do this in a C# program? I'm pretty sure it should be possible, since various media programs for example do this so the computer doesn't go into stand-by while watching a movie, etc.
So, if I for example create a plain and basic WinForm application, what do I need to do to prevent a laptop from going into Stand-By as long as this application is running?
I think you'll have to P/Invoke. But don't be scared... it's pretty easy.
SetThreadExecutionState is your friend. It's available in the PInvoke project, also available on NuGet.
Related
I need to develop a C# touch-screen desktop application with a "modern good-looking" UI.
How would you approach it? I´ve got in mind using Flash (just for the UI) or WPF... but i´m open to any idea or any third-party C# UI you´d know.
Is Flash easy to integrate with C#?
Thanks for your knowledge!
You should look for a AMF remoting library in C#.
Remoting is when you call a function on your server from flash.
AMF (version 0 or 3) is a binary format used to encode object transfered
between client and server
Weborb and fluorine are solutions for this.
see : .NET and AMF
You will probably be doing well with a third party framework to avoid the overhead of writing user interactions, controls, etc.
A couple of options are
http://xamarin.com/
http://www.resco.net/developer/mobileformstoolkit/
A review of these options is provided here.
I recall combining a flash interface with a C# back-end back in university. There's a method called fscommand() that will take a couple of string parameters (I may be mistaken, read up on it) to pass to and from the interface and the C# "code-behind".Flash is an ok option, but if I were you I'd opt for a WPF interface. I'm a huge fan of the telerik libraries, their WPF one allows you to create the most modern-looking interfaces and dashboards. Not to mention that the skills you will acquire while learning enough about wpf will be hugely beneficial in your career as a developer the way things are going (depending, obviously, on what direction you're heading).
FlashBuilder 4.6 has some nice functionality for quickly building a UI that work on a desktop or mobile device. You could use FluorineFX (free) or webOrb on a webserver to send data back and forth to a database server if that were needed. If you build it with the Flashbuilder 4.6 mobile project template, it would work on a iPad, mac, windows pc, or android device as well. Since a pc touchscreen should use the same type of finger gestures as a mobile app, this might be a nice way to go. (I don't actually have a touchscreen on my pc, but it runs well with a mouse, so I'd assume it worked with gestures too).
Adobe.tv has lots of examples of building a mobile app project (Which also runs on a PC) and there is a Flashbuilder 4.6 free trial.
http://flex.org/
Is it possible to create console apps like the Edit app in CMD with visual basic or C#? I want the program to respond to mouse input, have menubar, mssgboxes and windows.
Yes, this is possible! Instead of doing it completely from scratch, check out Curses Sharp. It is a wrapper for the curses library, which helps in building applications like this.
I must admit though, I have never used it. Please let us know how it goes.
Console API provided with .NET is not suitable for that sort of development. You'll need to do lots of P/Invoke to the platform console API. I would really suggest WinForms/WPF if you need GUI.
If you really want to do it anyway, you'll need to implement low level mouse/keyboard hooks. This will get you started: http://blogs.msdn.com/b/toub/archive/2006/05/03/589468.aspx
If you want it to run on DOS, you can't (because C#/vb.net don't run on DOS). If you want it to run on Windows, I think you're better off using Windows Forms or WPF.
To answer your question; it is probably possible but it would take an enormous amount of work and for the above reasons I don't think it would have any payoff.
I have an .exe that runs on my computer. How can I connect to it from c#?
For example notepad.exe is running. I would like to write in notepad from windows form app or console app form. How can I do that?
Two suggestions:
either start the process using Process.Start()
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
or use SendKeys from Windows Script Host
http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
It depends on exactly what you want to do. Using SendKeys is the simplest solution but it's crude and limited in functionality. You can do more and better with SendMessage, but this will be harder to code.
Have a look at this tutorial. As far as I can tell, it does exactly what you are looking for. I realize it's in German, so just look at the source code.
Reading from another process in windows is problematic to say the least. We did some work on this a while ago and it involved hooking into the low-level Win32 API using assembly language. Essentially, it's really not pleasant and if you can avoid doing this you'll have a lot more hair on your head.
Using SendMessage would work if the application you are sending to understands the message you are trying to send to it. I suspect that you start to get into security problems with this on later Windows versions (Vista + Win7) and would have to run your application with elevated privileges.
Why do you want to do this?
I'm rebuilding an Embedded application:
Prebuild application Specifications:
Use : For dispaying the captured images/video from microscope image capturing device on windows based PC or Laptops.
Sepcifications: Prebuild on .NET plateform using VC++
Flaws : Lacks some specified features.
Current Requirement:
Want to rebuild that entire application using C# and add some additional client features.
My Questions:
Is it feasible to develop such application in C#.net?
If yeh,What kind of resources available in C# to develop desktop embedded application?
Any references which show any of such kind of application?
Your suggestions on building this kind of application.
P.S. It is essential to buid it on .NET platform.
I think by "Prebuild" you mean "Existing". Why do you want to rewrite the complete application? As you have stated that the application is written in C++.Net. You can easily add all the new functions in C# and use that code from your existing C++.Net code.
Note: I'm making this answer CW because the question is hard on the limit towards some close reasons. Everyone feel free to edit and extend it.
Is it feasible to develop such application in C#.net?
That's a tough one...from the top of my head I'd argue that it doesn't matter. If you know C#, then build it in C#, if the client wants it in C#, then build it in C#. You'll most likely have to use COM-Components or API-Invokes anyway to accomplish this.
If it is a TWAIN device, you might be better of to stick with VC++, I found TWAIN on .NET a real pain in the a** and have given up on such features. Same goes for WIA, but that might just be me.
If yes, what kind of resources available in C# to develop desktop embedded application?
I guess you mean a Widget? In that case I have no idea, I never really looked at that (at least not on Windows). But as far as I know widgets on Windows consist of a data-backend and a HTML/JavaScript-Frontend, so you'll most likely have to develop the two separately.
Any references which show any of such kind of application?
I guess any WIA/TWAIN application would be a reference, at least your description sounds so.
Your suggestions on building this kind of application.
See your first question.
Using ExternalInterface in AS3 is it possible to call OS (C#?) functions within XP?
Example: Set the desktop background to a image supplied by a flash app?
If it is possible would it be different calls when applied to different OS. And what about cross over the Mac?
Any information would be great
Thanks
If you're launching the swf from within a C# app, external interface will do just fine. Nothing will change on the flash side, but you'll need to go through a couple hoops to get it to work in C#. It's not as simple as AMF or External Interface to JS.
All the communications to C# get converted to XML describing the data, and you've gotta write XML to send back to flash. Other than that though, its relativly simple.
Here's some info on how to do it. The AS portion is Flash 8/AS2, but the C# portion should say the same.
When working with Flash from a webpage or as a desktop app, you are limited to a small security sandbox and you will not be able to make any relevant OS call. I thought that switching to AIR would give the developper more flexibility but it doesn't seem correct either. From "The Pros and Cons of Adobe Air":
AIR apps have
file access, clipboard access, support
multiple windows, support drag and
drop, and can trigger notifications
(toast in Windows). If you app needs
to interact with the desktop in other
ways, the chances are that AIR is not
suitable. For example, there is no
access to COM automation, and no way
to execute external applications. The
reason is to maintain cross-platform
compatibility. That's a worthy goal,
but it would be good to have a way out
of the sandbox. Unlike Java or .NET,
you cannot extend AIR with custom
native code libraries. Nor can you
call operating system APIs.
As Alex Jillard commented, if your swf is called inside a C# desktop application, you should be able to access more OS funcionalities although I'm not sure how.
You could use as already mentioned AIR. Another idea would be to use HippoHX (I haven't written this, the similarity with my username is just coincidence). It runs on top of the NekoVM and gives you unrestricted (so no limitations like in AIR ) access to the system.