2008年7月30日星期三

Visula Studio Tips

Tip #4 : Conditional Compilation Symbols


[Conditional("condition1")]
public void Foo()
{
...
}

But I found some limitations for it:
1, can not apply to interface functions;
2, the return type of functions MUST be void.


Tip #3
: In MFC projects, use "Call Browser". You can see it in right click popup menu.




Tip #2 : enable mixed mode debug. When you call managed functions from un-managed world. You may found the managed codes sample can NOT be loaded. Here is the trick to enable the load.



Tip #1 : use "ctrl + i" to search. after press the two keys, you can see a telescope shown on the screen, then type the word you want to search. Some time this is more convenient than "ctrl + f".

2008年7月22日星期二

Expression Blend Tips


Tip #1:
Use "search" to find the property you want.
Tip #2:
Use "Color Eyedropper", you can pick any displayed color on your PC screen.

2008年7月9日星期三

Use Google Reader read RSS


在使用多种RSS阅读器之后,感觉还是 Google Reader 最好,推荐给大家。这是个 Web 应用程序,不需要安装,只要访问 www.google.com/reader 即可。当然你需要一个 google 帐号。注意上图中使用红色圆圈标出的部分,使用这些功能可以方便的帮助你管理的你 feeds 。都是很简单的东西,这里就不多说了,自己动手试试吧。

2008年7月7日星期一

Minimun Windows Version for VC2008

Our project team is moving codes from vs2005 to vs2008. Most legacy codes are MFC based. We saw one compile error after the migration. We dig out the reason in MSDN.

Origin : in Chinese, in English

---- from MSDN ---

Visual C++ 概念:移植和升级
如何:修改 WINVER 和 _WIN32_WINNT
从 Visual C++ 2008 开始,Visual C++ 不支持面向 Windows 95、Windows 98、Windows ME 或 Windows NT。如果您的 WINVER 或 _WIN32_WINNT 宏被指定到这些 Windows 版本之一,则需要修改宏。当升级从 Visual C++ 的以前版本创建的项目时,如果将 WINVER 或 _WIN32_WINNT 宏指定到不再受支持的 Windows 版本,可能会看到与这些宏相关的编译错误。

2008年7月6日星期日

New Updates to MFC in VS2008

Here is a 30 minutes vedio talk about new updates to MFC in vs2008. If you are working with MFC, this is what you should watch.

2008年7月4日星期五

WPF ?

So many ab. in this world. What's WPF? If C# == C++ , then WPF == MFC; WPF just another package in .NET framework.












To develop WPF application, you need these dev tools:
1, Visual Studio 2008 (or 2005 with some sp);
2, Microsoft Expression Blend, for the GUI programming, if you never heard it, google it.

2008年7月3日星期四

The power of UserControl

System.Windows.Controls.UserControl, here is some trick you can use it.

Senario 1:
You need display a image in your program. You can use xaml only, or you can use C# codes only. In some cases, combine xaml and Csharp is powerful. First you create a UserControl which only contain the picture, then you get a new class. In Cshap codes, you just "new" one instance.

If you create a image use codes only, you need there lines at least:
Image img = new Image();
BitmapFrame bmp = BitmapFrame.Create(new Uri(@"C:\myImage.jpg", UriKind.RelativeOrAbsolute));
img.Source = bmp;
img.Stretch = Stretch.Fill;

But, use expression blend, you can create a new user control just by several mouse click. Then in codes, just one line:
new MyImage();

Data Binding

Data Binding is a key concept in WPF.

Why I can NOT data bind my class ?

public class MyClass
{
public string MyPorperty { get; set; }
}
First time, I trid to bind MyProperty in MyClass to a TextBox, but I can NOT. Why? Because I did not derived my class from interface INotifyPropertyChanged.

public class MyClass : INotifyPropertyChanged
{...}


Yes, we have to implement the interface. Csharp is a great programming language, but not magician words. So when your data changed, you have to tell the framework the change happened. That's why you need the interface.

Same reason, when you implement you own collection class, you have implement the INotifyCollectionChanged. You may encounter some problem when you want to bind a List to ComboBox/ListBox/ListView. No, you are using the wrong class, you should use ObservableCollection instead.

Use ValidationRule to check your input






-

Let's use TextBox as a sample. You can set a validation rule to the binding. When the rule check failed, a red ring will around the text box.

Related classes: System.Windows.Data.Binding, System.Windows.Controls.ValidationRule

-------------------------------------------

Some Other Good Readings:

  1. Binding menus using HeirarchicalDataTemplates

2008年7月2日星期三

Regular Expression

I started to play with regular expression since a few days ago. In .NET framework , there is a namespace System.Test.RegularExpressions where you can find helpful classes. Give you a simple sample, I wrote this for our project. Maybe this can help you start.

Senario:
We need user to input string in a text box, the string represent a frequency value, like "10.000 MHz".

Validation rule: (top down are the charaters can legally show in the string)
0 to N spaces
0 to N figure(0,1,2...9)
0 or 1 dot
1 to N figures
0 to N spaces
0 or 1 letter(the letter could be k, K, m, M, g, G)
0 or 1 letter(h or H)
0 or 1 letter(z or Z)
0 to N spaces.

C# Codes:
Regex r = new Regex(@"^\s*\d*[.]?\d+\s*[kKmMgG]?[hH]?[zZ]?\s*$");
Match m = r.Match(" 20000000000 ghz");
if (m.Success)
{
Console.WriteLine("Found match at position " + m.Index);
}


What simple! You can image how hard this could be when you just use CString, or string classes.

See detail about regular expression here.

DocProject, a document generate tool

To setup the environment, you need install these software
  1. VisualStudio 2005 or 2008;
  2. Sandcastle
  3. Help 1.x
  4. Help 2.x (optional)
  5. DocProject

Make your "Hello World" DocProject

  1. Create a C# project, do some comments in the codes, check the "XML Documentation File" in project properties "Build" tab.
  2. Create a DocProject project, just follow the wizard, you can easily to setup it;
  3. Compile the projects, this may take some time, just be patient.
  4. After compile finished, you get your document. Yeah~~

Others

After do these, you may get a compile warning 1591, because you are not comment all the classes, functions, etc. Your can suppress this warning in project properties "Build" tab.