Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

#Include: "Test - Ppe.h"

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

#include "stdafx.

h"

#include <string>

#include <stdlib.h>

#include "test_ppe.h"

#include <iostream>

#include <sstream>

#include <windows.h>

#define MAX_LOADSTRING 100

#define SUBMIT_BUTTON 101

#define IDB_RADIO1 102

#define IDB_RADIO2 103

#define IDI_ICON 104

#define IDT_TIMER 105

#define IDB_CHECKBOX1 106

#define IDB_CHECKBOX2 107

#define IDB_CHECKBOX3 108

#define IDB_CHECKBOX4 104

void CreareTest(HWND hWnd);

void SetTime(HWND hWnd);

int time = 0; //in sec

int sec = 0;

int minute = 0;

int ore = 0;
HWND hquest, hOut, hINTREB1, hINTREB2, hRadio1, hRadio2, hCheckBox1, hCheckBox2, hCheckBox3,
hCheckBox4;

//VARIABILE GLOBALE

HINSTANCE hInst; // current instance

WCHAR szTitle[MAX_LOADSTRING]; // The title bar text

WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:

ATOM MyRegisterClass(HINSTANCE hInstance);

BOOL InitInstance(HINSTANCE, int);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//este funcția care va trata mesajele
pentru această clasă de ferestre

INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,

_In_opt_ HINSTANCE hPrevInstance,

_In_ LPWSTR lpCmdLine,

_In_ int nCmdShow)

UNREFERENCED_PARAMETER(hPrevInstance);

UNREFERENCED_PARAMETER(lpCmdLine);

LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

LoadStringW(hInstance, IDC_BUTTONSTIMER, szWindowClass, MAX_LOADSTRING);

MyRegisterClass(hInstance);
// Perform application initialization:

if (!InitInstance(hInstance, nCmdShow))

return FALSE;

HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BUTTONSTIMER));

MSG msg;

// Main message loop:

while (GetMessage(&msg, nullptr, 0, 0))//bucla de mesage

if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

TranslateMessage(&msg);

DispatchMessage(&msg);

return (int)msg.wParam;

ATOM MyRegisterClass(HINSTANCE hInstance)//INREGISTRARE CLASA de fereastra

WNDCLASSEXW wcex;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;

wcex.lpfnWndProc = WndProc;

wcex.cbClsExtra = 0;

wcex.cbWndExtra = 0;

wcex.hInstance = hInstance;

wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BUTTONSTIMER));

wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);

wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_BUTTONSTIMER);

wcex.lpszClassName = szWindowClass;

wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassExW(&wcex);

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)

hInst = hInstance; //

HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

if (!hWnd)

return FALSE;

ShowWindow(hWnd, nCmdShow);//afisare ferestra la ecran


UpdateWindow(hWnd);//actualizare fereastra

return TRUE;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

HDC hdc;

PAINTSTRUCT ps;

RECT timeRect = { 10,10,710,30 };//creare cronometru

switch (message)

case WM_CREATE:

SetTimer(hWnd, IDT_TIMER, 1000, NULL);//timpul va creste cu o secunda

CreareTest(hWnd);

break;

case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);

EndPaint(hWnd, &ps);

}
break;

case WM_COMMAND:

int wmId = LOWORD(wParam);

// Parse the menu selections:

switch (wmId)

case IDM_ABOUT:

DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);

break;

case IDM_EXIT:

DestroyWindow(hWnd);

break;

//la apasarea butonului trimite raspuns se verifica conditiile

// daca toate spatiile au fost completate

//daca raspunsul este coorect

//afisarea mesajului in dependenta de corectitudinea realizarii mesajului

case SUBMIT_BUTTON:

char raspunsINTREB1[30], raspunsINTREB2[530], out[100];

GetWindowTextA(hINTREB1, raspunsINTREB1, 30);

double draspuns1 = atof(raspunsINTREB1);

GetWindowTextA(hINTREB2, raspunsINTREB2, 530);

double draspuns2 = atof(raspunsINTREB2);

bool raspunsCorrect = true;

bool spatiuCompletat = true;

//INTREB 1 , verificare spatiu completat


if (!(strlen(raspunsINTREB1) > 0)) spatiuCompletat = false;

//INTREB 2

if (!(strlen(raspunsINTREB2) > 0)) spatiuCompletat = false;

//radioButtons

//verificare daca a fost selectata vreo varianta de raspuns pentru butoane radio

if ((SendDlgItemMessage(hWnd, IDB_RADIO1, BM_GETCHECK, 0, 0) ==


BST_UNCHECKED) &&

(SendDlgItemMessage(hWnd, IDB_RADIO2, BM_GETCHECK, 0, 0) ==


BST_UNCHECKED))

