Advertisement
Recluse

Tester project.

Jun 24th, 2012
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <string>
  3. #include "Answers.h"
  4. #include <vector>
  5. #include <tchar.h>
  6. #include <sstream>
  7.  
  8. #define IDC_CHECKBOX1 1500 // *** these are your control ID's but we will have to assign them to the checkbox windows below... ***
  9. #define IDC_CHECKBOX2 1501
  10. #define IDC_CHECKBOX3 1502
  11. #define IDC_NEXTBOX 1503
  12. #define IDC_PREVBOX 1504
  13.  
  14. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  15.  
  16. char szClassName[ ] = "Tester";
  17. HINSTANCE hInst;
  18. HWND hCheckBox1, hCheckBox2, hCheckBox3, hNextBox, hPrevBox;
  19. vector<string> list;
  20. stringstream sstr;
  21. string str[1024];
  22. int Counter=0,Total=1,Score,CheckScore=0,xtemp=1,ytemp=0,NumCounter=0,NumArray[256];
  23.  
  24. int WINAPI WinMain (HINSTANCE hThisInstance,
  25.                     HINSTANCE hPrevInstance,
  26.                     LPSTR lpszArgument,
  27.                     int nCmdShow)
  28. {
  29.  
  30.  
  31.     Answers test;
  32.     test.getString(list);
  33.  
  34.     for(int i=0; i!=list.size(); i++)
  35.     {
  36.         if(list[i]!=""&&list[i]!="@")
  37.         {
  38.             str[xtemp]+=' ';
  39.             str[xtemp]+=list[i];
  40.         }
  41.         else if(list[i]=="")
  42.         {
  43.             if(ytemp<3)
  44.             {
  45.                 ytemp++;
  46.             }
  47.             else
  48.             {
  49.                 ytemp=1;
  50.             }
  51.             if(xtemp%4==0&&(xtemp+2)%4!=0)
  52.             {
  53.                 Total++;
  54.                 ytemp--;
  55.             }
  56.             xtemp++;
  57.         }
  58.         else if(list[i]=="@")//true answer
  59.         {
  60.             NumArray[NumCounter]=ytemp;
  61.             NumCounter++;
  62.         }
  63.     }
  64.  
  65.     hInst = hThisInstance;
  66.     HWND hwnd;
  67.     MSG messages;
  68.     WNDCLASSEX wincl;
  69.  
  70.     wincl.hInstance = hThisInstance;
  71.     wincl.lpszClassName = szClassName;
  72.     wincl.lpfnWndProc = WindowProcedure;
  73.     wincl.style = CS_DBLCLKS;
  74.     wincl.cbSize = sizeof (WNDCLASSEX);
  75.  
  76.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  77.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  78.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  79.     wincl.lpszMenuName = NULL;
  80.     wincl.cbClsExtra = 0;
  81.     wincl.cbWndExtra = 0;
  82.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  83.  
  84.     if (!RegisterClassEx (&wincl))
  85.         return 0;
  86.  
  87.     hwnd = CreateWindowEx (
  88.                0,
  89.                szClassName,
  90.                "Tester",
  91.                WS_OVERLAPPEDWINDOW,
  92.                CW_USEDEFAULT,
  93.                CW_USEDEFAULT,
  94.                350,
  95.                350,
  96.                HWND_DESKTOP,
  97.                NULL,
  98.                hThisInstance,
  99.                NULL
  100.            );
  101.  
  102.     ShowWindow (hwnd, nCmdShow);
  103.  
  104.     while (GetMessage (&messages, NULL, 0, 0))
  105.     {
  106.         TranslateMessage(&messages);
  107.         DispatchMessage(&messages);
  108.     }
  109.  
  110.     return messages.wParam;
  111. }
  112.  
  113.  
  114. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  115. {
  116.  
  117.     const char *z = str[1+(4*Counter)].c_str(),*y = str[2+(4*Counter)].c_str(),*x = str[3+(4*Counter)].c_str(),*w = str[4+(4*Counter)].c_str();
  118.     switch (message)
  119.     {
  120.     case WM_CREATE :
  121.         hCheckBox1 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),0,
  122.                                      WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
  123.                                      0, 60, 16, 16,
  124.                                      hwnd, (HMENU) IDC_CHECKBOX1,
  125.                                      hInst, NULL) ;
  126.  
  127.         hCheckBox2 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),0,
  128.                                      WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
  129.                                      0, 100, 16, 16,
  130.                                      hwnd, (HMENU) IDC_CHECKBOX2,
  131.                                      hInst, NULL);
  132.  
  133.         hCheckBox3 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),0,
  134.                                      WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
  135.                                      0, 140, 16, 16,
  136.                                      hwnd, (HMENU) IDC_CHECKBOX3,
  137.                                      hInst, NULL);
  138.  
  139.         hNextBox = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),"Next",
  140.                                    WS_CHILD | WS_VISIBLE |BS_PUSHLIKE | BS_AUTORADIOBUTTON,
  141.                                    100, 180, 50, 25,
  142.                                    hwnd, (HMENU) IDC_NEXTBOX,
  143.                                    hInst, NULL) ;
  144.  
  145.         hPrevBox = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),"Prev",
  146.                                    WS_CHILD | WS_VISIBLE | BS_PUSHLIKE | BS_AUTORADIOBUTTON,
  147.                                    40, 180, 50, 25,
  148.                                    hwnd, (HMENU) IDC_PREVBOX,
  149.                                    hInst, NULL);
  150.         break;
  151.     case WM_PAINT:
  152.         PAINTSTRUCT ps;
  153.         RECT lpRect;
  154.         lpRect.top=0;
  155.         lpRect.left=17;
  156.         lpRect.bottom=50;
  157.         lpRect.right=300;
  158.         HDC hdc;
  159.         hdc = BeginPaint(hwnd, &ps);
  160.         DrawText(hdc,z,_tcslen(z),&lpRect,DT_LEFT|DT_WORDBREAK|DT_NOPREFIX);
  161.         TextOut(hdc,
  162.                 17, 60,
  163.                 y, _tcslen(y));
  164.         TextOut(hdc,
  165.                 17, 100,
  166.                 x, _tcslen(x));
  167.         TextOut(hdc,
  168.                 17, 140,
  169.                 w, _tcslen(w));
  170.         EndPaint(hwnd, &ps);
  171.         break;
  172.     case WM_COMMAND:
  173.     {
  174.         switch(LOWORD(wParam)) // *** Tells us which control ID sent a message ***
  175.         {
  176.         case IDC_CHECKBOX1: // *** user clicked box 1 ***
  177.         {
  178.             if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1),BM_GETCHECK,0,0) == BST_CHECKED)
  179.             {
  180.                 CheckScore=1;
  181.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
  182.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
  183.             }
  184.             else
  185.             {
  186.                 CheckScore=0;
  187.             }
  188.         }
  189.         break;
  190.         case IDC_CHECKBOX2: // *** user clicked box 2 ***
  191.         {
  192.             if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2),BM_GETCHECK,0,0) == BST_CHECKED)
  193.             {
  194.                 CheckScore=2;
  195.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
  196.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
  197.             }
  198.             else
  199.             {
  200.                 CheckScore=0;
  201.             }
  202.         }
  203.         break;
  204.         case IDC_CHECKBOX3: // *** user clicked box 3 ***
  205.         {
  206.             if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3),BM_GETCHECK,0,0) == BST_CHECKED)
  207.             {
  208.                 CheckScore=3;
  209.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
  210.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
  211.             }
  212.             else
  213.             {
  214.                 CheckScore=0;
  215.             }
  216.         }
  217.         break;
  218.         case IDC_NEXTBOX: // *** user clicked next button ***
  219.         {
  220.             if(SendMessage(GetDlgItem(hwnd,IDC_NEXTBOX),BM_GETCHECK,0,0) == BST_CHECKED)
  221.             {
  222.                 if(Counter!=Total&&CheckScore!=0)
  223.                 {
  224.                     if(NumArray[Counter]==CheckScore)
  225.                     {
  226.                         Score++;
  227.                     }
  228.                     if((Counter+1)==Total)
  229.                     {
  230.                         sstr<<"Your Score is:\n"<<Score<<" out of "<<Total<<"\n\nIf you would like to retry press the Prev button\nYour score will be reset";
  231.                         MessageBox(hwnd,sstr.str().c_str(),"Score",0);
  232.                         sstr.str("");
  233.                         ShowWindow(hNextBox,SW_HIDE);
  234.                         ShowWindow(hCheckBox1,SW_HIDE);
  235.                         ShowWindow(hCheckBox2,SW_HIDE);
  236.                         ShowWindow(hCheckBox3,SW_HIDE);
  237.                     }
  238.                     Counter++;
  239.                     InvalidateRect(hwnd,0,true);
  240.                     SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
  241.                     SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
  242.                     SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
  243.                 }
  244.                 else
  245.                 {
  246.                     MessageBox(hwnd,"You forgot to check one of the boxes","Oops",0);
  247.                 }
  248.                 CheckScore=0;
  249.             }
  250.         }
  251.         break;
  252.         case IDC_PREVBOX: // *** user clicked next button ***
  253.         {
  254.             if(SendMessage(GetDlgItem(hwnd,IDC_PREVBOX),BM_GETCHECK,0,0) == BST_CHECKED)
  255.             {
  256.                 if(Counter!=0)
  257.                 {
  258.                     Counter--;
  259.                     InvalidateRect(hwnd,0,true);
  260.                     if(Score!=0)
  261.                     {
  262.                         Score--;
  263.                     }
  264.                 }
  265.                 if((Counter)!=Total)
  266.                 {
  267.                     ShowWindow(hNextBox,SW_SHOW);
  268.                     ShowWindow(hCheckBox1,SW_SHOW);
  269.                     ShowWindow(hCheckBox2,SW_SHOW);
  270.                     ShowWindow(hCheckBox3,SW_SHOW);
  271.                 }
  272.                 if((Counter+1)==Total)
  273.                 {
  274.                     Counter=0;
  275.                     Score=0;
  276.                 }
  277.  
  278.                 CheckScore=0;
  279.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
  280.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
  281.                 SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
  282.             }
  283.         }
  284.         break;
  285.         }
  286.     }
  287.     break;
  288.     case WM_DESTROY:
  289.         PostQuitMessage (0);
  290.         break;
  291.     default:
  292.         return DefWindowProc (hwnd, message, wParam, lParam);
  293.     }
  294.     return 0;
  295. }
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303. /*************************************************************
  304. Answers.h file
  305. *************************************************************/
  306.  
  307. #ifndef ANSWERS_H
  308. #define ANSWERS_H
  309. #include <string>
  310. #include <iostream>
  311. #include <fstream>
  312. #include <vector>
  313. #include <windows.h>
  314.  
  315.  
  316. using namespace std;
  317.  
  318. class Answers
  319. {
  320.     public:
  321.         Answers();
  322.         void getString(vector<string>& list);
  323.         //int getChar();
  324.         //int getLine();
  325.     protected:
  326.     private:
  327. };
  328.  
  329. #endif // ANSWERS_H
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. /*************************************************************
  338. Answers.cpp file
  339. *************************************************************/
  340.  
  341. #include "Answers.h"
  342. #include <fstream>
  343. #include <iostream>
  344. #include <string>
  345. #include <vector>
  346. #include <windows.h>
  347.  
  348. using namespace std;
  349.  
  350. Answers::Answers()
  351. {
  352.     //ctor
  353. }
  354.  
  355. void Answers::getString(vector<string>& list)
  356. {
  357.     ifstream fi;
  358.     bool tf=false;
  359.     string str,str2;
  360.     while(tf==false)
  361.     {
  362.         cout<<"What test would you like to do?\n";
  363.         cin>>str2;
  364.         str2+=".txt";
  365.         cout<<str2<<endl;
  366.         fi.open(str2.c_str());
  367.         if(fi.good())
  368.         {
  369.             while(getline(fi,str))
  370.             {
  371.                 list.push_back(str);
  372.             }
  373.             tf=true;
  374.             fi.close();
  375.             FreeConsole();
  376.         }
  377.         else
  378.         {
  379.             cout<<"\nThat file does not exist please try again.\nDo not include the file type\n";
  380.             str2="";
  381.             fi.close();
  382.         }
  383.     }
  384.  
  385. }
  386.  
  387. /*int Answers::getChar()
  388. {
  389.     int charCount = 0;
  390.     fi.open("test.txt");
  391.     if(fi.good())
  392.     {
  393.         fi.seekg(0,ios::beg);
  394.         fi.seekg(0,ios::end);
  395.         charCount = fi.tellg();
  396.     }
  397.     fi.close();
  398.     return charCount;
  399. }
  400.  
  401. int Answers::getLine()
  402. {
  403.     int lineCount = 0;
  404.     string str;
  405.     fi.open("test.txt");
  406.     if(fi.good())
  407.     {
  408.         while(getline(fi,str))
  409.         {
  410.             lineCount++;
  411.         }
  412.     }
  413.     fi.close();
  414.     return lineCount;
  415. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement