No more annual renewal fee for Windows developer accounts

Standard

Windows Dev Center requires only a one-time registration payment, which grants developers the ability to submit apps to both the Windows Store and Windows Phone Store, with no annual renewal fee.

Lifetime Dev Center Subscriptions

Lifetime Dev Center Subscriptions

And this is applicable for the existing developers as well. You can find more details about it from Account subscription management page.

Account subscription management

Account subscription management

You can get more details from Windows Blog

How to set Bing wallpaper as your desktop wallpaper

Standard

This post is about setting Bing wallpaper as your desktop wallpaper using C# and Windows Forms. Bing.com is famous for having some nice pictures as wallpaper, updated on daily basis. The Bing Desktop application comes with same feature. Here is the code snippet, which has two parts one, download the wallpaper image from bing.com and set it as wallpaper using WIN32 APIs.

The URL for getting wallpaper is used by bing WP7 application.

http://appserver.m.bing.net/BackgroundImageService/TodayImageService.svc/GetTodayImage?dateOffset=0&urlEncodeHeaders=true&osName=wince&osVersion=7.10&orientation=480×800&deviceName=WP7Device&mkt=en-US&AppId=1

In the URL, you can change the orientation to 1024×768, landscape mode in Windows Phone to get the wallpaper. And the mkt parameter specifies the region, I am keep it as en-US. The following snippet will download the wallpaper and save it in the Temp folder as wallpaper.bmp. The SetWallpaper function will set the wallpaper.bmp as desktop wallpaper using Win32 API.

WebClient webClient = new WebClient();
webClient.OpenReadCompleted += (o, ev) =>
{
    if (ev.Error == null)
    {
        var wallpaper = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
        using (var bitmap = Bitmap.FromStream(ev.Result))
        {
            bitmap.Save(wallpaper, ImageFormat.Bmp);
            SetWallpaper(wallpaper);
        }
    }
};

webClient.OpenReadAsync(new Uri(bingserviceUrl));

Here is the SetWallpaper method

private static void SetWallpaper(string wallpaper)
{
    RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
    key.SetValue(@"WallpaperStyle", 2.ToString());
    key.SetValue(@"TileWallpaper", 0.ToString());

    SystemParametersInfo(SPI_SETDESKWALLPAPER,
        0, wallpaper,
        SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}

You require following WIN32 API declarations as well.

const int SPI_SETDESKWALLPAPER = 20;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDWININICHANGE = 0x02;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

In the SetWallpaper function, I am setting the wallpaper picture position as Stretched. You can change this by changing the WallpaperStyle and TileWallpaper values.

Picture Position WallpaperStyle TileWallpaper
Stretched 2 0
Centered 1 0
Tiled 1 1
Fit* 6 0
Fill* 10 0
* – Windows 7 and later

Happy Programming :)

How to change the startup page on a WP7 application

Standard

Sometimes you may need to change the startup page of Windows Phone application. By default it will be pointing to MainPage.xaml. You can modify the WMAppManifest.xml to change the default page. In the WMAppManifest.xml you will find the following.(You can get the WMAppManifest.xml by expanding the properties node in the Project Explorer window.)

<Tasks>
  <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>
</Tasks>

Happy Programming :)

How to handle hardware back button in Windows Phone

Standard

If you want to display an exit confirmation from your Windows Phone app, if user press the hardware back button, here is the code snippet. (It is not a recommended practice, as per Windows Phone market place certification requirements, if user pressing the back button from the application’s first page, application should exit)

protected override void OnBackKeyPress(CancelEventArgs e)
{
    if (MessageBox.Show("Are you sure want to exit?", "Confirm", 
        MessageBoxButton.OKCancel) != MessageBoxResult.OK)
    {
        e.Cancel = true;
    }

    base.OnBackKeyPress(e);
}

It will display a message box like this, if user press the back button.

WP7 Exit confirmation

WP7 Exit confirmation

Clicking on OK will exit the application.

Happy Coding.