-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_win.cpp
136 lines (111 loc) · 3.25 KB
/
main_win.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <omni/plot.hpp>
#include <tchar.h>
#include <math.h>
//////////////////////////////////////////////////////////////////////////
/// @brief The main window procedure.
LRESULT CALLBACK mainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static omni::plot::XYPlotter *plot_wnd = 0;
static omni::plot::LineGraph *line = 0;
if (WM_CREATE == uMsg)
{
plot_wnd = new omni::plot::XYPlotter(hWnd, WS_CHILD|WS_VISIBLE, WS_EX_CLIENTEDGE);
plot_wnd->setFixedAspectRatio(true);
plot_wnd->setScroll(true, true);
plot_wnd->enableMoving(true);
plot_wnd->enableZooming(true);
line = new omni::plot::LineGraph();
line->getPen()->SetColor(Gdiplus::Color::Red);
line->setSmoothCurve(true);
line->setMarker(omni::plot::StarMarker(5));
line->getMarker()->getPen()->SetColor(Gdiplus::Color::Lime);
line->getMarker()->setBrush(Gdiplus::SolidBrush(Gdiplus::Color::Blue));
line->getMarker()->setSize(10.0f);
//line->setBrush(Gdiplus::SolidBrush(Gdiplus::Color::Blue));
//line->setBarWidth(0.09f);
for (int i = 0; i < 20; ++i)
line->push_back(i*0.1f - 1.0f, sinf(i*0.5f));
plot_wnd->attach(*line);
plot_wnd->update();
}
if (WM_SIZE == uMsg)
{
RECT rc = {0};
::GetClientRect(hWnd, &rc);
::InflateRect(&rc, -10, -10);
::MoveWindow(plot_wnd->handle(),
rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, TRUE);
}
if (WM_MOUSEWHEEL == uMsg)
{
return ::SendMessage(plot_wnd->handle(), uMsg, wParam, lParam);
}
if (WM_CLOSE == uMsg)
{
delete plot_wnd;
plot_wnd = 0;
delete line;
line = 0;
::DestroyWindow(hWnd);
return 0;
}
if (WM_DESTROY == uMsg)
{
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
//////////////////////////////////////////////////////////////////////////
/// @brief The application entry point.
int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE, LPTSTR, int showCmd)
{
LPCTSTR mainWndClass = _T("omni::plot::test::MainWnd");
HWND hWnd = 0;
ULONG_PTR gdip_token = 0;
Gdiplus::GdiplusStartupInput gdip_in;
Gdiplus::GdiplusStartup(&gdip_token, &gdip_in, 0);
{ // register window class
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = mainWndProc;
wc.hInstance = hInst;
wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = HBRUSH(COLOR_BTNFACE + 1);
wc.lpszClassName = mainWndClass;
if (!::RegisterClassEx(&wc))
return -1;
}
try
{
hWnd = ::CreateWindowEx(0, mainWndClass, _T("omni::plot"),
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, 0);
::ShowWindow(hWnd, showCmd);
::UpdateWindow(hWnd);
if (hWnd)
{ // the message loop
MSG msg = {0};
while (BOOL ret = ::GetMessage(&msg, NULL, 0, 0))
{
//if (ret == -1)
// return -1;
//else
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
} // the message loop
}
catch (const std::exception &e)
{
::MessageBoxA(hWnd, e.what(), "Fatal Error",
MB_OK|MB_ICONERROR);
}
Gdiplus::GdiplusShutdown(gdip_token);
return 0;
}