Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include "Answers.h"
- #include <vector>
- #include <tchar.h>
- #include <sstream>
- #define IDC_CHECKBOX1 1500 // *** these are your control ID's but we will have to assign them to the checkbox windows below... ***
- #define IDC_CHECKBOX2 1501
- #define IDC_CHECKBOX3 1502
- #define IDC_NEXTBOX 1503
- #define IDC_PREVBOX 1504
- LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
- char szClassName[ ] = "Tester";
- HINSTANCE hInst;
- HWND hCheckBox1, hCheckBox2, hCheckBox3, hNextBox, hPrevBox;
- vector<string> list;
- stringstream sstr;
- string str[1024];
- int Counter=0,Total=1,Score,CheckScore=0,xtemp=1,ytemp=0,NumCounter=0,NumArray[256];
- int WINAPI WinMain (HINSTANCE hThisInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszArgument,
- int nCmdShow)
- {
- Answers test;
- test.getString(list);
- for(int i=0; i!=list.size(); i++)
- {
- if(list[i]!=""&&list[i]!="@")
- {
- str[xtemp]+=' ';
- str[xtemp]+=list[i];
- }
- else if(list[i]=="")
- {
- if(ytemp<3)
- {
- ytemp++;
- }
- else
- {
- ytemp=1;
- }
- if(xtemp%4==0&&(xtemp+2)%4!=0)
- {
- Total++;
- ytemp--;
- }
- xtemp++;
- }
- else if(list[i]=="@")//true answer
- {
- NumArray[NumCounter]=ytemp;
- NumCounter++;
- }
- }
- hInst = hThisInstance;
- HWND hwnd;
- MSG messages;
- WNDCLASSEX wincl;
- wincl.hInstance = hThisInstance;
- wincl.lpszClassName = szClassName;
- wincl.lpfnWndProc = WindowProcedure;
- wincl.style = CS_DBLCLKS;
- wincl.cbSize = sizeof (WNDCLASSEX);
- wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
- wincl.lpszMenuName = NULL;
- wincl.cbClsExtra = 0;
- wincl.cbWndExtra = 0;
- wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
- if (!RegisterClassEx (&wincl))
- return 0;
- hwnd = CreateWindowEx (
- 0,
- szClassName,
- "Tester",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 350,
- 350,
- HWND_DESKTOP,
- NULL,
- hThisInstance,
- NULL
- );
- ShowWindow (hwnd, nCmdShow);
- while (GetMessage (&messages, NULL, 0, 0))
- {
- TranslateMessage(&messages);
- DispatchMessage(&messages);
- }
- return messages.wParam;
- }
- LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- 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();
- switch (message)
- {
- case WM_CREATE :
- hCheckBox1 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),0,
- WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
- 0, 60, 16, 16,
- hwnd, (HMENU) IDC_CHECKBOX1,
- hInst, NULL) ;
- hCheckBox2 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),0,
- WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
- 0, 100, 16, 16,
- hwnd, (HMENU) IDC_CHECKBOX2,
- hInst, NULL);
- hCheckBox3 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),0,
- WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
- 0, 140, 16, 16,
- hwnd, (HMENU) IDC_CHECKBOX3,
- hInst, NULL);
- hNextBox = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),"Next",
- WS_CHILD | WS_VISIBLE |BS_PUSHLIKE | BS_AUTORADIOBUTTON,
- 100, 180, 50, 25,
- hwnd, (HMENU) IDC_NEXTBOX,
- hInst, NULL) ;
- hPrevBox = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),"Prev",
- WS_CHILD | WS_VISIBLE | BS_PUSHLIKE | BS_AUTORADIOBUTTON,
- 40, 180, 50, 25,
- hwnd, (HMENU) IDC_PREVBOX,
- hInst, NULL);
- break;
- case WM_PAINT:
- PAINTSTRUCT ps;
- RECT lpRect;
- lpRect.top=0;
- lpRect.left=17;
- lpRect.bottom=50;
- lpRect.right=300;
- HDC hdc;
- hdc = BeginPaint(hwnd, &ps);
- DrawText(hdc,z,_tcslen(z),&lpRect,DT_LEFT|DT_WORDBREAK|DT_NOPREFIX);
- TextOut(hdc,
- 17, 60,
- y, _tcslen(y));
- TextOut(hdc,
- 17, 100,
- x, _tcslen(x));
- TextOut(hdc,
- 17, 140,
- w, _tcslen(w));
- EndPaint(hwnd, &ps);
- break;
- case WM_COMMAND:
- {
- switch(LOWORD(wParam)) // *** Tells us which control ID sent a message ***
- {
- case IDC_CHECKBOX1: // *** user clicked box 1 ***
- {
- if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1),BM_GETCHECK,0,0) == BST_CHECKED)
- {
- CheckScore=1;
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
- }
- else
- {
- CheckScore=0;
- }
- }
- break;
- case IDC_CHECKBOX2: // *** user clicked box 2 ***
- {
- if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2),BM_GETCHECK,0,0) == BST_CHECKED)
- {
- CheckScore=2;
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
- }
- else
- {
- CheckScore=0;
- }
- }
- break;
- case IDC_CHECKBOX3: // *** user clicked box 3 ***
- {
- if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3),BM_GETCHECK,0,0) == BST_CHECKED)
- {
- CheckScore=3;
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
- }
- else
- {
- CheckScore=0;
- }
- }
- break;
- case IDC_NEXTBOX: // *** user clicked next button ***
- {
- if(SendMessage(GetDlgItem(hwnd,IDC_NEXTBOX),BM_GETCHECK,0,0) == BST_CHECKED)
- {
- if(Counter!=Total&&CheckScore!=0)
- {
- if(NumArray[Counter]==CheckScore)
- {
- Score++;
- }
- if((Counter+1)==Total)
- {
- 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";
- MessageBox(hwnd,sstr.str().c_str(),"Score",0);
- sstr.str("");
- ShowWindow(hNextBox,SW_HIDE);
- ShowWindow(hCheckBox1,SW_HIDE);
- ShowWindow(hCheckBox2,SW_HIDE);
- ShowWindow(hCheckBox3,SW_HIDE);
- }
- Counter++;
- InvalidateRect(hwnd,0,true);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
- }
- else
- {
- MessageBox(hwnd,"You forgot to check one of the boxes","Oops",0);
- }
- CheckScore=0;
- }
- }
- break;
- case IDC_PREVBOX: // *** user clicked next button ***
- {
- if(SendMessage(GetDlgItem(hwnd,IDC_PREVBOX),BM_GETCHECK,0,0) == BST_CHECKED)
- {
- if(Counter!=0)
- {
- Counter--;
- InvalidateRect(hwnd,0,true);
- if(Score!=0)
- {
- Score--;
- }
- }
- if((Counter)!=Total)
- {
- ShowWindow(hNextBox,SW_SHOW);
- ShowWindow(hCheckBox1,SW_SHOW);
- ShowWindow(hCheckBox2,SW_SHOW);
- ShowWindow(hCheckBox3,SW_SHOW);
- }
- if((Counter+1)==Total)
- {
- Counter=0;
- Score=0;
- }
- CheckScore=0;
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2), BM_SETCHECK, BST_UNCHECKED, 0);
- SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3), BM_SETCHECK, BST_UNCHECKED, 0);
- }
- }
- break;
- }
- }
- break;
- case WM_DESTROY:
- PostQuitMessage (0);
- break;
- default:
- return DefWindowProc (hwnd, message, wParam, lParam);
- }
- return 0;
- }
- /*************************************************************
- Answers.h file
- *************************************************************/
- #ifndef ANSWERS_H
- #define ANSWERS_H
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <windows.h>
- using namespace std;
- class Answers
- {
- public:
- Answers();
- void getString(vector<string>& list);
- //int getChar();
- //int getLine();
- protected:
- private:
- };
- #endif // ANSWERS_H
- /*************************************************************
- Answers.cpp file
- *************************************************************/
- #include "Answers.h"
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <windows.h>
- using namespace std;
- Answers::Answers()
- {
- //ctor
- }
- void Answers::getString(vector<string>& list)
- {
- ifstream fi;
- bool tf=false;
- string str,str2;
- while(tf==false)
- {
- cout<<"What test would you like to do?\n";
- cin>>str2;
- str2+=".txt";
- cout<<str2<<endl;
- fi.open(str2.c_str());
- if(fi.good())
- {
- while(getline(fi,str))
- {
- list.push_back(str);
- }
- tf=true;
- fi.close();
- FreeConsole();
- }
- else
- {
- cout<<"\nThat file does not exist please try again.\nDo not include the file type\n";
- str2="";
- fi.close();
- }
- }
- }
- /*int Answers::getChar()
- {
- int charCount = 0;
- fi.open("test.txt");
- if(fi.good())
- {
- fi.seekg(0,ios::beg);
- fi.seekg(0,ios::end);
- charCount = fi.tellg();
- }
- fi.close();
- return charCount;
- }
- int Answers::getLine()
- {
- int lineCount = 0;
- string str;
- fi.open("test.txt");
- if(fi.good())
- {
- while(getline(fi,str))
- {
- lineCount++;
- }
- }
- fi.close();
- return lineCount;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement