程序运行在Windows平台下。非阻塞控制台编程例子。、
#include <Windows.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QTimer>
#include <iostream>
#include <conio.h>
#include <string>
#include <QtCore/QTimer>
#include "../GVController/uiinf.h"
#ifdef _DEBUG
#pragma comment(lib, "..\\x64\\Debug\\xxController.lib")
#else
#pragma comment(lib, "..\\x64\\Release\\xxController.lib")
#endif
void clearInputBuffer()
{
HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
FlushConsoleInputBuffer(input_handle);
}
unsigned short peek_keypress()
{
HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
DWORD events = 0;
INPUT_RECORD input_record;
DWORD input_size = 1;
BOOL peeked = PeekConsoleInput(input_handle, &input_record, input_size, &events);
if (!peeked)
return 0;
DWORD n;
if (peeked && GetNumberOfConsoleInputEvents(input_handle, &n))
{
clearInputBuffer();
if (!input_record.Event.KeyEvent.bKeyDown)
return input_record.Event.KeyEvent.wVirtualKeyCode;
}
return 0;
}
int PrintDicomROIMenu()
{
std::wstring retString;
int retCode = -1;
while (true)
{
retString.clear();
retCode = -1;
std::cout << std::endl;
std::cout << "1: LoadDicomDir" << std::endl;
std::cout << "2: LoadNiffi" << std::endl;
std::cout << "3: test null file path" << std::endl;
std::cout << "H: Back Root Menu" << std::endl;
int c = 0;
while (!(c = peek_keypress()))
QCoreApplication::instance()->processEvents();
if (c == 'H')
return 0;
if (c == '2')
{
if (true == controllerIns()->parseNiffiFile(L"D:\\VTK_DTA\\XueBaoLin.inffi.gz", NULL, retCode, retString))
std::cout << "parse D:\\VTK_DTA\\XueBaoLin.inffi.gz ret" << std::endl;
else
std::cout << "no handler" << std::endl;
continue;
}
if (c == '3')
{
if (controllerIns()->parseNiffiFile(L"", NULL, retCode, retString))
{
if (retCode != SUCCESS)
{
std::cout << "ret error:" << std::endl;
std::wcout << retString.c_str() << std::endl;
}
}
continue;
}
}
return 0;
}
int PrintTotalMenu()
{
while (true)
{
std::cout << std::endl;
std::cout << "1: User Mananger" << std::endl;
std::cout << "2: Patient Manager" << std::endl;
std::cout << "3: DICOM ROI" << std::endl;
std::cout << "4: Register" << std::endl;
std::cout << "q: Quit App" << std::endl;
int c = 0;
while (true)
{
c = peek_keypress();
if (c != 0)
break;
QCoreApplication::instance()->processEvents();
};
if (c == '3')
PrintDicomROIMenu();
if (c == 'Q')
return 1;
}
return 0;
}
int main(int argc, char* argv[])
{
std::wcout.imbue(std::locale("chs")); //支持输出中文
clearInputBuffer();
QCoreApplication a(argc, argv);
if (!controllerIns()->initialize())
{
std::cout << "initilize controller failde" << std::endl;
return -1;
}
QTimer* timer = new QTimer();
timer->setInterval(50);
timer->start();
QObject::connect(timer, &QTimer::timeout, [=] {
controllerIns()->on50Ms();
});
while (true)
{
if (1 == PrintTotalMenu())
{
releaseController();
a.processEvents();
delete timer;
return 0;
}
}
return a.exec();
}
|