Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MainTestSystem.h"
- using namespace pugi;
- TestSystem::TestSystem(HWND hWindow, HWND hText, HWND* hRButtons)
- {
- RECT ClientRect;
- this->hStaticWin = hText;
- this->hButtonsWin = hRButtons;
- GetClientRect(hWindow, &ClientRect);
- this->WindowHeight = ClientRect.bottom;
- this->WindowWidth = ClientRect.right;
- hThisWindow = hWindow;
- iPageIterator = NULL;
- wchar_t szThisPath[1024];
- WIN32_FIND_DATA fData = {0};
- GetCurrentDirectory(sizeof(szThisPath), szThisPath);
- HANDLE hCurrentFile = FindFirstFile(szThisPath, &fData);
- if(hCurrentFile != INVALID_HANDLE_VALUE)
- {
- do
- {
- if(!wcsstr(fData.cFileName, L"page"))
- {
- Document = fData.cFileName;
- break;
- }
- } while (FindNextFile(hCurrentFile, &fData));
- }
- }
- void TestSystem::ReadXMLFile(std::wstring TestDoc)
- {
- xml_document testDoc;
- testDoc.load_file(as_utf8(TestDoc).c_str());
- if(TestDoc.empty())
- {
- throw TestSystem::TestSystemExceptions::Invalid_XML_File;
- }
- for(xml_node branch = testDoc.child("page"); branch; branch = branch.next_sibling())
- {
- if(branch.empty())
- {
- throw TestSystem::TestSystemExceptions::Invalid_XML_Value;
- }
- std::vector<std::wstring> listOfAnswers;
- if((branch.child("image") != NULL || branch.child("question") != NULL) && !(branch.child("image") != NULL && branch.child("question") != NULL))
- {
- char* XMLValue = branch.child("image") != NULL ? "image" : "question";
- std::pair<const char*, std::wstring> valuePair(XMLValue, as_wide(branch.child_value(XMLValue)));
- this->QuestionType.push_back(valuePair);
- }
- else
- {
- throw TestSystem::TestSystemExceptions::Image_Or_Question_Not_Exists;
- }
- if(branch.child("answer_list") != NULL)
- {
- if (!branch.child("answer_list").empty())
- {
- for(xml_node i = branch.child("answer_list").child("answer"); i; i = i.next_sibling())
- {
- listOfAnswers.push_back(as_wide(i.child_value("name")));
- }
- }
- else
- {
- throw TestSystem::TestSystemExceptions::Answers_Nos_Exists;
- }
- }
- this->Answer.push_back(listOfAnswers);
- }
- }
- void TestSystem::DisplayPage(HWND hWnd)
- {
- PAINTSTRUCT PaintStruct;
- HDC hDC, hCompatibleDC;
- HANDLE hBitmap, hOldBitmap;
- BITMAP ImageBM;
- if(!strcmp(QuestionType[iPageIterator].first, "image"))
- {
- hDC = BeginPaint(hWnd, &PaintStruct);
- hBitmap = LoadImage(0, QuestionType[iPageIterator].second.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- GetObject(hBitmap, sizeof(BITMAP), &ImageBM);
- hCompatibleDC = CreateCompatibleDC(hDC);
- hOldBitmap = SelectObject(hCompatibleDC, hBitmap);
- if (ImageBM.bmWidth > this->WindowWidth || ImageBM.bmHeight > (double)this->WindowHeight * 0.6)
- {
- throw TestSystem::TestSystemExceptions::Image_Is_So_Big;
- }
- int iImagePosX = (int)floor((double)(this->WindowWidth - ImageBM.bmWidth) / 2);
- int iImagePosY = (int)floor((double)(this->WindowHeight * 0.6 - ImageBM.bmHeight) / 2);
- StretchBlt(hDC, iImagePosX, iImagePosY, iImagePosX + ImageBM.bmWidth, iImagePosY + ImageBM.bmHeight, hCompatibleDC, 0, 0, ImageBM.bmWidth, ImageBM.bmHeight, SRCCOPY);
- SelectObject(hCompatibleDC, hOldBitmap);
- DeleteObject(hBitmap);
- DeleteDC(hCompatibleDC);
- EndPaint(hWnd, &PaintStruct);
- }
- else if(!strcmp(QuestionType[iPageIterator].first, "question"))
- {
- SetWindowText(this->hStaticWin, QuestionType[iPageIterator].second.c_str());
- }
- else
- {
- throw Invalid_XML_Value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment