-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer_class_test.cpp
More file actions
88 lines (66 loc) · 1.9 KB
/
timer_class_test.cpp
File metadata and controls
88 lines (66 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;
#include "timer_class.h"
HWND GetConsoleHwnd(void)
{
//#define MY_BUFSIZE 1024 // Buffer size for console window titles.
HWND hwndFound; // This is what is returned to the caller.
char pszNewWindowTitle[MAX_PATH]; // Contains fabricated
// WindowTitle.
char pszOldWindowTitle[MAX_PATH]; // Contains original
// WindowTitle.
// Fetch current window title.
GetConsoleTitle(pszOldWindowTitle, MAX_PATH);
// Format a "unique" NewWindowTitle.
wsprintf(pszNewWindowTitle,"%d/%d",
GetTickCount(),
GetCurrentProcessId());
// Change current window title.
SetConsoleTitle(pszNewWindowTitle);
// Ensure window title has been updated.
Sleep(40);
// Look for NewWindowTitle.
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// Restore original window title.
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
class test_timer : public test_namespace::timer
{
public:
test_timer() : timer() {}
test_timer(unsigned time_tick) : timer(time_tick) {}
test_timer(HWND hWnd) : timer(hWnd) {}
public:
virtual void handle_timeout(unsigned timer_type)
{
std::cout << " handle_timeout \n";
}
};
int main()
{
///*
{
using namespace std;
using namespace test_namespace;
//**
HWND this_app_handle = GetConsoleHwnd();
std::cout << " " << this_app_handle << "\n";
using namespace std;
using namespace test_namespace;
test_timer a_test_timer(100);//test_timer
MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL) != 0 && GetMessage(&msg, NULL, NULL, NULL) != -1)
{
if (msg.message == WM_TIMER)
{
std::cout << "get a message \n";
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
/** = = = = = = = = = =*/
cout << "Hello world!" << endl;
return 0;
}