`
阿尔萨斯
  • 浏览: 4248180 次
社区版块
存档分类
最新评论

.Net Mirco Framework 2007技术大会

 
阅读更多

.Net Mirco Framework 2007技术大会

2006年在《程序员》杂志上通过看马宁的专栏文章,第一次知道了.Net MF。一年后的今天终于近距离地接触了.Net Mirco Frmaework,对MF有了一定的感性认识。

最近公司很多项目都有大量嵌入式设备使用,由于WinCE系统相对较大,对硬件平台要求过高,所以对.Net MF一直比较关注。今天总算大开眼界了。

<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 414.75pt; HEIGHT: 311.25pt" type="#_x0000_t75"><imagedata o:title="MF07091801" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image001.jpg"></imagedata></shape>

微软公司的Colin MillerDigi公司的John Leier在上午的演讲拉开了.Net MF序幕,针对嵌入式领域,一个从软件角度进行阐述,另一个从硬件平台角度进行呼应,一软一硬,二者强强联合,恐怕未来嵌入式智能设备一半以上的项目开发要被其收入囊中了。下午的中文演讲给人感觉有些干瘪,两三个演讲,平均短短十几分钟就草草收场。后来微软公司杜伟的演讲,从VS2005一行行难以看清的代码,到一个个令人惊艳的样例把MF开发技术推向最前台。

<shape id="_x0000_i1026" style="WIDTH: 240pt; HEIGHT: 182.25pt" type="#_x0000_t75"><imagedata o:title="MF07091802" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image003.jpg"><font size="3"></font></imagedata></shape>

Digi公司很是有魄力,免费送出15套开发套件(5个作为回答问题的奖品,10个抽奖),自己即没有回答问题的勇气,也没有好的运气,只好剩下羡慕的份了。

最后为每个人送出的<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="g"><span lang="EN-US"><font face="Times New Roman">1G</font></span></chmetcnv>优盘(类似微软今年MVP大礼包中的优盘)很有分量,不仅是<chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="g"><span lang="EN-US"><font face="Times New Roman">1G</font></span></chmetcnv>的容量,并且里面竟然把所有的幻灯片拷贝其中,更没有想到的是,MF SDK也在里面,真棒!

回到家迫不及待装了一份MF SDKMicroFrameworkSDK.MSI 区区只有5998 kb,强!),有模拟器,也有示例。

<shape id="_x0000_i1027" style="WIDTH: 414.75pt; HEIGHT: 299.25pt" type="#_x0000_t75"><imagedata o:title="MF07091806" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image005.jpg"><font size="3"></font></imagedata></shape>

其中几个示例不知道为什么编译成功,就是运行失败,对第二示例比较感兴趣,可以绘制图形,并且可以贴图。

<shape id="_x0000_i1028" style="WIDTH: 137.25pt; HEIGHT: 208.5pt" type="#_x0000_t75"><imagedata o:title="MF07091804" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image007.jpg"><font size="3"></font></imagedata></shape>

<shape id="_x0000_i1029" style="WIDTH: 152.25pt; HEIGHT: 231.75pt" type="#_x0000_t75"><imagedata o:title="MF07091805" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image009.jpg"><font face="Times New Roman" size="3"></font></imagedata></shape>

<shape id="_x0000_i1030" style="WIDTH: 150pt; HEIGHT: 228pt" type="#_x0000_t75"><imagedata o:title="MF07091803" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image011.jpg"><font face="Times New Roman" size="3"></font></imagedata></shape>

相关代码如下:

//Copyright(C)MicrosoftCorporation.Allrightsreserved.

usingSystem;
usingSystem.Collections;
usingSystem.Threading;

usingMicrosoft.SPOT;
usingMicrosoft.SPOT.Input;
usingMicrosoft.SPOT.Hardware;
usingMicrosoft.SPOT.Presentation;
usingMicrosoft.SPOT.Presentation.Media;
usingMicrosoft.SPOT.Presentation.Controls;
usingMicrosoft.SPOT.Presentation.Shapes;

usingPresentationDemo;


/**///////////////////////////////////////////////////////////////////////////////


publicsealedclassMyApp:Application...{
//ThisstaticfieldpreventstheobjectfrombeingGC'd
privatestaticGpioButtonInputProviders_gpioInputProvider;

publicFontNinaBFont;
publicFontSmallFont;
publicBitmapSnowflake;

privateMyApp()...{
//InitializetheButtons/Pinsdispatcher
s_gpioInputProvider=newGpioButtonInputProvider(this.Dispatcher,null);

//Loadsomeresources
NinaBFont=Resources.GetFont(Resources.FontResources.NinaBFont);
SmallFont
=Resources.GetFont(Resources.FontResources.SmallFont);
Snowflake
=Resources.GetBitmap(Resources.BitmapResources.Snowflake);
}


protectedoverridevoidOnStartup(EventArgse)...{
//Createandsettheapplication'smainwindow
this.MainWindow=newMainMenuWindow(this);
base.OnStartup(e);
}


publicvoidGoHome()...{
Buttons.Focus(
this.MainWindow);//Setfocusbacktothemainwindow
}


publicstaticvoidMain()...{
newMyApp().Run();//Starttheapp'smainwindow
}

}



/**///////////////////////////////////////////////////////////////////////////////


//Thisisthebaseclassofallourwindows;itmakeseverywindowvisible,
//setsthewindow'ssizetothefullsizeoftheLCD,andgivethewindowfocus
internalclassPresentationWindow:Window...{
protectedMyAppm_app;

protectedPresentationWindow(MyAppapp)...{
m_app
=app;

//MakethewindowvisibleandthesizeoftheLCD
this.Visibility=Visibility.Visible;
this.Width=SystemMetrics.ScreenWidth;
this.Height=SystemMetrics.ScreenHeight;
Buttons.Focus(
this);//Setfocustothiswindow
}


protectedoverridevoidOnButtonDown(ButtonEventArgse)...{
//RemovethiswindowformtheWindowManager
this.Close();

//Whenanybuttonispressed,gobacktotheHomepage
m_app.GoHome();
}

}


/**///////////////////////////////////////////////////////////////////////////////


internalsealedclassMainMenuWindow:PresentationWindow...{
privateListBoxm_listbox;

publicListBoxMainListBox...{get...{returnm_listbox;}}

publicMainMenuWindow(MyAppapp)
:
base(app)...{

ColorinstructionTextColor
=ColorUtility.ColorFromRGB(192,192,192);
ColorbackgroundColor
=ColorUtility.ColorFromRGB(26,118,183);
ColorunselectedItemColor
=ColorUtility.ColorFromRGB(192,192,255);//Unselectedlistboxitemcolor
ColorselectedItemColor=Colors.White;//Selectedlistboxitemcolor

//TheMainwindowcontainsaveritcalStackPanel
StackPanelpanel=newStackPanel(Orientation.Vertical);
this.Child=panel;

//Thetopchildcontainstextwithinstructions
TextFlowtextflow=newTextFlow();
textflow.TextAlignment
=TextAlignment.Center;
textflow.Visibility
=Visibility.Visible;
textflow.TextRuns.Add(
newTextRun(Resources.GetString(Resources.StringResources.SelectAnItemFromBelow),
app.NinaBFont,instructionTextColor));
panel.Children.Add(textflow);

//Addablanklinetothestack
panel.Children.Add(textflow=newTextFlow());
textflow.TextRuns.Add(
"",app.NinaBFont,instructionTextColor);
textflow.Visibility
=Visibility.Visible;

//Thenextchildcontainsalistboxwithoptions
m_listbox=newListBox();

//Preparethelistbox
Buttons.Focus(m_listbox);
panel.Children.Add(m_listbox);
this.Background=m_listbox.Background=newSolidColorBrush(backgroundColor);

m_listbox.SelectionChanged
+=delegate(Objectsender,SelectionChangedEventArgse)...{
Int32previousSelectedIndex
=e.PreviousSelectedIndex;
if(previousSelectedIndex!=-1)...{//Iftherewasapreviousindex
//Changepreviously-selectedlistboxitemcolortounselectedcolor
((Text)m_listbox.Items[previousSelectedIndex].Child).ForeColor=unselectedItemColor;
}


//Changenewly-selectedlistboxitemcolortoselectedcolor
((Text)m_listbox.Items[e.SelectedIndex].Child).ForeColor=selectedItemColor;
}
;

//Addtheitemstothelistbox
foreach(StringsinnewString[]...{"VerticalStack","HorizontalStack","Canvas","Diagonal"})...{
Texttext
=newText(m_app.NinaBFont,s+"PanelDemo");
text.ForeColor
=unselectedItemColor;
text.TextAlignment
=TextAlignment.Center;
text.Width
=this.Width;
ListBoxItemlbi
=newListBoxItem();
lbi.Background
=m_listbox.Background;
lbi.Child
=text;
m_listbox.Items.Add(lbi);
}

m_listbox.SelectedIndex
=0;

//Addablanklineinthestack
panel.Children.Add(textflow=newTextFlow());
textflow.TextRuns.Add(
"",app.NinaBFont,instructionTextColor);
textflow.Visibility
=Visibility.Visible;

//Thebottomchildcontainstextwithreturninstructions
textflow=newTextFlow();
textflow.TextAlignment
=TextAlignment.Center;
textflow.Visibility
=Visibility.Visible;
textflow.TextRuns.Add(
newTextRun("(AfterviewingaPanelDemo,hitEntertoreturntothisscreen)",
app.NinaBFont,instructionTextColor));
panel.Children.Add(textflow);
}


protectedoverridevoidOnButtonDown(ButtonEventArgse)...{
//If<enter>buttonispressed,gointotheselecteddemo</enter>
if(e.Button==Button.Select)...{
switch(MainListBox.SelectedIndex)...{
case0://VerticalStackPanelDemo
newStackPanelDemo(m_app,Orientation.Vertical);
break;
case1://HorizontalStackPanelDemo
newStackPanelDemo(m_app,Orientation.Horizontal);
break;
case2://CanvasPanelDemo
newCanvasPanelDemo(m_app);
break;
case3://DiagonalPanelDemo
newDiagonalPanelDemo(m_app);
break;
}

}


//Don'tcallbaseimplementation(base.OnButtonDown)orwe'llgobackHome
}


protectedoverridevoidOnGotFocus(FocusChangedEventArgse)...{
//Wheneverthiswindowgetsfocus,itgivesittoitslistbox
Buttons.Focus(m_listbox);
base.OnGotFocus(e);
}

}



/**///////////////////////////////////////////////////////////////////////////////


internalsealedclassStackPanelDemo:PresentationWindow...{
//ThisclassshowshowtobuildyourownshapedrawinginaDrawingContext
privatesealedclassCross:Shape...{
publicCross()...{}

publicoverridevoidOnRender(DrawingContextdc)...{
//Drawalinefromtop,lefttobottom,right
dc.DrawLine(base.Stroke,0,0,Width,Height);

//Drawalinefromtop,righttobottom,left
dc.DrawLine(base.Stroke,Width,0,0,Height);
}

}


publicStackPanelDemo(MyAppapp,Orientationorientation)
:
base(app)...{
StackPanelpanel
=newStackPanel(orientation);
this.Child=panel;
panel.Visibility
=Visibility.Visible;

Shape[]shapes
=newShape[]...{
newEllipse(),
newLine(),
newPolygon(newInt32[]...{0,0,50,0,50,50,0,50}),//ASquare
newRectangle(),
newCross()//Ourowncustomshape
}
;

for(Int32x=0;xshapes.Length;x++)...{
Shapes
=shapes[x];
s.Fill
=newSolidColorBrush(ColorUtility.ColorFromRGB(0,255,0));
s.Stroke
=newPen(Color.Black,2);
s.Visibility
=Visibility.Visible;
s.HorizontalAlignment
=HorizontalAlignment.Center;
s.VerticalAlignment
=VerticalAlignment.Center;
s.Height
=Height-1;
s.Width
=Width-1;

if(panel.Orientation==Orientation.Horizontal)
s.Width
/=shapes.Length;
else
s.Height
/=shapes.Length;

panel.Children.Add(s);
}

}

}



/**///////////////////////////////////////////////////////////////////////////////


internalsealedclassCanvasPanelDemo:PresentationWindow...{
publicCanvasPanelDemo(MyAppapp)
:
base(app)...{
Canvascanvas
=newCanvas();
this.Child=canvas;
this.Background=newSolidColorBrush(ColorUtility.ColorFromRGB(0,255,255));

for(Int32x=0;xWidth;x+=Width/4)...{
for(Int32y=0;yHeight;y+=Height/4)...{
Texttext
=newText(m_app.SmallFont,"("+x+","+y+")");
Canvas.SetLeft(text,x);
Canvas.SetTop(text,y);
canvas.Children.Add(text);
}

}

}

}



/**///////////////////////////////////////////////////////////////////////////////


internalsealedclassDiagonalPanelDemo:PresentationWindow...{
publicDiagonalPanelDemo(MyAppapp)
:
base(app)...{
DiagonalPanelpanel
=newDiagonalPanel();
this.Child=panel;
this.Background=newLinearGradientBrush(
ColorUtility.ColorFromRGB(
192,0,0),ColorUtility.ColorFromRGB(32,0,0),0,0,Width,Height);

for(Int32x=0;x4;x++)...{
Bitmapb
=newBitmap(Width/4,Height/4);
b.StretchImage(
0,0,app.Snowflake,b.Width,b.Height,(UInt16)((x+1)*50));
Imageimage
=newImage(b);
panel.Children.Add(image);
}

}


//ThisclassshowshowtobuildyourownPanel
privatesealedclassDiagonalPanel:Panel...{
publicDiagonalPanel()...{
}


protectedoverridevoidMeasureOverride(intavailableWidth,intavailableHeight,outintdesiredWidth,outintdesiredHeight)...{
//Calledtocalculatethewidth/heightdesired
desiredWidth=0;
desiredHeight
=0;
foreach(UIElementchildinChildren)...{
if(child.Visibility!=Visibility.Collapsed)...{
child.Measure(Int32.MaxValue,Int32.MaxValue);
Int32childWidth,childHeight;
child.GetDesiredSize(
outchildWidth,outchildHeight);
desiredWidth
+=childWidth;
desiredHeight
+=childHeight;
}

}

}


protectedoverridevoidArrangeOverride(intarrangeWidth,intarrangeHeight)...{
Int32x
=0,y=0;
foreach(UIElementchildinChildren)...{
if(child.Visibility!=Visibility.Collapsed)...{
Int32childWidth,childHeight;
child.GetDesiredSize(
outchildWidth,outchildHeight);
child.Arrange(x,y,childWidth,childHeight);
x
+=childWidth;
y
+=childHeight;
}

}

}

}

}



/**///////////////////////////////////////////////////////////////////////////////

后记:此外在会上还遇到了我的偶像马宁、马琪、张欣(还是张欣强,通过回答问题获得一个MF开放套件),如果他们不介意附上照片作个留念:-)

<shape id="_x0000_i1031" style="WIDTH: 96pt; HEIGHT: 70.5pt" type="#_x0000_t75"><imagedata o:title="MVP070917" src="file:///C:/DOCUME~1/yefan/LOCALS~1/Temp/msohtml1/01/clip_image013.jpg"></imagedata></shape>




<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics