Nothing is everything.
Friday, January 22, 2010
Thursday, January 21, 2010
Wednesday, January 20, 2010
Tuesday, January 19, 2010
Monday, January 18, 2010
Friday, January 8, 2010
Get Shortcut Path
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/99249eff-5e8f-4ce8-8fd6-625401c987ea/
private string GetShortcutPath(string shortCutPath)
{
Shell32.Shell shl = new Shell32.ShellClass();
Shell32.Folder dir = shl.NameSpace(Path.GetDirectoryName(shortCutPath));
string linkName = Path.GetFileName(shortCutPath);
Shell32.ShellLinkObject linkObj = (Shell32.ShellLinkObject)dir.Items().Item(linkName).GetLink;
return linkObj.Path;
}
We need to add reference of path ‘dll c:\windows\system32\shell32.dll’ to run the code above.
Thursday, January 7, 2010
Wednesday, January 6, 2010
API - Get System Information
- Operation System Version:
GetVersionEx: http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx - Hardware, such as processor, memory:
GetSystemInfo: http://msdn.microsoft.com/en-us/library/ms724381(VS.85).aspx - SystemDirectory, WindowsDirectory:
GetSystemDirectory: http://msdn.microsoft.com/en-us/library/ms724373(VS.85).aspx
GetWindowsDirectory: http://msdn.microsoft.com/en-us/library/ms724454(VS.85).aspx - User name and computer name:
GetUserName: http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx
GetComputerName: http://msdn.microsoft.com/en-us/library/ms724295(VS.85).aspx
GetComputerNameEx: http://msdn.microsoft.com/en-us/library/ms724301(VS.85).aspx - UI and Display:
GetSysColor: http://msdn.microsoft.com/en-us/library/ms724371(VS.85).aspx
Tuesday, January 5, 2010
WPF Data Binding - xaml
<Grid.Resources>
<collection:ArrayList x:Key="photos"/>
</Grid.Resources>
<!--Bind to element mainPate-->
<TextBlock Text="{Binding ElementName=mainPage, Path=Title}"/>
<!--Bind to self-->
<TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=Background}"/>
<!--Bind to its TemplatedParent property-->
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
<!--Bind to an ancestor-->
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType={x:Type TypeName=TreeView}}}"/>
<!--Bind to the previous data.-->
<TextBlock Text="{Binding RelativeSource={RelativeSource PreviousData}}"/>
<!--Bind to a resourc, one-way binding unless photos's type implements INotifyPropertyChanged-->
<!--WPF has an inner collection class which implements INotifyPropertyChanged-->
<TextBlock Text="{Binding Source={StaticResource photos}, Path=Count}"/>
<!--binding source can be of any type, target can only be dependency objects-->
WPF Data Binding - Code
TextBlock textBlock = new TextBlock();
//Set the binding.
textBlock.SetBinding(TextBlock.TextProperty,new Binding{ Source = this, Path = new PropertyPath("Width")});
//Remove the binding, only one-way is removed.
textBlock.Text = "";
//Remove the binding.
BindingOperations.ClearBinding(textBlock, TextBlock.TextProperty);
//Remove all the bindings.
BindingOperations.ClearAllBindings(textBlock);
Msi Properties
- The directory of the msi file: SourceDir
- The directory of the installation target: TARGETDIR
- The operation system version: VersionNT
The link below shows the detail list:
http://msdn.microsoft.com/en-us/library/aa370905(VS.85).aspx#operating_system_properties
Monday, January 4, 2010
Sunday, January 3, 2010
Filter and Pagination
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/8f27b1b8-f63c-4f8e-80c8-51fdd6e44219
Saturday, January 2, 2010
Accessing Resources in Other Assemblies
<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:MyClass},
ResourceId=MyClassBrush}">Yellow</SolidColorBrush>
<Button Background="{DynamicResource {x:Static otherAssembly:MyClass.MyClassBrushKey}}"/>
WPF unleashed, page 256
Handle Resources programmatically
//Add resources.
window.Resources.Add("backgroundBrush", new SolidColorBrush(Colors.Blue));
window.Resources.Add("borderBrush", new SolidColorBrush(Colors.Red));
//Access resources.
Button button = new Button();
button.Background = (Brush)button.FindResource("backgroundBrush");
button.BorderBrush = (Brush)button.FindResource("borderBrush");
WPF unleashed, page 254.
Merging Resources
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=”±file1.xaml”±/>
<ResourceDictionary Source=”±file2.xaml”±/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
WPF unleashed, page 253.
Accessing Resources Embedded in Another Assembly
AssemblyReference;Component/ResourceName
WPF unleashed, page243
A complete table about resources accessing methods, page 242.
How do I create a full-trust XAML Browser Application?
If you want to take advantage of functionality that requires a higher level of trust yet still want
to be integrated into a browser,you can indeed configure an XBAP to require full trust. The
two actions to enable this are a bit convoluted,however:
1. In the ClickOnce application manifest (app.manifest),add Unrestricted=”true” to
the PermissionSet XML element. For example:
<PermissionSet class=”System.Security.PermissionSet” version=”1”
ID=”Custom” SameSite=”site” Unrestricted=”true”/>
2. In the project file (with the .csproj or .vbproj extension),change
<TargetZone>Internet</TargetZone>
to
<TargetZone>Custom</TargetZone>
You can also make this change inside Visual Studio’s project properties UI on the
Security tab.
WPF unleashed, page 231
How to enable our own library to run in the WPF browser application.
You use the same mechanism that applies to all .NET components. If you mark an assembly
with the AllowPartiallyTrustedCallers attribute and install it into the Global Assembly
Cache (which can only be done if the user trusts your code and decides to run it),any of the
assembly’s public APIs can be called by any XBAP
WPF unleashed, page 230
Nonrectangular Window, Irregular Window
<Window x:Class="MyWpfSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Title="Window1" Height="300" Width="300"
MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid>
<Ellipse Fill="Red" Opacity="0.5" Margin="20">
<Ellipse.BitmapEffect>
<DropShadowBitmapEffect/>
</Ellipse.BitmapEffect>
</Ellipse>
<Button Margin="100" Click="Button_Click">Close</Button>
</Grid>
</Window>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
Referenced from book WPF unleashed, page225.
WPF Hook Message
IntPtr hwnd = new WindowInteropHelper(this).Handle;
HwndSource.FromHwnd(hwnd).AddHook(new HwndSourceHook(WndProc));
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_PAINT)
{
//Do some extra actions.
}
return IntPtr.Zero;
}
C# Check OS Version
System.Environment.OSVersion
http://msdn.microsoft.com/en-us/library/system.environment.osversion.aspx
Edit Page: PageFunction
http://msdn.microsoft.com/en-us/library/ms615540.aspx
Below is a simple sample.
PageFunction:
<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="NavigateSample.PageFunction1"
x:TypeArguments="sys:String"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageFunction1">
<Grid>
</Grid>
</PageFunction>
Show page and get result:
//Instantiate the edit page.
PageFunction1 editPage = new PageFunction1();
//Show the page.
this.NavigationService.Navigate(editPage);
//Get returned result.
string result;
editPage.Return += new ReturnEventHandler<string>((object obj, ReturnEventArgs<string> arg)=>
{
result = arg.Result;
});
Have one Frame Navigate to Another Page
<TextBlock Height="23" HorizontalAlignment="Left" Margin="66,66,0,0" Name="textBlock1" VerticalAlignment="Top" Width="278" >
Click <Hyperlink NavigateUri="Page2.xaml">Page2</Hyperlink>
<Hyperlink NavigateUri="Page3.xaml" TargetName="frame">Have frame navigate to another page.</Hyperlink>
</TextBlock>
<Frame Name="frame" Source="Page2.xaml" Margin="66,118,137,52" />
Notes about Application
1. The event fired when the current user logs off or shuts down the computer: SessionEnding
http://msdn.microsoft.com/en-us/library/system.windows.application.sessionending.aspx
2. Some properties about window: Windows, MainWindow
http://msdn.microsoft.com/en-us/library/system.windows.application.windows.aspx
http://msdn.microsoft.com/en-us/library/system.windows.application.mainwindow.aspx
3. Customerize how to exit an application: ShutdownMode
http://msdn.microsoft.com/en-us/library/system.windows.application.shutdownmode.aspx
4. Start window: StartupUri
http://msdn.microsoft.com/en-us/library/system.windows.application.startupuri.aspx
5. A dictionary for the windows to share information: Properties
http://msdn.microsoft.com/en-us/library/system.windows.application.properties.aspx