Documente Academic
Documente Profesional
Documente Cultură
RAPORT
Lucrare de laborator Nr.1
la
Programarea Pilotată de Evenimente
Varianta 10
Chișinău – 2019
Scopul lucrării:
De studiat bazele și principiile de creare a aplicațiilor Windows
Sarcina :
Creați o aplicație Windows, în centrul zonei client al căreia este afișat un mesaj
“Lucrarea de laborator a studentului “ La redimensionarea ferestrei, mesajul
trebuie să fie afișat în centrul zonei client.
Rezultate afișate:
Figura 1 ;
Codul Programului:
#include "stdafx.h"
#include "WindowsProject5.h"
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
MSG msg;
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
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
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
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
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;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
RECT rect;
//HWND hwnd;
if (GetClientRect(hWnd, &rect))
{
SetTextColor(hdc, RGB(0, 0, 0));
SetBkMode(hdc, TRANSPARENT);
DrawTextW(hdc, L"", -1, &rect, DT_CENTER | DT_VCENTER |
DT_SINGLELINE);
}
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
Mersul Lucrarii:
Odata inregistrata clasa ferestri se poate crea o fereastra din aceasta clasa folosind functia CreateWindowEx.
HWND hwnd;
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Titlul ferestrei mele",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
*Urmatorul este numele clasei (g_szClassName), acesta spune sistemului ce fel de fereastra sa creeze.
*Urmatorul parametru este titlul ferestrei (adica textul ce va apare pe bara de sus a feretrei).
*Urmatorile valori (NULL, NULL, g_hInst, NULL) corespund respectiv la handle-rul ferestrei parinte, al meniului,
al instantei aplicatiei precum si un pointer datele de creare a ferestrei. In sistemul windows, ferestrele sunt aranjate
intr-o ierarhie de tip parinte-copili.
Concluzia: