Programmatically set Windows Live Messenger Display Picture - avatar

How can I programmatically set Windows Live Messenger (currently using 8.5.1302.1018) display picture. Possible solutions can be in C++, .NET or VB. Even just a hint could be useful.

There is an open source project called MSNP-Sharp that you should look at.
You can use this to connect to MSN and set your profile picture. Here's an example of setting the image:
try
{
Image fileImage = Image.FromFile(ConfigurationSettings.AppSettings["ImageFileName"]);
DisplayImage displayImage = new DisplayImage();
displayImage.Image = fileImage;
m_Messenger.Owner.DisplayImage = displayImage;
m_Messenger.Nameserver.StorageService.UpdateProfile(fileImage, "MyPhoto");
}
catch
{
LogError(new StackTrace(true), "Error adding avatar image.");
}

Related

UIAutomation FlaUI - Detect opening windows on application level

I am using FlaUI for test automation and it works fine so far. Now I am trying to detect opening windows and while plain UIAutomation offers to register an eventhandler for "AutomationElement.RootElement" I cannot find a way to translate this to FlaUI as it always expects an AutomationElement. I can only think of the MainWindow, but this changes with Splash, Login, Enviroment-Selections, etc.
This is what I have now, but it does not fire when I open a window:
Window win = app.GetMainWindow(automation, TimeSpan.FromSeconds(5));
UIA3AutomationEventHandler automationEventHandler = new UIA3AutomationEventHandler(win.FrameworkAutomationElement, automation.EventLibrary.Window.WindowOpenedEvent, TestAction);
automation.NativeAutomation.AddAutomationEventHandler(automation.EventLibrary.Window.WindowOpenedEvent.Id,automation.NativeAutomation.GetRootElement(), (Interop.UIAutomationClient.TreeScope)TreeScope.Descendants, null, automationEventHandler);
Following the working plain UIAutomation code:
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,
AutomationElement.RootElement,
TreeScope.Descendants,
someDelegate);
Any help would be highly appreciated! Thanks everybody!
FlaUI has a GetDesktop method on the automation object which is the RootElement. You should be able to register an event there.
With #Roemer' help I made it work. Thank you so much!
using (var automation = new UIA3Automation())
{
AutomationElement root = automation.GetDesktop();
UIA3AutomationEventHandler automationEventHandler = new UIA3AutomationEventHandler(root.FrameworkAutomationElement,
automation.EventLibrary.Window.WindowOpenedEvent, HandleClickOnceDialogs);
automation.NativeAutomation.AddAutomationEventHandler(automation.EventLibrary.Window.WindowOpenedEvent.Id,
root.ToNative(),
(Interop.UIAutomationClient.TreeScope)TreeScope.Descendants,
null, automationEventHandler);
}
private void HandleClickOnceDialogs(AutomationElement element, EventId id)
{
}

WPF native windows 10 toasts

Using .NET WPF and Windows 10, is there a way to push a local toast notification onto the action center using c#? I've only seen people making custom dialogs for that but there must be a way to do it through the os.
You can use a NotifyIcon from System.Windows.Forms namespace like this:
class Test
{
private readonly NotifyIcon _notifyIcon;
public Test()
{
_notifyIcon = new NotifyIcon();
// Extracts your app's icon and uses it as notify icon
_notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
// Hides the icon when the notification is closed
_notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false;
}
public void ShowNotification()
{
_notifyIcon.Visible = true;
// Shows a notification with specified message and title
_notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info);
}
}
This should work since .NET Framework 1.1. Refer to this MSDN page for parameters of ShowBalloonTip.
As I found out, the first parameter of ShowBalloonTip (in my example that would be 3000 milliseconds) is generously ignored. Comments are appreciated ;)
I know this is an old post but I thought this might help someone that stumbles on this as I did when attempting to get Toast Notifications to work on Win 10.
This seems to be good outline to follow -
Send a local toast notification from desktop C# apps
I used that link along with this great blog post- Pop a Toast Notification in WPF using Win 10 APIs
to get my WPF app working on Win10. This is a much better solution vs the "old school" notify icon because you can add buttons to complete specific actions within your toasts even after the notification has entered the action center.
Note- the first link mentions "If you are using WiX" but it's really a requirement. You must create and install your Wix setup project before you Toasts will work. As the appUserModelId for your app needs to be registered first. The second link does not mention this unless you read my comments within it.
TIP- Once your app is installed you can verify the AppUserModelId by running this command on the run line shell:appsfolder . Make sure you are in the details view, next click View , Choose Details and ensure AppUserModeId is checked. Compare your AppUserModelId against other installed apps.
Here's a snipit of code that I used. One thing two note here, I did not install the "Notifications library" mentioned in step 7 of the first link because I prefer to use the raw XML.
private const String APP_ID = "YourCompanyName.YourAppName";
public static void CreateToast()
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
ToastTemplateType.ToastImageAndText02);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("This is my title!!!!!!!!!!"));
stringElements[1].AppendChild(toastXml.CreateTextNode("This is my message!!!!!!!!!!!!"));
// Specify the absolute path to an image
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + #"\Your Path To File\Your Image Name.png";
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = filePath;
// Change default audio if desired - ref - https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio
XmlElement audio = toastXml.CreateElement("audio");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Reminder");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Mail"); // sounds like default
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call7");
audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call2");
//audio.SetAttribute("loop", "false");
// Add the audio element
toastXml.DocumentElement.AppendChild(audio);
XmlElement actions = toastXml.CreateElement("actions");
toastXml.DocumentElement.AppendChild(actions);
// Create a simple button to display on the toast
XmlElement action = toastXml.CreateElement("action");
actions.AppendChild(action);
action.SetAttribute("content", "Show details");
action.SetAttribute("arguments", "viewdetails");
// Create the toast
ToastNotification toast = new ToastNotification(toastXml);
// Show the toast. Be sure to specify the AppUserModelId
// on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
}
UPDATE
This seems to be working fine on windows 10
https://msdn.microsoft.com/library/windows/apps/windows.ui.notifications.toastnotificationmanager.aspx
you will need to add these nugets
Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Shell
Add reference to:
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd
And
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
And use the following code:
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier("Toast Sample").Show(toast);
The original code can be found here: https://www.michaelcrump.net/pop-toast-notification-in-wpf/
I managed to gain access to the working API for windows 8 and 10 by referencing
Windows.winmd:
C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral
This exposes Windows.UI.Notifications.
You can have a look at this post for creating a COM server that is needed in order to have notifications persisted in the AC with Win32 apps https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/.
A working sample can be found at https://github.com/WindowsNotifications/desktop-toasts

How can i save files in the phone accessible by several apps?

I try to develop several WP8 apps using the same credentials for all(same user and password).So if the user choose to change his credentials he does only once in one app and it will change for all.
Until now i used Isolatedstorage to save the credentials(as shown below) but im wondering if the files would be accessible by all the apps...i guess they would not.
So what solution do you have ?
thanks for your help
public static void SaveToFile(byte[] Encryptedfile, string FileName)
{
using (var SaveApplicationFile = IsolatedStorageFile.GetUserStoreForApplication())
{
SaveApplicationFile.DeleteFile(FileName);
using (IsolatedStorageFileStream fileAsStream = new IsolatedStorageFileStream(FileName, System.IO.FileMode.Create, FileAccess.Write, SaveApplicationFile))
{
using (Stream writer = new StreamWriter(fileAsStream).BaseStream)
{
writer.Write(Encryptedfile, 0, Encryptedfile.Length);
}
}
}
}
You can't access IsolatedStorage of other App.
Nor you can't save on SD card.
Maybe consider using Skydrive or other exteral storage.
Another idea, I'm thinking about - maybe you can use MediaLibrary and Save Picture there. And use this picture as a container for some data - maybe using Steganography ;)

YouTube on Windows Phone with MediaElement

This blog post suggests that it might be possible to play YouTube videos with the Silverlight MediaEelement directly.
<MediaElement HorizontalAlignment="Left"
VerticalAlignment="Top"
Source="http://www.youtube.com/get_video?
video_id=8yuIw_0ejLs&t=vjVQa1PpcFPrX3tFoahhu4DbniDIqTLkwybdm8xuCt8%3D&fmt=22"/>
I was wondering if this holds true for the Windows Phone 7. I have an application that is based on playing videos hosted on YouTube, and it would be nice to be able to have more control over the video experience other than just launching the browser with the YouTube video URL.
Unless you have a direct link to video content, you cannot display YouTube videos on Windows Phone 7. As far as I know, get_video is no longer available for public access.
Quoting from the Windows Phone Developer FAQ
How can I play youtube videos in my app?
Use the WebBrowserTask and open the target URL in the browser; if the youtube app is installed, it will play, if not installed, it will prompt the user to install and then play.
For everyone else still curious the problem to overcome is getting a direct link to the video which does require a small hack but it's very reliable and easy to do. Firstly you need the video id so you can get the youtube url which you can use the youtube api for. Then do something like this. I pretty much converted a userscript to silverlight.
WebClient client = new WebClient();
string url = "http://www.youtube.com/watch?v=HLQqOpILDcI";
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ClientDownloadStringCompleted);
client.DownloadStringAsync(new Uri(url, UriKind.Absolute));
the next bit looks bad.
private void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
rx = new Regex("(?<=url_encoded_fmt_stream_map=)([^(\\\\)]*)(?=\\\\)", RegexOptions.IgnoreCase);
match = rx.Matches(flashvars);
string video_format = match[0].ToString();
string sep1="%2C";
string sep2="%26";
string sep3="%3D";
string link = "";
string[] videoFormatsGroup = Regex.Split(video_format, sep1);
for (var i=0;i<videoFormatsGroup.Length;i++){
string[] videoFormatsElem = Regex.Split(videoFormatsGroup[i], sep2);
if (videoFormatsElem.Length<5) continue;
string[] partialResult1 = Regex.Split(videoFormatsElem[0], sep3);
if (partialResult1.Length<2) continue;
string url = partialResult1[1];
url = HttpUtility.UrlDecode(HttpUtility.UrlDecode(url));
string[] partialResult2 = Regex.Split(videoFormatsElem[4], sep3);
if (partialResult2.Length<2) continue;
int itag = Convert.ToInt32(partialResult2[1]);
if (itag == 18){
link = url;
}
}
}
the last bit itag==18 selects the quality according to this
{'5':'FLV 240p','18':'MP4 360p','22':'MP4 720p (HD)','34':'FLV 360p','35':'FLV 480p','37':'MP4 1080p (HD)','38':'MP4 4K (HD)','43':'WebM 360p','44':'WebM 480p','45':'WebM 720p (HD)','46':'WebM 1080p (HD)'};
now you can do whatever you want with the link like open it with mediaplayerlauncher or mediaelement. personally i'd love to download it to isolated storage and play it at the same time but at the moment that seems easier said than done. thanks for your time sorry for the long post.
I am sure you can adjust it for Windows Phone http://www.codeproject.com/KB/WPF/YouViewer.aspx

Is it possible to launch a Silverlight 4 OOB application from a web page? [duplicate]

This question already has an answer here:
Launch Silverlight Out-of-Browser from browser post-installation
(1 answer)
Closed 2 years ago.
I'm planning to build a download manager application and would like to be able to launch the application when a user clicks a button the site. The application would obviously already need to be installed on the client machine.
There are a few reasons why this needs to be written using Silverlight, but they're not really relevant to the question. I only mention it so that people don't suggest that I use another technology.
Doing a bit of a mash up from two other posts [1] and [2].
But of course this will only work for Windows not Mac. There you will have to fallback to the #michael-s-scherotter style solution.
private void Button_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.HasElevatedPermissions && System.Windows.Interop.ComAutomationFactory.IsAvailable)
{
string run = "\""%ProgramFiles%\\Microsoft Silverlight\\sllauncher.exe"\" /emulate:"Silverface.xap" /origin:\"http://www.silverlight.net/content/samples/apps/facebookclient/ClientBin/Silverface.xap\" /overwrite";
dynamic cmd = ComAutomationFactory.CreateObject("WScript.Shell");
cmd.Run(run, 1, true);
}
}
Yes. Here is an example:
http://www.silverlight.net/content/samples/apps/facebookclient/sfcquickinstall.aspx
I found a trick that launches the installed silverlight OOB from the silverlight app in-browser. Both applications should be singed and have the elevated trust.
When a user installs the silverlight OOB App first time, retrive the path and argument values from the shortcut file of the OOB app on desktop. (ref: How I can use Shell32.dll in Silverlight OOB) If you know the the path and argument values, you can launch the OOB app using Com Object.
Send the retrive the path and argument values to the silverlight App in-browser. (ref: http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx)
Store the path and argument values in a cookie.
Now, the silverlight app in-browser is able to launch the silverlight OOB using the path and argument values in the cookie.
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
shell.Run(launchPath);
}
I hope this trick is useful to you :)
It is possible if you agree to install the app each time the user clicks on it.
You also should set the app to require elevated trust in its OOB settings.
Just uninstall the app on startup (for example, in main window constructor):
if (Application.Current.HasElevatedPermissions && Application.Current.InstallState == InstallState.Installed)
{
string launcherPath = string.Empty;
using (dynamic shell = AutomationFactory.CreateObject("Shell.Application"))
{
string launcher64 = #"C:\Program Files (x86)\Microsoft Silverlight";
string launcher32 = #"C:\Program Files\Microsoft Silverlight";
dynamic folder64 = shell.NameSpace(launcher64);
if (folder64 != null)
{
launcherPath = launcher64;
}
else
{
dynamic folder32 = shell.NameSpace(launcher32);
if (folder32 != null)
{
launcherPath = launcher32;
}
}
}
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
var origin = Application.Current.Host.Source.OriginalString;
var launchCmd = string.Format(#"""{0}\sllauncher.exe"" /uninstall /origin:""{1}""", launcherPath, origin);
shell.Run(launchCmd);
}
}
(the code for uninstall was taken from this post: http://www.wintellect.com/blogs/sloscialo/programmatically-uninstalling-silverlight-out-of-browser-application)

Resources