【发布时间】:2012-08-22 01:35:53
【问题描述】:
所以我正在开发一个在倒计时完成后拍照的应用程序。我在 Windows 7 中使用过 win32 计时器,但我不知道如何在 Windows Metro 中应用它。我需要一些帮助或 c++ 中的一些示例代码,这些代码与如何在设定的时间到期后触发事件有关。 提前感谢您的帮助
【问题讨论】:
标签: c++ windows timer microsoft-metro
所以我正在开发一个在倒计时完成后拍照的应用程序。我在 Windows 7 中使用过 win32 计时器,但我不知道如何在 Windows Metro 中应用它。我需要一些帮助或 c++ 中的一些示例代码,这些代码与如何在设定的时间到期后触发事件有关。 提前感谢您的帮助
【问题讨论】:
标签: c++ windows timer microsoft-metro
在 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...
}
【讨论】:
Windows::Foundation::EventHandler<Platform::Object^>^。
usage requires Windows::UI::Xaml::DispatcherTimer::Tick' to be a data member
该文档包含一个使用示例。该示例使用 C# 编写,但应该可以直接将其转换为 C++/CX。
【讨论】: