Pushok

tester first day

Jun 15th, 2011
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 KB | None | 0 0
  1. #include "MainTestSystem.h"
  2.  
  3. using namespace pugi;
  4.  
  5. TestSystem::TestSystem(HWND hWindow, HWND hText, HWND* hRButtons)
  6. {
  7.     RECT ClientRect;
  8.  
  9.     this->hStaticWin = hText;
  10.     this->hButtonsWin = hRButtons;
  11.  
  12.     GetClientRect(hWindow, &ClientRect);
  13.     this->WindowHeight = ClientRect.bottom;
  14.     this->WindowWidth = ClientRect.right;
  15.  
  16.     hThisWindow = hWindow;
  17.     iPageIterator = NULL;
  18.  
  19.     wchar_t szThisPath[1024];
  20.     WIN32_FIND_DATA fData = {0};
  21.     GetCurrentDirectory(sizeof(szThisPath), szThisPath);
  22.  
  23.     HANDLE hCurrentFile = FindFirstFile(szThisPath, &fData);
  24.  
  25.     if(hCurrentFile != INVALID_HANDLE_VALUE)
  26.     {
  27.         do
  28.         {
  29.             if(!wcsstr(fData.cFileName, L"page"))
  30.             {
  31.                 Document = fData.cFileName;
  32.                 break;
  33.             }
  34.  
  35.         } while (FindNextFile(hCurrentFile, &fData));
  36.     }
  37. }
  38.  
  39. void TestSystem::ReadXMLFile(std::wstring TestDoc)
  40. {
  41.     xml_document testDoc;
  42.  
  43.     testDoc.load_file(as_utf8(TestDoc).c_str());
  44.  
  45.     if(TestDoc.empty())
  46.     {
  47.         throw TestSystem::TestSystemExceptions::Invalid_XML_File;
  48.     }
  49.  
  50.     for(xml_node branch = testDoc.child("page"); branch; branch = branch.next_sibling())
  51.     {
  52.         if(branch.empty())
  53.         {
  54.             throw TestSystem::TestSystemExceptions::Invalid_XML_Value;
  55.         }
  56.  
  57.         std::vector<std::wstring> listOfAnswers;
  58.  
  59.         if((branch.child("image") != NULL || branch.child("question") != NULL) && !(branch.child("image") != NULL && branch.child("question") != NULL))
  60.         {
  61.             char* XMLValue = branch.child("image") != NULL ? "image" : "question";
  62.  
  63.             std::pair<const char*, std::wstring> valuePair(XMLValue, as_wide(branch.child_value(XMLValue)));
  64.  
  65.             this->QuestionType.push_back(valuePair);
  66.         }
  67.         else
  68.         {
  69.             throw TestSystem::TestSystemExceptions::Image_Or_Question_Not_Exists;
  70.         }
  71.  
  72.         if(branch.child("answer_list") != NULL)
  73.         {
  74.             if (!branch.child("answer_list").empty())
  75.             {
  76.                 for(xml_node i = branch.child("answer_list").child("answer"); i; i = i.next_sibling())
  77.                 {
  78.                     listOfAnswers.push_back(as_wide(i.child_value("name")));
  79.                 }
  80.             }
  81.             else
  82.             {
  83.                 throw TestSystem::TestSystemExceptions::Answers_Nos_Exists;
  84.             }
  85.         }
  86.  
  87.         this->Answer.push_back(listOfAnswers);
  88.     }
  89. }
  90.  
  91. void TestSystem::DisplayPage(HWND hWnd)
  92. {
  93.     PAINTSTRUCT PaintStruct;
  94.     HDC hDC, hCompatibleDC;
  95.     HANDLE hBitmap, hOldBitmap;
  96.     BITMAP ImageBM;
  97.  
  98.     if(!strcmp(QuestionType[iPageIterator].first, "image"))
  99.     {
  100.         hDC = BeginPaint(hWnd, &PaintStruct);
  101.         hBitmap = LoadImage(0, QuestionType[iPageIterator].second.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  102.         GetObject(hBitmap, sizeof(BITMAP), &ImageBM);
  103.  
  104.         hCompatibleDC = CreateCompatibleDC(hDC);
  105.         hOldBitmap = SelectObject(hCompatibleDC, hBitmap);
  106.        
  107.         if (ImageBM.bmWidth > this->WindowWidth || ImageBM.bmHeight > (double)this->WindowHeight * 0.6)
  108.         {
  109.             throw TestSystem::TestSystemExceptions::Image_Is_So_Big;
  110.         }
  111.  
  112.         int iImagePosX = (int)floor((double)(this->WindowWidth - ImageBM.bmWidth) / 2);
  113.         int iImagePosY = (int)floor((double)(this->WindowHeight * 0.6 - ImageBM.bmHeight) / 2);
  114.  
  115.         StretchBlt(hDC, iImagePosX, iImagePosY, iImagePosX + ImageBM.bmWidth, iImagePosY + ImageBM.bmHeight, hCompatibleDC, 0, 0, ImageBM.bmWidth, ImageBM.bmHeight, SRCCOPY);
  116.  
  117.         SelectObject(hCompatibleDC, hOldBitmap);
  118.         DeleteObject(hBitmap);
  119.  
  120.         DeleteDC(hCompatibleDC);
  121.         EndPaint(hWnd, &PaintStruct);
  122.     }
  123.     else if(!strcmp(QuestionType[iPageIterator].first, "question"))
  124.     {
  125.         SetWindowText(this->hStaticWin, QuestionType[iPageIterator].second.c_str());
  126.     }
  127.     else
  128.     {
  129.         throw Invalid_XML_Value;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment