Orfeo Toolbox  3.16
itkWin32OutputWindow.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkWin32OutputWindow.cxx,v $
5  Language: C++
6  Date: $Date: 2006-03-18 18:06:38 $
7  Version: $Revision: 1.21 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #include "itkWin32OutputWindow.h"
21 #include "itkObjectFactory.h"
22 
23 namespace itk
24 {
25 
28 
31 {
33  {
34  DestroyWindow(Win32OutputWindow::m_OutputWindow);
36  }
37 }
38 
40 LRESULT APIENTRY
42 ::WndProc(HWND hWnd, UINT message,
43  WPARAM wParam,
44  LPARAM lParam)
45 {
46  switch (message)
47  {
48  case WM_SIZE:
49  {
51  int w = LOWORD(lParam);
52 
54  int h = HIWORD(lParam);
55 
57  0, 0, w, h, true);
58  }
59  break;
60  case WM_DESTROY:
63  break;
64  case WM_CLOSE:
66  {
67  DestroyWindow(Win32OutputWindow::m_OutputWindow);
69  }
70  break;
71  case WM_CREATE:
72  break;
73  }
74  return DefWindowProc(hWnd, message, wParam, lParam);
75 }
76 
78 void
80 ::DisplayText(const char* text)
81 {
82  if ( !text )
83  {
84  return;
85  }
86 
87  if ( this->GetPromptUser() )
88  {
89  this->PromptText(text);
90  return;
91  }
92 
94  char* buffer = new char[strlen(text)+1];
95 
97  const char* NewLinePos = text;
98  while ( NewLinePos )
99  {
100  int len;
102  NewLinePos = strchr(text, '\n');
104  if(NewLinePos == 0)
105  {
107  }
110  else
111  {
112  len = NewLinePos - text;
113  strncpy(buffer, text, len);
114  buffer[len] = 0;
115  text = NewLinePos+1;
118  }
119  }
120  delete [] buffer;
121 }
122 
123 
125 void
127 ::AddText(const char* text)
128 {
129  if(!Initialize() || (strlen(text) == 0))
130  {
131  return;
132  }
133 
135  SendMessage( Win32OutputWindow::m_OutputWindow, EM_SETSEL,
136  (WPARAM)-1, (LPARAM)-1 );
137 
139  SendMessage( Win32OutputWindow::m_OutputWindow, EM_REPLACESEL,
140  0, (LPARAM)text );
141 }
142 
145 int
148 {
151  {
152  return 1;
153  }
156  WNDCLASS wndClass;
158  if (!GetClassInfo(GetModuleHandle(NULL),"OutputWindow",&wndClass))
159  {
160  wndClass.style = CS_HREDRAW | CS_VREDRAW;
161  wndClass.lpfnWndProc = Win32OutputWindow::WndProc;
162  wndClass.cbClsExtra = 0;
163  wndClass.hInstance = GetModuleHandle(NULL);
164  wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
165  wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
166  wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
167  wndClass.lpszMenuName = NULL;
168  wndClass.lpszClassName = "OutputWindow";
171  wndClass.cbWndExtra = 4;
172  RegisterClass(&wndClass);
173  }
174 
176  HWND win = CreateWindow(
177  "OutputWindow", "OutputWindow",
178  WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
179  0, 0, 512, 512,
180  NULL, NULL, GetModuleHandle(NULL), NULL);
181 
183  CREATESTRUCT lpParam;
184  lpParam.hInstance = GetModuleHandle(NULL);
185  lpParam.hMenu = NULL;
186  lpParam.hwndParent = win;
187  lpParam.cx = 512;
188  lpParam.cy = 512;
189  lpParam.x = 0;
190  lpParam.y = 0;
191  lpParam.style = ES_MULTILINE | ES_READONLY | WS_CHILD
192  | ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_VISIBLE | WS_MAXIMIZE
193  | WS_VSCROLL | WS_HSCROLL;
194 
195  lpParam.lpszName = "Output Control";
196  lpParam.lpszClass = "EDIT"; // use the RICHEDIT control widget
197  lpParam.dwExStyle = 0;
198 
200  Win32OutputWindow::m_OutputWindow = CreateWindow(
201  lpParam.lpszClass, // pointer to registered class name
202  "", // pointer to window name
203  lpParam.style, // window style
204  lpParam.x, // horizontal position of window
205  lpParam.y, // vertical position of window
206  lpParam.cx, // window width
207  lpParam.cy, // window height
208  lpParam.hwndParent, // handle to parent or owner window
209  NULL, // handle to menu or child-window identifier
210  lpParam.hInstance, // handle to application instance
211  &lpParam // pointer to window-creation data
212  );
213  const int maxsize = 5242880;
214 
216  EM_LIMITTEXT, maxsize, 0L);
217 
218 
220  ShowWindow(win, SW_SHOW);
221  return 1;
222 }
223 
224 
226 void
228 ::PromptText(const char* text)
229 {
230  OStringStream msg;
231  msg << text << "\nPress Cancel to supress any further messages.";
232  if (MessageBox(NULL, msg.str().c_str(), "Error",
233  MB_ICONERROR | MB_OKCANCEL) == IDCANCEL)
234  {
236  }
237 }
238 
239 } // end namespace itk

Generated at Sun May 19 2013 00:15:22 for Orfeo Toolbox with doxygen 1.8.3.1