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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// MainFrm.cpp : CMainFrame Å¬·¡½ºÀÇ ±¸Çö
//
 
#include "stdafx.h"
#include "LogView.h"
 
#include "MainFrm.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
 
// CMainFrame
 
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    ON_WM_CREATE()
    ON_WM_CLOSE()
    ON_WM_DESTROY()
    ON_MESSAGE(UM_TRAY, &CMainFrame::OnTray)
    ON_COMMAND(ID_TRAYMENU_SHOWAPPLICATION, &CMainFrame::OnTraymenuShowapplication)
    ON_COMMAND(ID_TRAYMENU_EXIT, &CMainFrame::OnTraymenuExit)
    ON_COMMAND(ID_ViewAlwaysOnTop, &CMainFrame::OnViewalwaysontop)
END_MESSAGE_MAP()
 
static UINT indicators[] =
{
    ID_SEPARATOR,           // »óÅ Á٠ǥ½Ã±â
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
};
 
 
// CMainFrame »ý¼º/¼Ò¸ê
 
CMainFrame::CMainFrame()
{
    // TODO: ¿©±â¿¡ ¸â¹ö ÃʱâÈ­ Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    m_uShellRestart = ::RegisterWindowMessage(__TEXT("TaskbarCreated"));
    m_bOnTop = false;
}
 
CMainFrame::~CMainFrame()
{
}
 
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    /*
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
        | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("µµ±¸ ¸ðÀ½À» ¸¸µéÁö ¸øÇß½À´Ï´Ù.\n");
        return -1;      // ¸¸µéÁö ¸øÇß½À´Ï´Ù.
    }
*/
    if (!m_wndStatusBar.Create(this) ||
        !m_wndStatusBar.SetIndicators(indicators,
          sizeof(indicators)/sizeof(UINT)))
    {
        TRACE0("StatusBar Error.\n");
        return -1;      // ¸¸µéÁö ¸øÇß½À´Ï´Ù.
    }
 
    // TODO: µµ±¸ ¸ðÀ½À» µµÅ·ÇÒ ¼ö ¾ø°Ô ÇÏ·Á¸é ÀÌ ¼¼ ÁÙÀ» »èÁ¦ÇϽʽÿÀ.
    /*m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);
*/
    GoTray();
    return 0;
}
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    if( !CFrameWnd::PreCreateWindow(cs) )
        return FALSE;
    // TODO: CREATESTRUCT cs¸¦ ¼öÁ¤ÇÏ¿© ¿©±â¿¡¼­
    //  Window Å¬·¡½º ¶Ç´Â ½ºÅ¸ÀÏÀ» ¼öÁ¤ÇÕ´Ï´Ù.
    cs.style = WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
    cs.lpszName = _T("LogView");
    return TRUE;
}
 
 
// CMainFrame Áø´Ü
 
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
    CFrameWnd::AssertValid();
}
 
void CMainFrame::Dump(CDumpContext& dc) const
{
    CFrameWnd::Dump(dc);
}
 
#endif //_DEBUG
 
 
// CMainFrame ¸Þ½ÃÁö Ã³¸®±â
void CMainFrame::GoTray(void)
{
    NOTIFYICONDATA nid;
    ::ZeroMemory(&nid, sizeof(nid));
    nid.cbSize = sizeof(nid);
    nid.hWnd = m_hWnd;
    nid.uID = IDR_MAINFRAME;
    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    nid.uCallbackMessage = UM_TRAY;
    nid.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 
    wsprintf(nid.szTip, _T("%s"),_T("LogViewer"));
 
    ::Shell_NotifyIcon(NIM_ADD, &nid);
}
 
void CMainFrame::OnClose()
{
    // TODO: ¿©±â¿¡ ¸Þ½ÃÁö Ã³¸®±â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù.
    ShowWindow(SW_HIDE);
    //CFrameWnd::OnClose();
}
 
void CMainFrame::OnDestroy()
{
    NOTIFYICONDATA nid;
    nid.cbSize = sizeof(nid);
    nid.hWnd = m_hWnd;
    nid.uID = IDR_MAINFRAME;
 
    ::Shell_NotifyIcon(NIM_DELETE, &nid);
 
    CFrameWnd::OnDestroy();
}
 
LRESULT CMainFrame::OnTray(WPARAM wParam, LPARAM lParam)
{
    if(lParam == WM_RBUTTONDOWN)
    {
        SetCapture();
    }
    else if(lParam == WM_RBUTTONUP)
    {
        CMenu menu, *pMenu = NULL;
        CPoint pt;
 
        menu.LoadMenu(IDR_Tray);
        pMenu = menu.GetSubMenu(0);
 
        GetCursorPos(&pt);
        SetForegroundWindow();
        pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,
                                pt.x, pt.y, this);
        ::PostMessage(m_hWnd, WM_NULL, 0, 0);
 
        ReleaseCapture();
    }
    else if(lParam == WM_LBUTTONDBLCLK)
    {
        ShowWindow(SW_SHOW);
        SetForegroundWindow();
    }
    return 0;
}
void CMainFrame::OnTraymenuShowapplication()
{
    // TODO: ¿©±â¿¡ ¸í·É Ã³¸®±â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    ShowWindow(SW_SHOW);
}
 
void CMainFrame::OnTraymenuExit()
{
    // TODO: ¿©±â¿¡ ¸í·É Ã³¸®±â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    CFrameWnd::OnClose();
}
 
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    // TODO: ¿©±â¿¡ Æ¯¼öÈ­µÈ Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº» Å¬·¡½º¸¦ È£ÃâÇÕ´Ï´Ù.
    if(message == m_uShellRestart)        GoTray();
    
    return CFrameWnd::WindowProc(message, wParam, lParam);
}
 
void CMainFrame::OnViewalwaysontop()
{
    // TODO: ¿©±â¿¡ ¸í·É Ã³¸®±â Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    CMenu *m_pMenu;
    m_pMenu = this->GetMenu();
 
    if(m_bOnTop)
    {
        m_pMenu->CheckMenuItem(ID_ViewAlwaysOnTop, MF_UNCHECKED);
        SetWindowPos(&wndNoTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
        m_bOnTop = !m_bOnTop;
    }
    else
    {
        m_pMenu->CheckMenuItem(ID_ViewAlwaysOnTop,MF_CHECKED);
        SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
        m_bOnTop = !m_bOnTop;
    }
}