spatiuCompletat = false;

//verifica raspunsul corect pentru intrebarea 3 ,varianta de raspuns corect


pentru IDB_RADIO1

if (!(SendDlgItemMessage(hWnd, IDB_RADIO1, BM_GETCHECK, 1, 0) == 1))

raspunsCorrect = false;

//checkboxes

//VERIFICA RASPUNSURILE pentru intrebarile 2 si 4, care au variantele de


raspuns corecte pentru IDB_CHECKBOX2, IDB_CHECKBOX4 pentru intrebarea 2

//iar pentru intrebarea 4 raspunsul corect este IDB_CHECKBOX2

if (

((SendDlgItemMessage(hWnd, IDB_CHECKBOX1, BM_GETCHECK,


0, 0) == 1) &&

(SendDlgItemMessage(hWnd, IDB_CHECKBOX3, BM_GETCHECK,


0, 0) == 1)) ||

(SendDlgItemMessage(hWnd, IDB_CHECKBOX1, BM_GETCHECK,


0, 0) == 1) ||

(SendDlgItemMessage(hWnd, IDB_CHECKBOX3, BM_GETCHECK,


0, 0) == 1) ||

((SendDlgItemMessage(hWnd, IDB_CHECKBOX2, BM_GETCHECK,


0, 0) == 0) &&

(SendDlgItemMessage(hWnd, IDB_CHECKBOX4, BM_GETCHECK,


0, 0) == 0)) ||
((SendDlgItemMessage(hWnd, IDB_CHECKBOX4, BM_GETCHECK,
0, 0) == 1) &&

(SendDlgItemMessage(hWnd, IDB_CHECKBOX2, BM_GETCHECK,


0, 0) == 1))

raspunsCorrect = false;

//INTREB 1

if (draspuns1 != 4) {

raspunsCorrect = false;

//INTREB 2

if (draspuns2 != 2) {

raspunsCorrect = false;

//dupa completarea raspunsurilor se afiseaza un mesaj in dependenta de


corectitudinea raspunsurilor

if (time <= 0) {

strcpy_s(out, "Timpul a expirat!");

else if (raspunsCorrect && spatiuCompletat) {

strcpy_s(out, "Excelent ");

strcat_s(out, ", totul este corect");

else if (!spatiuCompletat) {

strcpy_s(out, "Nu ai raspuns la toate intrebarile");

else if (!raspunsCorrect) {

strcpy_s(out, "Raspuns gresit");


}

SetWindowTextA(hOut, out);

//AddControls(hWnd);

break;

case IDB_RADIO1:

switch (HIWORD(wParam))

case BN_CLICKED:

//cind radio buton 1 este apasat , radiobuton2 poate fi apasat sau nu

if (SendDlgItemMessage(hWnd, IDB_RADIO1, BM_GETCHECK, 0, 0) == 0)

SendDlgItemMessage(hWnd, IDB_RADIO1, BM_SETCHECK, 1, 0);

SendDlgItemMessage(hWnd, IDB_RADIO2, BM_SETCHECK, 0, 0);

break;

break;

case IDB_RADIO2:

switch (HIWORD(wParam))

case BN_CLICKED:

//cind radio buton 2 este apasat , radiobuton1 poate fi apasat sau nu


if (SendDlgItemMessage(hWnd, IDB_RADIO2, BM_GETCHECK, 0, 0) == 0)

SendDlgItemMessage(hWnd, IDB_RADIO2, BM_SETCHECK, 1, 0);

SendDlgItemMessage(hWnd, IDB_RADIO1, BM_SETCHECK, 0, 0);

break;

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

break;

case WM_TIMER://setarea timpului pentru ceas care va creste pina la finisarea timpului
preconuzat pentru test

if (time >= 0)

time++;

SetTime(hWnd);

else {

KillTimer(hWnd, IDT_TIMER);

break;
}

InvalidateRect(hWnd, &timeRect, TRUE);

//InvalidateRect(hWnd, NULL, TRUE);

break;

case WM_DESTROY:

//KillTimer distruge cronometrul

KillTimer(hWnd, IDT_TIMER);

PostQuitMessage(0);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

return 0;

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

UNREFERENCED_PARAMETER(lParam);

switch (message)

case WM_INITDIALOG:

return (INT_PTR)TRUE;

case WM_COMMAND:

if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)

EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;

break;

return (INT_PTR)FALSE;

void SetTime(HWND hWnd)

static POINT pointNume;

pointNume.x = 210;

pointNume.y = 1;

static int labelWidth = 300;

static int labelHeigth = 20;

char timeString[100];

ore = time / 3600;

minute = (time / 60) % 60;

sec = time % 60;

//uses an string stream to create time string then uses it to output to user

std::wstringstream remainingTime;

remainingTime << "Timp Ramas: " << ore << " : " << minute << " : " << sec;

LPCWSTR Output = remainingTime.str().c_str();

CreateWindow(L"Static", remainingTime.str().c_str(), WS_VISIBLE | WS_CHILD, pointNume.x,


pointNume.y, labelWidth, labelHeigth, hWnd, NULL, NULL, NULL);

//if time is up set time to -1 and

//show "Timpul a expirat" message

if (time == 60)
{

time = -59;

MessageBox(hWnd, L"Timpul a expirat", L"", MB_OK);

char out[] = "Timpul a expirat";

SetWindowTextA(hOut, out);

void CreareTest(HWND hWnd)

POINT pointNume;

pointNume.x = 10;

pointNume.y = 10;

int labelWidth = 300;

int labelHeigth = 20;

RECT timeRect = { 10,10,710,30 };

CreateWindowW(L"Static", L"Scrie numarul la laborator", WS_VISIBLE | WS_CHILD,


pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.1;

hINTREB1 = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER,


pointNume.x, pointNume.y, 500, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.3;

CreateWindowW(L"Static", L"Care sunt dispozitivele de intrare?", WS_VISIBLE |


WS_CHILD, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.05;

hCheckBox4 = CreateWindowEx(0, L"BUTTON", L"Ploterul", WS_VISIBLE | WS_CHILD |


BS_AUTOCHECKBOX | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX1, NULL, NULL);

pointNume.y += (double)labelHeigth;
hCheckBox1 = CreateWindowEx(0, L"BUTTON", L"Mouse-ul", WS_VISIBLE | WS_CHILD |
BS_AUTOCHECKBOX, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX2, NULL, NULL);

pointNume.y += (double)labelHeigth;

hCheckBox2 = CreateWindowEx(0, L"BUTTON", L"Imprimanta", WS_VISIBLE | WS_CHILD


| BS_AUTOCHECKBOX | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX3, NULL, NULL);

pointNume.y += (double)labelHeigth;

hCheckBox3 = CreateWindowEx(0, L"BUTTON", L"Tastatura", WS_VISIBLE | WS_CHILD |


BS_AUTOCHECKBOX | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX3, NULL, NULL);

pointNume.y += (double)labelHeigth;

//RadioButtons

CreateWindowW(L"Static", L"Ce este un eveniment?", WS_VISIBLE | WS_CHILD,


pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.05;

CreateWindowEx(0, L"BUTTON", L"un mesaj de la mouse", WS_VISIBLE | WS_CHILD |


BS_RADIOBUTTON | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_RADIO1, NULL, NULL);

pointNume.y += (double)labelHeigth;

CreateWindowEx(0, L"BUTTON", L"un mesaj de la un prieten", WS_VISIBLE | WS_CHILD


| BS_RADIOBUTTON | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_RADIO2, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.3;

CreateWindowW(L"Static", L"Cite laboratoare ti-au ramas?", WS_VISIBLE | WS_CHILD,


pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.1;

hINTREB2 = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER,


pointNume.x, pointNume.y, 500, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.3;

//ChackBoxes
CreateWindowW(L"Static", L"Unul din parametrii functiei WinMain", WS_VISIBLE |
WS_CHILD, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd, NULL, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.05;

hCheckBox1 = CreateWindowEx(0, L"BUTTON", L"hCursor", WS_VISIBLE | WS_CHILD |


BS_AUTOCHECKBOX | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX1, NULL, NULL);

pointNume.y += (double)labelHeigth;

hCheckBox2 = CreateWindowEx(0, L"BUTTON", L"hInstance", WS_VISIBLE | WS_CHILD |


BS_AUTOCHECKBOX, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX2, NULL, NULL);

pointNume.y += (double)labelHeigth;

hCheckBox3 = CreateWindowEx(0, L"BUTTON", L"hIcon", WS_VISIBLE | WS_CHILD |


BS_AUTOCHECKBOX | WS_GROUP, pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd,
(HMENU)IDB_CHECKBOX3, NULL, NULL);

pointNume.y += (double)labelHeigth * 1.3;

//button de submitere raspuns

CreateWindowW(L"Button", L"Trimite raspuns", WS_VISIBLE | WS_CHILD | WS_BORDER,


pointNume.x, pointNume.y, labelWidth, labelHeigth, hWnd, (HMENU)SUBMIT_BUTTON, NULL, NULL);

//pentru afisarea mesajelor catre utilizator

hOut = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD, pointNume.x + labelWidth,


pointNume.y, 500, labelHeigth, hWnd, NULL, NULL, NULL);

You might also like