0% found this document useful (0 votes)
125 views

Raport: Lucrare de Laborator Nr. 4-5

The document describes a laboratory work assignment to create a Windows program that displays a quiz using radio buttons, check boxes, push buttons, and a timer. The program code provided implements the quiz as directed, displaying multiple choice and true/false questions with buttons to select answers and submit responses, and using timers and message boxes to control timing and display results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Raport: Lucrare de Laborator Nr. 4-5

The document describes a laboratory work assignment to create a Windows program that displays a quiz using radio buttons, check boxes, push buttons, and a timer. The program code provided implements the quiz as directed, displaying multiple choice and true/false questions with buttons to select answers and submit responses, and using timers and message boxes to control timing and display results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Ministerul educației a Republicii Moldova

Universitatea tehnică a Moldovei


Facultatea Calculatoare, Informatică și Microelectronică
Filiera francofonă Informatica

Raport
Programarea pilotată de evenimente
Lucrare de laborator nr. 4-5
Tema : Ceasul sistemului Windows. Ferestre
descendent

Realizat de :
Verificat de :

Chișinau 2021
Sarcina:  Scrieţi un program care afişează un test, utilizând radio
butoane, check boxes, butoane push și pentru cronometrare de folosit timer-ul.
Codul sursă :

// WindowsProject4.cpp : Defines the entry point for the application.


//

#include "framework.h"
#include "WindowsProject4.h"

#define NUM 10

#define MAX_LOADSTRING 100

// Global Variables:
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);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
UINT uResult;

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,


_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.

// Initialize global strings


LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_WINDOWSPROJECT4, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:


if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}

HACCEL hAccelTable = LoadAccelerators(hInstance,


MAKEINTRESOURCE(IDC_WINDOWSPROJECT4));

MSG msg;

// Main message loop:


while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int)msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
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_WINDOWSPROJECT4));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINDOWSPROJECT4);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassExW(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable

HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,


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

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//

int DisplayResourceNAMessageBox()
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Timpul a expirat",
(LPCWSTR)L"Alert",
MB_ICONWARNING
);
return msgboxID;
}

int Congrats()
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Correct",
(LPCWSTR)L"Congrats",
MB_OK
);
return msgboxID;
}

int Retry()
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Incorrect. Try again.",
(LPCWSTR)L"Incorrect",
MB_RETRYCANCEL
);
return msgboxID;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
static HWND hwndButton[NUM];
static RECT rect;
static int cxChar, cyChar;
HDC hdc;
PAINTSTRUCT ps;
int i;
TEXTMETRIC tm;

case WM_CREATE:
uResult = SetTimer(hWnd, // handle to main window
0, // timer identifier
10000, // 10-second interval
(TIMERPROC)NULL); // no timer callback
hdc = GetDC(hWnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hWnd, hdc);
hwndButton[0] = CreateWindowW(TEXT("button"), TEXT("Care este cel mai lung fluviu
din Europa"), WS_CHILD | WS_VISIBLE |
BS_GROUPBOX, cxChar, cyChar * 1,
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)0,
hInst, NULL);
hwndButton[1] = CreateWindowW(TEXT("button"), TEXT("Eden"), WS_CHILD | WS_VISIBLE
|
BS_AUTORADIOBUTTON, cxChar, cyChar * (1 + 2),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)1,
hInst, NULL);
hwndButton[2] = CreateWindowW(TEXT("button"), TEXT("Onega"), WS_CHILD |
WS_VISIBLE |
BS_AUTORADIOBUTTON, cxChar, cyChar * (1 + 2 * 2),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)2,
hInst, NULL);
hwndButton[3] = CreateWindowW(TEXT("button"), TEXT("Volga"), WS_CHILD |
WS_VISIBLE |
BS_AUTORADIOBUTTON, cxChar, cyChar * (1 + 2 * 3),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)3,
hInst, NULL);
hwndButton[4] = CreateWindowW(TEXT("button"), TEXT("Lee"), WS_CHILD | WS_VISIBLE
|
BS_AUTORADIOBUTTON, cxChar, cyChar * (1 + 2 * 4),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)4,
hInst, NULL);

hwndButton[5] = CreateWindowW(TEXT("button"), TEXT("Care este capitala


Islandei?"), WS_CHILD | WS_VISIBLE |
BS_GROUPBOX, cxChar, cyChar * (1 + 2 * 5),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)5,
hInst, NULL);
hwndButton[6] = CreateWindowW(TEXT("button"), TEXT("Praga"), WS_CHILD |
WS_VISIBLE |
BS_AUTOCHECKBOX, cxChar, cyChar * (1 + 2 * 6),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)6,
hInst, NULL);
hwndButton[7] = CreateWindowW(TEXT("button"), TEXT("Copenhaga"), WS_CHILD |
WS_VISIBLE |
BS_AUTOCHECKBOX, cxChar, cyChar * (1 + 2 * 7),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)7,
hInst, NULL);
hwndButton[8] = CreateWindowW(TEXT("button"), TEXT("Reykjavik"), WS_CHILD |
WS_VISIBLE |
BS_AUTOCHECKBOX, cxChar, cyChar * (1 + 2 * 8),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)8,
hInst, NULL);
hwndButton[9] = CreateWindowW(TEXT("button"), TEXT("Nicosia"), WS_CHILD |
WS_VISIBLE |
BS_AUTOCHECKBOX, cxChar, cyChar * (1 + 2 * 9),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)9,
hInst, NULL);
hwndButton[10] = CreateWindowW(TEXT("button"), TEXT("Submit"), WS_CHILD |
WS_VISIBLE |
BS_PUSHBUTTON, cxChar, cyChar * (1 + 2 * 10),
20 * cxChar, 7 * cyChar / 4, hWnd, (HMENU)10,
hInst, NULL);
return 0;

case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case 10:
if (SendMessage(hwndButton[3], BM_GETCHECK, BST_CHECKED, 1) &&
SendMessage(hwndButton[8], BM_GETCHECK, BST_CHECKED, 1))
Congrats();
else {
Retry();
for (int i = 0; i < NUM; i++) {
SendMessage(hwndButton[i], BM_SETCHECK, BST_UNCHECKED, 0);
}
}
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_TIMER:
DisplayResourceNAMessageBox();
PostQuitMessage(0);
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
KillTimer(hWnd, uResult);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.


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;
}
Concluzie :
În această lucrare de laborator am creat o aplicație Windows care afișează o
fereastră, în centrul zonei de client fiind un test. În cazul în care selectăm
răspunsurile corecte, ne va afișa o fereastră care va afișa o felicitare, în caz
contrar, butoanele se deselectează și utilizatorul mai are o șansă de a încerca
testul. La expirarea a 10 secunde, apare o fereastră alert după care se așteaptă ca
utilizatorul să apese pe ok iar testul să se închidă.

You might also like