How can I implement these Windows 10 "media notifications" into a C# WPF desktop application?
You are talking about the SystemMediaTransportControls class. Its usage it described on Microsoft Docs.
However, this API is designed for UWP so getting this to work in a regular desktop application like WPF takes a little more work. There are some answers here on StackOverflow that describe how to do this, but there is also some newer, official documentation from Microsoft on how to use these WinRT APIs.
Unfortunately, the System Media Transport Controls API is not directly supported in Desktop apps [5], so it gets a little more complicated, as described here [6].
In short, for .NET 5:
Install the Windows 10 SDK of a version you like (e.g. through the VS Installer);
Change the target framework to the SDK version you installed, e.g. net5.0-windows10.0.19041.0.
Use the API interops as described on [6] to get an instance.
In the case of SMTP, you'd want to use Windows.Media.SystemMediaTransportControlsInterop. This requires the handle to a window, which you can get with WindowInteropHelper in WPF.
Use the SystemMediaTransportControls instance as described on [2].
Related
For some reason everything I've found online says that the Accelerometer class is only for winRT applications and I can't use it unless I code against winRT. I dont understand what winRT is. And my app can't be a metro style app because I need special access to different APIs that I've read can only be accessed in a WPF app. Also windows 8 metro style apps wont work with windows 7 which I would like my app to work for. Also I've only recently started programming so explain it to me like I'm a 4 year old.
Thanks!
The accelerometer you are referring to is a specific WinRT (Windows RunTime) class which is not available in .NET.
WinRT API was made for phones and tablets, but also integrated in Windows 8 / 8.1. It's basically the API for 'Metro' apps and therefore requires such an app. It will definitely not work for Windows 7, since WinRT is not available for this OS. I'm also somehow wondering, why you would need an accelerometer on Win7 (Notebook?), but that is a different topic.
I've once tried to get WinRT stuff working in C#.NET, and to my knowledge, this is not possible.
If you can provide us any additional information about your idea, maybe we can offer you an acceptable alternative.
Since the Metro environment on Windows 8 lacks most of the .NET framework class libraries or contains a substancially pared down version, is it possible to execute a "ping" from a Metro style application? There is support for Sockets, so I guess there is hope, but I don't know where to start, since every "C# Ping" example uses System.Net.NetworkInformation.Ping and that is not available in WinRT.
I also looked into the source code for Mono, and their ping implementation fires up ping.exe and returns the result from the standard output window of the command line.
No, unfortunately not. ICMP is not supported in WinRT: IcmpCreateFile and related Win32 APIs are only available in the "desktop" API partition. ICMP can be implemented using raw sockets but since these are not supported in WinRT (and usually require elevation, anyway), this option is also not available to you.
As the developer of a Windows Store network scanning tool myself (http://lanscan.rcook.org/), I'd love to be able to do this.
I am trying to build a Windows 8 "metro-style" app that will operate as a "app killer". For those of you who have used Win8 (Tech Preview) you'll notice that once you open a metro-style app you cannot close it (without going into Task Manager and ending the process).
My challenge is that I cannot access 'System.Diagnostics.Process' from my metro-style app, nor do I know if there is an comparable alternative within the WinRT. I also thought of building a separate app that hosts a service for my metro app to interface with, but I'd like to do this with a single app.
Fundamentally, I am looking for a pattern for building Metro-style apps that leverage .NET 4.0 components, specifically to be able to enumerate and kill other processes running on the PC.
CLARIFICATION: I am less concerned with this specific application than I am with access that type of .NET functionality within a Metro-style app
Thanks
To your specific question, this functionality is not available. Apps are not allowed to interact or interfere with other apps.
To answer your more general question, the APIs available to Metro style applications is limited compared to what is available to desktop applications. C# has a subset of the .Net library available, much like Silverlight does. The same is true for C++ where a subset of the desktop Win32/COM APIs are available.
From what I understand (watching Build2011 videos) a Metro App won't be able to do that...
Interaction between processes is severally limited to specific Contracts (the charms on the right: Search, Send-to).
Think Phone, not Desktop.
You might be able to build a non-Metro Win8 app though.
Don't waste too much time on this. I expect that in a beta a close option (perhaps even a charm) will be included. Until then use a keyboard Alt-F4 or the Task Manager
C++:
Window::Current->CoreWindow->Close();
or
Window::Current->Close();
I haven't explored the difference between these two (more precisely, I don't know how CoreWindow differs from Current. I could assume though...
I'm using an Oracle VBox with Win8 on my Win7 machine to develop a C++ Metro App using VS 11. I used both of the above methods. I verified in Task Manager the app was not running on both Win8 and the Simulator.
I want to use windows 7 features like icon overlay, and thumbnail tasks but my question is that can i do it without using any other API on just my plain .net 3.5. i recently enabled jumplists on an application in my c#.net 3.5 using the Shell routine so can something like that be done for icon overlay and other windows 7 taskbar features.
And can old application like notepad which i am sure was made years ago use these new feaures?
I guess it depends on the meaning of "use". You get jumplists for free if you use the Common Files Dialog. If your app is WPF or MFC, you get some Windows 7 stuff in the latest version of those libraries (not 3.5). Failing that, you will need to either ask Windows directly (use an API) or use a library that isn't part of .NET 3.5 that will ask Windows for you. I recommend you use the Code Pack. One line of code for an overlay icon, for example. It also has non-visual Windows 7 features like Restart and Recovery, Power Awareness (.NET events when the machine goes on battery etc). It was last updated November 18th 2009 and I am expecting a new release any day now.
If you really don't want to use .NET wrapped taskbar functionalities,
you can try this link that calls overlay via PInvoke. For other W7 taskbar options you can check on the same site.
Anyway I suggest you to use the .NET managed API
The new Windows 7 taskbar features, like jump lists, previews, etc. are really cool, and I want to allow my C# applications to use them. I have two questions:
First of all, how can I use these functions (in general)? I found two articles by Microsoft about this, but I'm not really sure what to do. Could you provide links to a library, as well as some sample code?
Next, let's say that I figure out how to use these Taskbar functions. My question is, is there some built-in way of checking whether the OS is Windows 7, and thus enabling the taskbar functions? If I didn't have this logic in my app, would it have problems if it was run on a non-Win7 machine?
Thanks!
In the first article you link to there is a sample library that you can download that makes use of the new Windows 7 features.
This article shows how to check the version of Windows your application is running on.
As always, if you call an API that isn't in existence, then yes, your app will experience some turbulence. Remember, it's (almost) always better to check for a condition and act accordingly once (as in application startup) than to try something over and over in code and catch exceptions.
Windows API Code Pack for .NET Framework is your one stop shop for a ton of .NET API for Windows programming, including Taskbar. This library gives you a complete API set to work with Windows 7 Taskbar and then some. It also includes samples for WPF, and Winform.
Another good source for Windows 7 content is the Windows Team Blog