2013年4月30日 星期二

[筆記] 印出long long結果

有三種方式可以讓printf印出64-bit的long long整數結果

1. 使用MSVC或GNU的編譯器都可用

   1: "%llu" 

2. 使用MSVC編譯器可用


   1: "%I64d" 

3. 使用"inttypes.h"時可用


   1: %"PRId64" 

2013年4月28日 星期日

[W8App] Add AppBar (1)

在程式中加入AppBar最基本的方法,是在MainPage.xaml的<Page></Page>區間中加入以下程式。

   1: <Page.BottomAppBar>
   2:   <AppBar>
   3:     <StackPanel Orientation="Horizontal">
   4:     </StackPanel>
   5:   </AppBar>
   6: </Page.BottomAppBar>

Page.BottomAppBar如字面所示,會在應用程式下方嵌入AppBar。除了BottomAppBar以外,也有TopAppBar可產生嵌在應用程式上部顯示的appbar。為了GUI排版的需求,通常不會直接在AppBar中加入元件,而是先放置StackPanel後,再把元件放置於StackPanel中,以其有一致的風格。

如果要有更複雜的風格變化,就加入Grid來幫忙吧,像下面的方式可以在AppBar常見的左邊和右邊都有元件形式。


   1: <AppBar>
   2:     <Grid>
   3:         <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
   4:         </StackPanel>
   5:         <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
   6:         </StackPanel>
   7:     </Grid>
   8: </AppBar>

系統其實已經提供不少預設的AppBarButton給我們使用,只是需要把他們「打開」而已。

開啟專案的Common / StandardStyles.xaml 檔案,可以發現有一大段的程式被隱藏在下面這段敘述之後:

<!-- 
Standard AppBarButton Styles for use with Button and ToggleButton

An AppBarButton Style is provided for each of the glyphs in the Segoe UI Symbol font.
Uncomment any style you reference (as not all may be required).
-->



這裡面包含了各種AppBarButton的圖片文字,關於這些AppBarButton的icon圖片可參考MSDN的AppBar button style images這篇文章。

我選擇了PlayAppBarButtonStyle來測試,在StandardStyles.xaml中把PlayAppBarButtonStyle的註釋區間取消,程式會像這樣:


   1: <Style x:Key="PlayAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
   2:     <Setter Property="AutomationProperties.AutomationId" Value="PlayAppBarButton"/>
   3:     <Setter Property="AutomationProperties.Name" Value="Play"/>
   4:     <Setter Property="Content" Value="&#xE102;"/>
   5: </Style>

然後在MainPage.xaml的AppBar中加入Button元件,並指定其風格為"{StaticResource PlayAppBarButtonStyle}",程式會像這樣:


   1: <AppBar>
   2:     <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
   3:         <Button x:Name="PlayBtn" Style="{StaticResource PlayAppBarButtonStyle}"/>
   4:     </StackPanel>
   5: </AppBar>

在VS2012中看到的結果會長的像這樣

clip_image001

UI完成後別忘了處理使用者按下PlayButton的事件,除了直接在.xaml中寫入程式碼外,我比較推廌透過VS2012的Properties來加入事件,可以直接在程式中產生相對應的程式碼,省去不少Key in的工作。

clip_image002

clip_image003

如果對自製AppBar button有與趣的也可參考MSDN的Quickstart: Styling app bar buttons

2013年4月9日 星期二

整合Windows 8與google行事曆

四月一日愚人節一到,我的行事曆中公司使用的google行事曆全不見了。難道我提前被炒魷魚了嗎XD??受到二個偉大帝國的戰火波及的小老百姓只好自已想辨法。


雖然windows 8的行事曆不能直接加入google帳號來整合行事曆,不過還是有旁門小道可用。

1. 首先要開啟IE瀏覽器,從瀏覽器進入skydrive的行事曆。



2. 選用匯入的功能


3. 選擇訂閱,在行事曆中輸入google行事曆的URL即可


不過正常人應該是記不住自己goolge行事曆的URL XD

5. 從瀏覽器進入google的行事曆後,開啟行事曆的設定頁


6. 切換到日曆頁點選等等要整合到windows 8行事曆的日曆



7. 點選私人網址的ICAL格式


8. 複製你的私人網址


9. 貼到windows 8行事曆的URL,輸入一個你自己喜歡的行事曆名稱後按下『訂閱』就大功告成了。