Windows 8 DirectX SwapChainBackgroundPanel Questions - c#

I come from two distinct backgrounds: I have much experience with WPF/XAML/C# app development and equal experience with C++/DirectX development. I hear about the ability to use DirectX and XAML together and I get all excited, but now I have hit this wall.
I'm trying to use the SwapChainBackgroundPanel in a WPF application. But I'm trying to use C# as the underlying language. I keep running into issues where, regardless of the type of C# project I create (PCL, WPF, Windows Store) none of these types are defined [namely I've been looking for SwapChainBackgroundPanel and some other DX stuff like the device and etc.)
So my question is: how does this work in C#? I've seen the simple shooter example from the MSDN done in C++ and it makes sense; I get it. But I feel like I'm missing one of those "gotcha's" when trying to do it in C#.
Any advice, or maybe a link to an example, or at best a little tutorial on setting up a C#/XAML/DX app would be amazing. Thanks everyone.

There is no SwapChainBackgroundPanel available to a WPF app (that is in PresentationCore). The closest you are going to get is the D3DImage class, but it's not exactly the same. See this discussion.
I don't think you can fully utilize the DirectX capabilities of a Windows 8 Store app (SwapChainBackgroundPanel) from C#. You're going to have to do your DirectX work in C++ as in the example you described. You can certainly combine the three (Xaml, C#, C++) as in this example, but I don't think a 100% C# app is possible.

The answer is wrong. It is possible to fully utilize C# throught a wrapper.
I did this myself with SharpDx which is actually one of the microsoft recommendations to use DirectX in C#.
As for the choice of XAML Library, Universal Windows App 10 or Windows Store App 8 is the way to go. Use a SwapChainPanel instead of SwapChainBackgroundPanel.

Related

Trying to Understand Windows Forms and Threading in C#

Recently I’ve been working on a windows wallpaper manager. It will scan multiple directories for images and have a settings window to customize. In addition, I want to bypass the built-in wallpaper and instead use a windows form based off the ideas discussed here: Setting a Windows form to be bottommost to allow for greater control over image placement. I have built the file operations to find the wallpapers, and various other support operations.
However, I am stumped on how to implement a windows form properly. Not just the one in the Stack Overflow post above. So far none of my CompSci classes (7 so far) have discussed GUIs, and thus I have no knowledge to work from. I turned to the internet to learn how to work with GUIs. While I learned plenty to start a thread, or show a form, I was never able to find anything that described the proper way to engineer an application with a GUI. All I have learned in respect to engineering the application is to limit the number of threads, and try to separate the GUI from the non-GUI related code (if that makes sense).
Like I have said, I have no clue what I am doing. If someone would be willing to give me pointers or even a link to something on this subject, that would be amazing!
EDIT: I have been using this as a learning exercise, and I have mostly been learning from trial and error, probably mostly error
To draw on the true desktop, you need to get a handle to it: GetDesktopWindow is the function to use. But to change the wallpaper you do not draw on the desktop, but instead you use the dedicated API for handling the desktop wallpaper: SystemParametersInfo(SPI_SETDESKWALLPAPER, ...). There is also the legacy COM Shell interface, IActiveDesktop and IActiveDesktop::SetWallpaper.
As you can see, none of the APIs to manipulate the desktop and the wallpaper are managed (C#, .Net) so you will have to jump through some hoops to get this working from C#. If your goal is to learn C# style UI, I would recommend to stick to the 'blessed' way of doing this (winforms, WPF etc) and do not try to jump straight to p-Invoke and COM interop. Perhaps you can pick another project, eg. display the images/pictures in a carousel in a form.
If you're curious still, Google for C# and SystemParametersInfo or IActiveDesktop and you'll find examples of how to do this from managed C#, many examples right here on StackOverflow.
Bonus: of course Raymond Chen has a blog on this topic: How do I put a different wallpaper on each monitor?.

Do games like Starcraft 2 use Windows Forms to build their UI?

This may be a dumb question...
When I log into Starcraft 2 and see that beautiful UI, I can't help but wonder if it's designed using Windows Forms (.Net or C#). Is the login box just some kind of Windows dialog or do they do their own thing - whatever that may be?
Is it possible to get that much customization within Windows Forms?
No. Games and other apps that use DirectX to take control of the video device don't use WinForms or even the Win32 API for screen output.
StarCraft 2 most likely implements its own windowing and UI system, completely independent of the Windows API or WinForms library.
Yes, you can write an app in C# to perform similar DirectX graphics output, but using DirectX is not as simple as working with WinForms. I wouldn't recommend attempting to write a DirectX app as a way to teach yourself C# unless you are already very experienced with DirectX through other languages or tools (C++, mostly).
WinForms is fine for learning C# and whatever IDE tool chain you choose to use. After you're comfortable with C# patterns and terminology, then tackle learning how to write DirectX code with C#.
No. They use DirectX. DirectX bypasses normal windows and operates at alower level.
You can customize a form to a great degree. You have full control over painting it to look however you want.

.net 3.5 windows form application, using webcam

Having searched high and low for native c# hook to webcam, I found 5 basic ways to interact with the camera.
Video for Windows (VFW)
DirectX
avicap32.dll
WIA
3rd party tools
My requirement is to take a photo. The application will be used on some legacy windows XP and Vista machines, but going forward Windows 7 and greater will be required. So what might the best approach be with the broad install base? Just reading WIA looked like the way to go but looks like some changes were made so it works a little different now (I don't know for sure). I understand that some people have done combos.
Might need to crop photo, but that is really about it.
For school visitor monitoring.
I think the best thing is to use the WIA. I know a third party toolkit that could help you doing your requirements which is leadtools. You can check this Tutorial
I would always try to pick up something already on the web and tweak it to my own needs... some open source project or an example where the mainly portion of my app is already made.
on Codeplex you can find a nice library to work with webcams and it's simply called
WebCam Library for WinForm and WPF with C# and VB.NET
Give that a try, maybe you can even help the project, by contributing your own findings, and everyone is a winner... isn't Open Source a great idea?!

An embedded application for windows desktop using .NET platform?

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.

Good framework for a C# developer to use for visually stunning presentation layer

I am about to write a front end app, which will be used as a media center app. It will plug directly into a high definition TV. Essentially transforming my laptop into a media player. While this concept is not new, I want custom functionality, so this is why I am not reusing existing products.
I'm a C# developer, so the app should ideally be written in C#. And there is 1 other consideration, I need to accept input via the MCE Remote.
I was considering using Silverlight for this. Would you recommend this? Or any other recommendations for frameworks before I begin planning around this.
Thanks in advance.
This is the type of stuff that the Windows Presentation Foundation was meant for. You'll get a lot more access to the hardware than Silverlight would provide (I.E. that MCE remote you mentioned). You mark up your UI with vector graphics/XAML, and then perform the logic with C#.
EDIT: WPF also has support out of the box for animations which can make your UI a lot more interactive.
EDIT 2: Scott Hanselman has written a really cool application called BabySmash and posted the source online. It basically intercepts keyboard input and shows shapes and sounds on the computer. It's a good "child-proofing" method for your PC. The code could provide you with some insight into WPF and how to do the animations and interactivity that you're looking for.
Is this a desktop app? If so I would use WPF. Silverlight is a subset of WPF, so using WPF you could potentially do more.
Silverlight or WPF, if you want some extra power. Both have a similar programming model (with XAML and code-behind) so you might be able to start with Silverlight and move up to WPF if you need.
The VLC api might be useful for playing your media, someone has created a C# wrapper for it:
http://wiki.videolan.org/.Net_Interface_to_VLC
WPF is certainly the way to go, and for playing media check out the excellent WPF MediaKit: http://wpfmediakit.codeplex.com/ I've used it successfully in many projects.

Categories

Resources