Scope
LogFrame.cpp
1 #include "StdAfx.h"
2 #include "LogFrame.h"
3 
4 namespace scope {
5  namespace gui {
6 
7 void CLogFrame::OnFinalMessage(HWND /*hWnd*/) {
8  delete this;
9 }
10 
11 CLogFrame::~CLogFrame() {
12  // If we land here through an exception, OnDestroy is eventually not called thus we need to detach here to avoid
13  // an invalid pointer in the DisplayController
14  if ( attached ) {
16  attached = false;
17  }
18 }
19 
20 int CLogFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {
21  m_hWndClient = view.Create(m_hWnd, rcDefault);
22 
23  SetWindowText(L"Logbook");
24 
26  attached = true;
27  return 1;
28 }
29 
30 void CLogFrame::OnDestroy() {
31  // We have to detach here, because after OnDestroy the HWND is not valid anymore
33  attached = false;
34 }
35 
36 BOOL CLogFrame::PreTranslateMessage(MSG* pMsg) {
37  if(view.PreTranslateMessage(pMsg))
38  return TRUE;
39 
40  return CFrameWindowImpl<CLogFrame>::PreTranslateMessage(pMsg);
41 }
42 
43 void CLogFrame::AppendLogText(const std::wstring& _text) {
44  LONG start, end;
45  view.GetSel(start, end);
46  view.AppendText(_text.c_str());
47  view.SetSel(start, end);
48 }
49 
50 void CLogFrame::ReplaceLogText(const std::wstring& _text) {
51  LONG start, end;
52  view.GetSel(start, end);
53  view.SetWindowText(_text.c_str());
54  // Keeps the caret position (SetWindowText resets it to the beginning)
55  view.SetSel(start, end);
56  view.Invalidate();
57 }
58 
59 std::wstring CLogFrame::GetLogText() {
60  std::size_t textlen = view.GetWindowTextLength()+1; // +1 since terminating \0 is not counted
61  std::vector<wchar_t> buffer(textlen, L' ');
62  view.GetWindowText(buffer.data(), textlen); // empty control gives only a \0
63  return std::wstring(buffer.begin(), buffer.end()-1);
64 }
65 
66 }}
scope::ScopeLogger scope_logger
our ScopeLogger here
Definition: LogFrame.h:15
void DetachLogFrame()
Detaches a CLogFrame.
Definition: ScopeLogger.cpp:46
bool attached
are we attached to the DisplayController?
Definition: LogFrame.h:21
CLogView view
the view class inside the frame
Definition: LogFrame.h:18
This is the include file for standard system include files, or project specific include files that ar...
void AttachLogFrame(gui::CLogFrame *const _logframe)
Attaches a CLogFrame as the logbook window.
Definition: ScopeLogger.cpp:30