|
| 1 | +// TODO: |
| 2 | +// - show context menu on tray icon (has 'Show Log', 'Reload' and 'Exit') |
| 3 | +// - click handlers for blocks |
| 4 | +// - bug with changing font of block also changing defaultBlock font *sometimes*...?, debug by logging fontrefs on render |
| 5 | + |
1 | 6 | // Require Windows 10 |
2 | 7 | #define WINVER 0x0A00 |
3 | 8 | #define _WIN32_WINNT 0x0A00 |
|
7 | 12 | #include <stdlib.h> |
8 | 13 | #include <stdbool.h> |
9 | 14 | #include <assert.h> |
| 15 | +#include <io.h> |
10 | 16 |
|
11 | 17 | #include <quickjs/quickjs.h> |
12 | 18 | #include <quickjs/quickjs-libc.h> |
@@ -435,7 +441,7 @@ char *runProcess(char *cmd) |
435 | 441 | .hStdError = stdoutW, |
436 | 442 | .dwFlags = STARTF_USESTDHANDLES, |
437 | 443 | }; |
438 | | - if (!CreateProcessA(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { |
| 444 | + if (!CreateProcessA(NULL, cmd, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { |
439 | 445 | CloseHandle(stdoutR); |
440 | 446 | CloseHandle(stdoutW); |
441 | 447 | return NULL; |
@@ -517,6 +523,20 @@ int CALLBACK WinMain(HINSTANCE inst, HINSTANCE prevInst, LPSTR cmdLine, int cmdS |
517 | 523 | { |
518 | 524 | hInst = inst; |
519 | 525 |
|
| 526 | + // Create console and redirect output |
| 527 | + assert(AllocConsole()); |
| 528 | +#ifdef DEBUG |
| 529 | + assert(freopen("CONOUT$", "w", stdout)); |
| 530 | + assert(freopen("CONOUT$", "w", stderr)); |
| 531 | +#else |
| 532 | + ShowWindow(GetConsoleWindow(), 0); |
| 533 | + assert(freopen("wblocks.log", "w", stdout)); |
| 534 | + assert(freopen("NUL", "w", stderr)); |
| 535 | + assert(!_dup2(_fileno(stdout), _fileno(stderr))); |
| 536 | +#endif |
| 537 | + setvbuf(stdout, NULL, _IONBF, 0); |
| 538 | + setvbuf(stderr, NULL, _IONBF, 0); |
| 539 | + |
520 | 540 | // Load default font |
521 | 541 | defaultBlock.font = xmalloc(sizeof(fontref_t)); |
522 | 542 | defaultBlock.font->handle = CreateFont(22, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, "Courier New"); |
|
0 commit comments