| 429 | } |
| 430 | |
| 431 | int wmain(int argc, const WCHAR* args[]) |
| 432 | { |
| 433 | boost::system::error_code ec; |
| 434 | boost::asio::io_service ioctx; |
| 435 | boost::asio::serial_port serialPort(ioctx); |
| 436 | hInstance = GetModuleHandle(nullptr); |
| 437 | |
| 438 | DWORD consoleMode = 0; |
| 439 | auto conin = GetStdHandle(STD_INPUT_HANDLE); |
| 440 | auto conout = GetStdHandle(STD_OUTPUT_HANDLE); |
| 441 | GetConsoleMode(conin, &consoleMode); |
| 442 | consoleMode |= ENABLE_MOUSE_INPUT; |
| 443 | consoleMode &= ~ENABLE_ECHO_INPUT; |
| 444 | consoleMode &= ~ENABLE_PROCESSED_INPUT; |
| 445 | consoleMode &= ~ENABLE_LINE_INPUT; |
| 446 | consoleMode |= ENABLE_QUICK_EDIT_MODE; |
| 447 | consoleMode |= ENABLE_WINDOW_INPUT; |
| 448 | consoleMode |= ENABLE_VIRTUAL_TERMINAL_INPUT; |
| 449 | SetConsoleMode(conin, consoleMode); |
| 450 | |
| 451 | GetConsoleMode(conout, &consoleMode); |
| 452 | SetConsoleMode(conout, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT); |
| 453 | |
| 454 | while (true) |
| 455 | { |
| 456 | auto hWndParent = ::GetForegroundWindow(); |
| 457 | if (hWndParent == nullptr) |
| 458 | hWndParent = GetConsoleWindow(); |
| 459 | if (DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETTING_DIALOG), hWndParent, SettingFunc, 1) == IDOK) |
| 460 | { |
| 461 | ioctx.restart(); |
| 462 | auto cfg = ReadSerialConfig(); |
| 463 | auto portName = std::string("COM") + std::to_string(cfg.Serial); |
| 464 | if (serialPort.open(portName, ec)) |
| 465 | { |
| 466 | std::cerr << "\033[31m" << "can not open " << portName << "\033[0m" <<std::endl; |
| 467 | std::cerr << "\033[31m" << "error : " << ec.message() << "\033[0m" << std::endl; |
| 468 | continue; |
| 469 | } |
| 470 | if (InitializeSerialPort(serialPort, cfg, ec)) |
| 471 | { |
| 472 | std::cerr << "\033[31m" << "can not initialize " << portName << "\033[0m" << std::endl; |
| 473 | std::cerr << "\033[31m" << "error : " << ec.message() << "\033[0m" << std::endl; |
| 474 | continue; |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | // 根据用户选择的编码格式设置控制台 |
| 479 | if (cfg.EncodingFormat == 0) // UTF-8 |
| 480 | { |
| 481 | SetConsoleOutputCP(CP_UTF8); |
| 482 | SetConsoleCP(CP_UTF8); |
| 483 | } |
| 484 | else // GBK |
| 485 | { |
| 486 | SetConsoleOutputCP(936); // 936是GBK的代码页 |
| 487 | SetConsoleCP(936); |
| 488 | } |
nothing calls this directly
no test coverage detected