WINCE 定时器0控制LED上位机源码

  /******************************************************
  *作    者:温子祺
  *联系方式:[email protected]
  *创建事件:2010-09-06
  *说    明: 定时器闪烁LED上位机源码
  ******************************************************/

 

转载请注明出处,谢谢!

 

  
    
1 // TIMERDlg.cpp : 实现文件
2   //
3  
4 #include " stdafx.h "
5 #include " TIMER.h "
6 #include " TIMERDlg.h "
7
8 #ifdef _DEBUG
9   #define new DEBUG_NEW
10   #endif
11
12   #define IOCTL_START_TIMER 1
13 #define IOCTL_STOP_TIMER 2
14
15 // CTIMERDlg 对话框
16
17 CTIMERDlg::CTIMERDlg(CWnd * pParent /* =NULL */ )
18 : CDialog(CTIMERDlg::IDD, pParent)
19 {
20 m_hIcon = AfxGetApp() -> LoadIcon(IDR_MAINFRAME);
21
22 m_hTimer = INVALID_HANDLE_VALUE;
23 }
24
25 void CTIMERDlg::DoDataExchange(CDataExchange * pDX)
26 {
27 CDialog::DoDataExchange(pDX);
28 }
29
30 BEGIN_MESSAGE_MAP(CTIMERDlg, CDialog)
31 #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
32 ON_WM_SIZE()
33 #endif
34 // }}AFX_MSG_MAP
35 ON_BN_CLICKED(IDC_BUTTON1, & CTIMERDlg::OnBnClickedStartTimer)
36 ON_BN_CLICKED(IDC_BUTTON2, & CTIMERDlg::OnBnClickedStopTimer)
37 ON_BN_CLICKED(IDC_BUTTON3, & CTIMERDlg::OnBnClickedOpenTimer)
38 ON_BN_CLICKED(IDC_BUTTON4, & CTIMERDlg::OnBnClickedCloseTimer)
39 END_MESSAGE_MAP()
40
41
42 // CTIMERDlg 消息处理程序
43
44 BOOL CTIMERDlg::OnInitDialog()
45 {
46 CDialog::OnInitDialog();
47
48 // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
49 // 执行此操作
50 SetIcon(m_hIcon, TRUE); // 设置大图标
51 SetIcon(m_hIcon, FALSE); // 设置小图标
52
53 // TODO: 在此添加额外的初始化代码
54
55
56
57 return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
58 }
59
60 #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
61 void CTIMERDlg::OnSize(UINT /* nType */ , int /* cx */ , int /* cy */ )
62 {
63 if (AfxIsDRAEnabled())
64 {
65 DRA::RelayoutDialog(
66 AfxGetResourceHandle(),
67 this -> m_hWnd,
68 DRA::GetDisplayMode() != DRA::Portrait ?
69 MAKEINTRESOURCE(IDD_TIMER_DIALOG_WIDE) :
70 MAKEINTRESOURCE(IDD_TIMER_DIALOG));
71 }
72 }
73 #endif
74
75
76 void CTIMERDlg::OnBnClickedStartTimer()
77 {
78 if (m_hTimer == INVALID_HANDLE_VALUE)
79 {
80 MessageBox(L " ERROR: m_hTimer is invalid! " );
81
82 return ;
83 }
84
85 ::DeviceIoControl(m_hTimer,IOCTL_START_TIMER,NULL, 0 ,NULL, 0 ,NULL,NULL);
86 }
87
88 void CTIMERDlg::OnBnClickedStopTimer()
89 {
90 if (m_hTimer == INVALID_HANDLE_VALUE)
91 {
92 MessageBox(L " ERROR: m_hTimer is invalid! " );
93
94 return ;
95 }
96
97 ::DeviceIoControl(m_hTimer,IOCTL_STOP_TIMER,NULL, 0 ,NULL, 0 ,NULL,NULL);
98 }
99
100 void CTIMERDlg::OnBnClickedOpenTimer()
101 {
102 m_hTimer = CreateFile(_T( " TMR1: " ),GENERIC_READ | GENERIC_WRITE, 0 ,NULL,OPEN_EXISTING, 0 , 0 );
103
104 if (m_hTimer == INVALID_HANDLE_VALUE)
105 {
106 MessageBox(L " ERROR:Create file for m_hTimer fail! " );
107 }
108 }
109
110 void CTIMERDlg::OnBnClickedCloseTimer()
111 {
112 if (m_hTimer)
113 {
114 CloseHandle(m_hTimer);
115
116 m_hTimer = INVALID_HANDLE_VALUE;
117
118 }
119 else
120 {
121 MessageBox(L " ERROR: m_hTimer is invalid! " );
122 }
123 }
124

 

 

你可能感兴趣的:(WinCE)