xoblite™ / Blackbox for Windows bb5 | RC6 preview | 0.25.2.14
http://xoblite.net/
Console.cpp File Reference
#include "Console.h"

Functions

LRESULT CALLBACK ConsoleWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 

Variables

const char szConsoleName [] = "BBConsole"
 
ConsolepConsole
 
SettingspSettings
 
BImagepBImage
 
ToolbarpToolbar
 
DesktoppDesktop
 
int consoleMessageSubscription [] = { BB_TOGGLECONSOLE, BB_CONSOLEMESSAGE, BB_RECONFIGURE, 0 }
 

Function Documentation

◆ ConsoleWndProc()

LRESULT CALLBACK ConsoleWndProc ( HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam )
135{
136 switch (message)
137 {
138 //====================
139
141 {
142 if (strlen(pConsole->messageToBlock) > 0)
143 {
144 if (!_stricmp((LPCSTR)lParam, pConsole->messageToBlock))
145 {
146 // This message (typically a bro@m part of an @Script) should not be echoed in the console...
147 pConsole->messageToBlock[0] = '\0';
148 break;
149 }
150 }
151
152 //====================
153
154 if ((int)pConsole->messageList.size() >= 50)
155 {
156 // We already have the maximum 50 messages in the list, remove the oldest...
157 if (pConsole->messageList[0]->icon != NULL) DeleteObject(&pConsole->messageList[0]->icon);
158 delete pConsole->messageList[0];
159 pConsole->messageList.erase(pConsole->messageList.begin());
160 }
161
162 //====================
163
164 messageListItem *newMessage = new messageListItem;
165
166 newMessage->type = (int)wParam;
167
168 //====================
169
170 if (newMessage->type == CONSOLE_INFORMATION_MESSAGE) newMessage->icon = LoadIcon(NULL, IDI_INFORMATION);
171 else if (newMessage->type == CONSOLE_WARNING_MESSAGE) newMessage->icon = LoadIcon(NULL, IDI_WARNING);
172 else if (newMessage->type == CONSOLE_ERROR_MESSAGE) newMessage->icon = LoadIcon(NULL, IDI_ERROR);
173 else if (newMessage->type == CONSOLE_SHELL_MESSAGE) newMessage->icon = LoadIcon(pConsole->hConsoleInstance, MAKEINTRESOURCE(IDI_XOBLITE));
174 else newMessage->icon = NULL; // CONSOLE_REGULAR_MESSAGE, CONSOLE_PLAIN_MESSAGE, CONSOLE_INDENTED_MESSAGE, CONSOLE_SEPARATOR
175
176 //====================
177
178 if (newMessage->type != CONSOLE_SEPARATOR)
179 {
180 char message[MAX_LINE_LENGTH];
181 if (newMessage->type == CONSOLE_REGULAR_MESSAGE)
182 {
183 // Add a timestamp to regular messages...
184 _strtime(message);
185 strncat_s(message, sizeof(message), " -> ", _TRUNCATE);
186 strncat_s(message, sizeof(message), (LPCSTR)lParam, _TRUNCATE);
187 }
188 else strncpy_s(message, sizeof(message), (LPCSTR)lParam, _TRUNCATE);
189 message[sizeof(message)-1] = '\0'; // Failsafe
190
191 // Replace any \r\n in the string with a single space character...
192 LPSTR ptr;
193 while (ptr = strchr(message, '\r'))
194 {
195// int nLen = strlen(ptr);
196// memmove(ptr+3, ptr, nLen);
197// strncpy(ptr, " -> ", 4);
198 ptr[0] = ' ';
199 }
200 while (ptr = strchr(message, '\n'))
201 {
202 int nLen = strlen(ptr);
203 memmove(ptr, ptr+1, nLen);
204 }
205
206// strncpy(newMessage->msg, message, sizeof(newMessage->msg));
207 strncpy_s(newMessage->msg, sizeof(newMessage->msg), message, _TRUNCATE);
208 newMessage->msg[sizeof(newMessage->msg)-1] = '\0';
209
210 //====================
211
212 // Detect any URL in the message and if found make it clickable...
213 char* url = StrStrI(newMessage->msg, "http://");
214 if (url == NULL) url = StrStrI(newMessage->msg, "https://");
215 if (url == NULL) url = StrStrI(newMessage->msg, "file://");
216 if (url == NULL) newMessage->url[0] = '\0';
217 else
218 {
219 strncpy_s(newMessage->url, sizeof(newMessage->url), url, _TRUNCATE);
220 newMessage->url[sizeof(newMessage->url)-1] = '\0';
221
222 // Check whether the URL is part of an @Script, and if so perform some additional operations on the two strings... (URL+message)
223 if (IsInString(newMessage->msg, "@Script"))
224 {
225 char* first = newMessage->url;
226 char* pipe = StrStrI(newMessage->url, "|");
227 if (pipe != NULL) newMessage->url[pipe-first] = '\0';
228 else if (newMessage->url[strlen(newMessage->url)-1] == ']') newMessage->url[strlen(newMessage->url)-1] = '\0';
229
230 char updatedMsg[350];
231 updatedMsg[sizeof(updatedMsg) - 1] = '\0';
232 int n = url - newMessage->msg;
233 strncpy_s(updatedMsg, sizeof(updatedMsg), newMessage->msg, n);
234 strcat_s(updatedMsg, " "); // ...to avoid the later URL highlighting covering the character immediately *before* the URL...
235 strcat_s(updatedMsg, newMessage->url);
236 strcat_s(updatedMsg, " "); // ...to avoid the later URL highlighting covering the character immediately *after* the URL...
237 strcat_s(updatedMsg, &url[strlen(newMessage->url)]);
238 strncpy_s(newMessage->msg, sizeof(newMessage->msg), updatedMsg, _TRUNCATE);
239 newMessage->msg[sizeof(newMessage->msg)-1] = '\0';
240 }
241
242 // If not part of an @Script, we remove everything else after the URL (using blank space as delimiter) including any ending parantheses and commas...
243 else if (strchr(newMessage->url, ' '))
244 {
245 char temp[sizeof(newMessage->url)];
246 Tokenize(newMessage->url, temp, " ");
247 strcpy(newMessage->url, temp);
248 switch(newMessage->url[strlen(newMessage->url)-1])
249 {
250 case ')':
251 case '>':
252 case ',':
253 {
254 newMessage->url[strlen(newMessage->url)-1] = '\0';
255 }
256 }
257 }
258 }
259 }
260
261 //====================
262
263 pConsole->messageList.push_back(newMessage);
264
265 //====================
266
267 if (!pSettings->consoleHidden)
268 {
269 pConsole->UpdateConsoleWindow();
270
271/*
272 if (!SetTimer(pConsole->hConsoleWnd, CONSOLE_SETLABEL_TIMER, 4000, (TIMERPROC)NULL))
273 {
274 MessageBox(0, "Error creating console timer!", szConsoleName, MB_OK | MB_ICONERROR | MB_TOPMOST);
275 Log("Could not create console timer!", NULL);
276 return 0;
277 }
278*/
279 }
280 }
281 break;
282
283 //===========================================================================
284/*
285 case WM_TIMER:
286 {
287 if (wParam == CONSOLE_SETLABEL_TIMER)
288 {
289 KillTimer(pConsole->hConsoleWnd, CONSOLE_SETLABEL_TIMER);
290 if (pSettings->consoleHidden) ShowWindow(pConsole->hConsoleWnd, SW_HIDE);
291 }
292
293 return 0;
294 }
295 break;
296*/
297 //====================
298
299 case BB_RECONFIGURE:
300 case WM_DISPLAYCHANGE:
301 {
302 pConsole->UpdatePosition();
303 }
304 break;
305
306 case WM_SETTINGCHANGE:
307 {
308 // Update the console's position (and maybe also dimensions) if the work area changes...
309 // (e.g. if the Explorer taskbar is moved to another screen edge)
310 if (wParam == SPI_SETWORKAREA) pConsole->UpdatePosition();
311 return 0;
312 }
313
314 //====================
315
316 case BB_TOGGLECONSOLE:
317 {
318 if (pSettings->consoleHidden)
319 {
320 // Show window and force update...
321 pSettings->consoleHidden = false;
322 ShowWindow(pConsole->hConsoleWnd, SW_SHOWNOACTIVATE);
323 pConsole->UpdateConsoleWindow();
324 }
325 else
326 {
327 // Hide window...
328 pSettings->consoleHidden = true;
329 ShowWindow(pConsole->hConsoleWnd, SW_HIDE);
330 }
331
333
334 WriteBool(pSettings->xobrcFile, "xoblite.console.hidden:", pSettings->consoleHidden);
335 }
336 break;
337
338 //====================
339/*
340 case WM_WINDOWPOSCHANGING:
341 {
342 // ##### FOR SOME REASON THIS WILL CRASH THE SHELL...? #####
343 if (pDesktop) SetWindowPos(pConsole->hConsoleWnd, pDesktop->hDesktopWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOOWNERZORDER);
344 return 0;
345 }
346*/
347 //====================
348
349 case WM_GETMINMAXINFO:
350 {
351 MINMAXINFO *mmi = (MINMAXINFO*)lParam;
352 mmi->ptMaxSize.y = pConsole->ConsoleHeight;
353 return 0;
354 }
355
356 //====================
357
358 case WM_CLOSE:
359 return 0;
360
361 //====================
362
363 case WM_MOUSEACTIVATE:
364 return MA_NOACTIVATE;
365
366// case WM_ACTIVATE:
367// if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) SetActiveWindow(hwnd);
368// return 0;
369
370 //====================
371
372 case WM_NCHITTEST:
373 {
374 if ((GetAsyncKeyState(VK_CONTROL) & 0x8000)) return HTCAPTION;
375 else return HTCLIENT;
376 }
377 break;
378
379 //====================
380
381 case WM_LBUTTONDBLCLK:
382 {
383 // Check which message was clicked...
384 POINT pt;
385 pt.x = LOWORD(lParam);
386 pt.y = HIWORD(lParam);
387
388 int i = 0;
389 for (i; i < (int)pConsole->messageList.size(); i++)
390 {
391 if (PtInRect(&pConsole->messageList[i]->r, pt)) break;
392 }
393 if (i == (int)pConsole->messageList.size()) break; // No message clicked
394
395 //====================
396
397 if (strlen(pConsole->messageList[i]->url) > 0) // Message including a clickable URL...
398 {
399 BBExecute(GetDesktopWindow(), NULL, pConsole->messageList[i]->url, NULL, NULL, SW_SHOWNORMAL, true);
400 }
401 else
402 {
403 // Relay all mouse actions and drag'n'dropped files to the desktop...
404// SendMessage(pDesktop->hDesktopWnd, message, wParam, lParam);
405 }
406 }
407 break;
408
409
410 //====================
411
412 case WM_LBUTTONDOWN:
413 case WM_LBUTTONUP:
414 case WM_RBUTTONDOWN:
415 case WM_RBUTTONUP:
416 case WM_MBUTTONDOWN:
417 case WM_MBUTTONUP:
418 case WM_XBUTTONDOWN:
419 case WM_XBUTTONUP:
420 case WM_MOUSEWHEEL:
421 case WM_MOUSEHWHEEL:
422 case WM_DROPFILES:
423 {
424 if (message == WM_LBUTTONUP)
425 {
426 POINT pt;
427 pt.x = LOWORD(lParam);
428 pt.y = HIWORD(lParam);
429
430 // Did the user click the maximize/restore button?
431 if (PtInRect(&pConsole->consoleZoomButtonRect, pt))
432 {
433 pConsole->ToggleMaximized();
434 break;
435 }
436 }
437
438 // If not, we relay all mouse actions and drag'n'dropped files to the desktop...
439 pDesktop->MouseAndDropHandler(pDesktop->hDesktopWnd, message, wParam, lParam);
440 }
441 break;
442
443 //====================
444
445 default:
446 return DefWindowProc(hwnd,message,wParam,lParam);
447
448 //====================
449 }
450 return 0;
451}
void WriteBool(LPCSTR fp, LPCSTR keyword, bool value)
Definition BBApi.cpp:3131
Desktop * pDesktop
Definition Blackbox.cpp:37
LPSTR Tokenize(LPCSTR string, LPSTR buf, LPSTR delims)
Definition BBApi.cpp:273
bool IsInString(LPCSTR inputString, LPCSTR searchString)
Definition BBApi.cpp:2519
HINSTANCE BBExecute(HWND Owner, LPCSTR szOperation, LPCSTR szCommand, LPCSTR szArgs, LPCSTR szDirectory, int nShowCmd, bool noErrorMsgs)
Definition BBApi.cpp:1648
Settings * pSettings
Definition Blackbox.cpp:46
#define BB_TOGGLECONSOLE
Definition BBApi.h:173
#define BB_CONSOLEMESSAGE
Definition BBApi.h:165
#define CONSOLE_SEPARATOR
Definition BBApi.h:304
#define CONSOLE_REGULAR_MESSAGE
Definition BBApi.h:297
#define BB_RECONFIGURE
Definition BBApi.h:147
#define CONSOLE_SHELL_MESSAGE
Definition BBApi.h:301
#define CONSOLE_ERROR_MESSAGE
Definition BBApi.h:300
#define MAX_LINE_LENGTH
Definition BBApi.h:64
#define CONSOLE_INFORMATION_MESSAGE
Definition BBApi.h:298
#define CONSOLE_WARNING_MESSAGE
Definition BBApi.h:299
Console * pConsole
Definition Blackbox.cpp:36
void PlaySoundFX(int sound)
Definition Sounds.cpp:40
@ SFX_TOGGLE_ELEMENT
Definition Sounds.h:48
Definition Console.h:43
char msg[350]
Definition Console.h:45
int type
Definition Console.h:44
char url[256]
Definition Console.h:47
HICON icon
Definition Console.h:46

Variable Documentation

◆ szConsoleName

const char szConsoleName[] = "BBConsole"

◆ pConsole

Console* pConsole
extern

◆ pSettings

Settings* pSettings
extern

◆ pBImage

BImage* pBImage
extern

◆ pToolbar

Toolbar* pToolbar
extern

◆ pDesktop

Desktop* pDesktop
extern

◆ consoleMessageSubscription

int consoleMessageSubscription[] = { BB_TOGGLECONSOLE, BB_CONSOLEMESSAGE, BB_RECONFIGURE, 0 }