Skip to main content

WPF - Simple App

· One min read

Step by Step tutorial for creating Simple WPF Application

  1. Open Visual Studio 2010
  2. Go to ‘File’ Menu and select ‘New Project’
  3. Select ‘WPF Application’ as shown below
  4. Give the application name as “FirstWPFApp”
  5. Visual studio generates two xaml files ( App.xaml , MainWindow.xaml) And corresponding code behind .cs files (App.xaml.cs, MainWindow.xaml.cs)
  6. Drag and drop a Button from toolbox on to the Window and give names as ‘btnClickMe’ and Add an even to it by double click on the button.
  7. Open MainWindow.xaml.cs in btnClickMe_Click event add MessageBox.Show("Hello World !!");
  8. Compile and Build the project.

C-Pointers What is the output

· One min read

FAQ-1

void main() { 
int _p = 91; //compilation error
printf("%d n",_ p);
printf("%d n", p);
}

OUTPUT: Does not compile error C2440: 'initializing' : cannot convert from 'int' to 'int *'

FAQ-2

void main() { 
int i = 91; int *p = &i;
printf("%d n", *p); printf("%d n", p);
}

OUTPUT: 91 1245024

FAQ-3

void main() { 
int i = 91;
int *p = &i;

printf(" p = %d n",p);
printf(" p = %d n", p);
printf(" &p = %d n", &p);
printf(" (&p) = %d n", (&p));
printf(" ((&p)) = %d n", ((&p)));
}

OUTPUT: i = 91 &i = 1245024 p = 91 p = 1245024 &p = 1245012 (&p) = 1245024 ((&p)) = 91

FAQ-4

void main() { 
const int p;
int i;
i = 10;
p = &i;
printf("p = %d, p = %d, i = %d", p, p, i);
}

OUTPUT p = 1245012, p = 10, i = 10
Tags:

Find the length of the string in C

· One min read
//str_len returns the length of str
int str_len(char* str) {
int len; len = 0;
for (int i = 0; str[i] != '\\0'; i++)
{
len ++;
}
return len;
}

void main() {
char* website = "www.github.com";
int len = str_len(website);
printf("length = %d n", len);
}

OUTPUT length = 17
Tags:

Set a variable that can be accessed on all pages of a Windows Phone App

· One min read

App.xaml.cs

public partial class App : Application {
public string sName { get; set; }

public static new App Current
{
get { return Application.Current as App; }
}
...
...


}

Page1.xaml.cs

public partial class Page1 : PhoneApplicationPage { 
public string _sName;

public Page1()
{
InitializeComponent();

_sName = App.Current.sName;
}

}

Can't login to Windows 8 with account live password! ?

· One min read

Steps

  1. open the 'On screen keyboard' and use it to type the password

Preventive measure steps:

It's good to setup sign-in options in order to have one or more ways to login to your PC

  1. Go to charm bar select 'Change PC Settings'

  2. Select Users

  3. Use 'Sign-in options' to use 'Picture Password' and 'PIN' password

How to Delete \"Windows.old\" in windows 8

· One min read

1. Press the Windows+R keys to open the Run dialog, type cleanmgr, and press Enter.

2. Select the Windows drive, and click/tap on OK. NOTE: You will not see this window unless you have more than one drive or partition on your computer with a drive letter.

3. Click/tap on the Clean up system files button

4. Click/tap on the Previous Windows installation(s) box to check it, and click/tap on OK. (see screenshot below)

5. Click/tap on Delete Files.

6. When Disk Cleanup finishes, the C:Windows.old folder will be deleted.

Installation Setup for Windows Phone 7 Development

· 2 min read
  1. Install Visual Studio 2010 Professional or  Visual Studio 2010 Ultimate

  2. Install Microsoft VisualStudio 2010 ServicePack1 http://www.microsoft.com/en-in/download/details.aspx?id=23691

or

If you don’t have Visual Studio 2010 Professional or Visual Studio 2010 Ultimate go for 3) Visual Studio 2010 Express for Windows Phone (MSDN) http://www.microsoft.com/visualstudio/en-us/products/2010-editions/windows-phone-developer-tools

  1. After installing  Visual Studio 2010 Professional or  Visual Studio 2010 Ultimate or Visual Studio 2010 Express for Windows Phone install following Windows Phone SDK’s

  2. Install Microsoft XNA Game Studio 4.0 http://www.microsoft.com/en-in/download/details.aspx?id=23714

  3. Install Windows Phone SDK 7.1 SDK http://www.microsoft.com/en-us/download/details.aspx?id=27570

  4. Install Windows Phone SDK 7.1.1 SDK Update http://www.microsoft.com/en-us/download/details.aspx?id=29233

