所以我開發的應用程序在倒計時完成後拍攝一張照片。我已經在Windows 7中使用win32定時器,但我不知道如何在Windows metro中應用它。我需要一些幫助或C++中的一些示例代碼,涉及如何在設定的時間過期後觸發事件。 在此先感謝您的幫助使用計時器在Windows metro中用C++觸發事件
回答
在C++中,聲明DispatcherTimer,並在其上註冊一個事件處理程序。
DispatcherTimer類 - http://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.dispatchertimer
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx
示例代碼:
using namespace Windows::UI::Xaml;
using namespace Windows::Foundation;
void Application1::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
DispatcherTimer^ timer = ref new DispatcherTimer;
timer->Tick += ref new Windows::UI::Xaml::EventHandler(this, &Application1::MainPage::DispatcherTimer_Tick);
TimeSpan t;
t.Duration=1000;
timer->Interval = t;
timer->Start();
}
void Application1::MainPage::DispatcherTimer_Tick(Platform::Object^ sender, Platform::Object^ e)
{
// Put TO DO stuff here...
}
文檔包括其使用的一個例子。這個例子是用C#編寫的,但它應該直接轉換成C++/CX。
不幸的是翻譯成C#這是困難的,因爲很明顯的DateTimeOffset庫中的C++版本不存在。 – HollywoodCurls
C++有'std :: chrono'。 –
DateTimeOffset是Windows :: Foundation :: DateTime在C++ –
- 1. 在設計時間觸發事件c#
- 2. C#Windows服務計時器未觸發
- 3. 定時器已用事件不會在Windows服務中觸發c#vs2013
- 4. 使用UserControl paint事件觸發空閒計時器?
- 5. 計時器事件不會觸發
- 6. System.Timers計時器未觸發事件
- 7. C#中的Windows Mobile 6觸發事件#
- 8. 不觸發事件C#WPF
- 9. 使用javascript在asp.net中觸發事件
- 10. 在Kaa中使用Webapp觸發事件
- 11. 使用jquery觸發我的計時器
- 12. System.Timers.Timer在Windows服務中多次觸發已使用事件
- 13. 事件觸發器打印使用VC++
- 14. jQuery,使用多個事件觸發器?
- 15. 如何使用事件觸發器庫?
- 16. 使用UpdatePanel時事件不會觸發
- 17. C#觸發事件
- 18. C#COM事件不觸發
- 19. 我怎麼能分出用戶觸發,並計劃在C#觸發textbox1_TextChange事件
- 20. 在C中調用ShowDialog(ParentForm)時會觸發什麼事件#
- 21. 在空JComboBox觸發器上調用addItem觸發器actionPerformed事件
- 22. 使用window.location.hash觸發事件
- 23. window.onblur事件在使用IE8時也會觸發window.onfocus事件
- 24. 觸發事件處理器回發c#
- 25. 使用WPF事件觸發事件
- 26. metro應用定製的ListView KeyDown事件不觸發
- 27. 如何觸發在Windows Mobile中的keydown事件提交在C#
- 28. 在Windows Phone應用程序中使用c計數定時器#
- 29. 如何在WP8.1中使用MVVM Light中的事件觸發器?
- 30. 停止使用ProcessCmdKey在C#中觸發事件的密鑰?
謝謝你,這正是我需要的。 – HollywoodCurls
我遇到了問題'timer-> Tick + = ref new Windows :: UI :: Xaml :: EventHandler(this,&Application1 :: MainPage :: DispatcherTimer_Tick);編譯器不能識別「windows :: ui :: xaml :: eventhandler」作爲類型 – HollywoodCurls
事件的類型是Windows :: Foundation :: EventHandler ^'。 –