ATL Tutorial (DLL or Inproc Server)

· One min read

In this tutorial we will be creating

  1. MathComp which is a DLL or Inproc server and exposes the Add and Sub functions.

  2. An MFC Dialog Based Application which acts like a Client for MathComp

For complete tutorial refer Tutorial

WPF Architecture

· One min read

The major code portions of WPF are.

PresentationFramework, PresentationCore, and milcore WPF. PresentationFramework, PresentationCore are managed components but only milcore is an unmanaged component Milcore is developed in unmanaged code in order to enable tight integration with DirectX. All display in WPF is done through the DirectX engine, allowing for efficient hardware and software rendering.

1. Presentation Framework

Most of the important WPF elements are in Presentation Framework.  Presentation Framework Provides high-level services like layout, data binding, command handling.

2. Presentation Core

Presentation provides .NET API that uses rendering services for the MIL. During graphics programming we work with Core API.

3. Milcore

The composition engine in milcore (Media Integration) is extremely performance sensitive. MIL takes Bitmaps, Vectors, and media render them to the DirectX

WPF Basics

· 3 min read

1. WPF Definition

Windows Presentation Foundation is the successor to Windows Forms for Microsoft Desktop Application development. WPF uses XAML to create visible User Interface (UI) elements like (buttons, listboxes, editboxes, etc).

WPF applications allows take advantage of the best attributes of diverse systems, such as DirectX (3-D and hardware acceleration), Adobe Flash (animation support), and HTML (declarative markup and easy deployment), styles, templates, documents and typograph.

2. Advantages of WPF Applications

The advantages of WPF applications include:

  1. Declarative programming – WPF uses Extensible Application Markup Language (XAML) declarative programming to define the layout of application objects and to represent 3-D models, among other things. This allows graphic designers to directly contribute to the look and feel of WPF applications.

  2. Tight multimedia integration –WPF provides consistent programming model to create -D graphics, video, speech, and rich document viewing.

  3. Resolution independence –WPF uses vector graphics to make the applications resolution-independent. WPF Applications can shrink or enlarge elements on the screen, independent of the screen’s resolution.

  4. Hardware acceleration – WPF is built on top of Direct3D, which offloads work to graphics processing units (GPUs) instead of central processor units (CPUs). This provides WPF applications with the benefit of hardware acceleration, permitting smoother graphics and enhanced performance.

  5. Rich composition and customization – WPF controls are easily customizable. We need not write any code to customize controls in very unique ways. WPF also lets you create skins for applications that have radically different looks.

  6. Easy deployment – WPF provides options for deploying traditional Windows applications (using Windows Installer or ClickOnce).

  7. Culturally aware controls – static text in controls and the return data for the String function are modified according to the culture and language specified by the end user's operating system.

3. WPF vs WinForms

WPF is also more suitable for applications with rich media content than Windows Forms applications. This includes applications using:

  1. Multimedia and animation with DirectX technology
  2. HD video playback
  3. XPS documentation for high quality printing
  4. Control rotation (Windows Forms applications support text rotation only)

WPF is also great if you need to create a skinned user interface, or if you need to bind to XML data, or dynamically load portions of a user interface from a Web service, or want to create a desktop application with a Web-like navigation style.

WPF stores its data more efficiently hence individual objects will be small, but there tend to be more objects in WPF than in WinForms .This would require more RAM than Windows Application.

CPU utilization will go up compared to WinForms   WPF objects onscreen takes more CPU as normal WinForms rendering (again depending on the requirement).

4. XAML - eXtensible Application Markup Language

Definition: XAML (zammel) is an XML-based declarative markup. We can create visible User Interface (UI) elements like (buttons, listboxes, editboxes, etc) using XAML.

XAML files are XML files .xaml file name extension encoded as UTF-8.

Example:

C# Button  Compile (Design-time) and Execute (Runtime) where as XAML Button Load, Parse,Render and Display