Lab 7 PW
Lab 7 PW
REFERAT
Lucrarera de laborator nr.7
Nita Alexandr
Postaru Andrei
Chişinău 2011
1.Scopul lucrarii: De studiat metodele si principiile de lucru cu ferestrele descendente si
principiile de prelucrare a mesajelor parvenite de la ferestre descendente.
2.Codul sursa:
// lab7.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "lab7.h"
#include "math.h"
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
//////
struct
{
LONG style;
TCHAR *name;
}
button[]=
{
BS_AUTORADIOBUTTON, L" CUB ",
BS_AUTORADIOBUTTON, L" PIRAMIDA",
BS_AUTORADIOBUTTON, L" EFECT",
BS_AUTOCHECKBOX, L"Rosu",
BS_AUTOCHECKBOX, L"Verde",
BS_AUTOCHECKBOX, L"Albastru",
BS_PUSHBUTTON, L" START",
BS_PUSHBUTTON, L" STOP"
};
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
return RegisterClassEx(&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)
{
HWND hWnd;
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
//
//
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
hdc=GetDC(hWnd);
switch (wParam)
{
case 6:
iCheck[6]= (int) SendMessage (hWndButton[6], BM_GETSTATE, 0, 0) ;
iCheck[7]=0;
if (iCheck[6]!=0)
{
EnableWindow(hWndButton[0],FALSE);
EnableWindow(hWndButton[1],FALSE);
EnableWindow(hWndButton[2],FALSE);
EnableWindow(hWndButton[7],TRUE);
EnableWindow(hWndButton[6],FALSE);
}
InvalidateRect(hWnd,NULL,TRUE);
break;
case 7:
iCheck[7]= (int) SendMessage (hWndButton[7], BM_GETSTATE, 0, 0) ;
iCheck[6]=0;
EnableWindow(hWndButton[0],TRUE);
EnableWindow(hWndButton[1],TRUE);
EnableWindow(hWndButton[2],TRUE);
if(iCheck[7]!=0)
{
EnableWindow(hWndButton[7],FALSE);
EnableWindow(hWndButton[6],TRUE);
}
break;
}
hdc=GetDC(hWnd);
ReleaseDC(hWnd,hdc);
for(int i=0;i<=7;i++)
{
if(i<3){
hWndButton[i]=CreateWindow(L"button",button[i].name,WS_CHILD|WS_VISIBLE|
button[i].style,
100,0+20*y*i,200,20,hWnd,(HMENU) i,
((LPCREATESTRUCT)lParam)-
>hInstance,NULL);
}
if((i>=3)&&(i<6)){
hWndButton[i]=CreateWindow(L"button",button[i].name,WS_CHILD|WS_VISIBLE|
button[i].style,
700,0+20*y*k,200,20,hWnd,(HMENU) i,
((LPCREATESTRUCT)lParam)-
>hInstance,NULL);k++;
}
if (i==6){
hWndButton[i]=CreateWindow(L"button",button[i].name,WS_CHILD|
WS_VISIBLE|button[i].style,
250,0+20*y*k,200,20,hWnd,(HMENU) i,
((LPCREATESTRUCT)lParam)-
>hInstance,NULL);
}
if (i==7){
hWndButton[i]=CreateWindow(L"button",button[i].name,WS_CHILD|
WS_VISIBLE|button[i].style,
550,0+20*y*k,200,20,hWnd,(HMENU) i,
((LPCREATESTRUCT)lParam)-
>hInstance,NULL);
}
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd,&rect);
HPEN pen;
if(color==1) pen=CreatePen(PS_SOLID,2,RGB(255,0,0));
if(color==2) pen=CreatePen(PS_SOLID,2,RGB(0,255,0));
if(color==3) pen=CreatePen(PS_SOLID,2,RGB(0,0,255));
SelectObject(hdc,pen);
x_1=lengthx*cos(angle);
y_1=lengthy*sin(angle);
x_2=lengthx*cos(angle+PI/2);
y_2=lengthy*sin(angle+PI/2);
x_11=lengthx2*cos(angle2);
y_11=lengthy2*sin(angle2);
x_22=lengthx2*cos(angle2+PI/2);
y_22=lengthy2*sin(angle2+PI/2);
//fetile laterale
MoveToEx(hdc,patrat1[0].x,patrat1[0].y,NULL);
LineTo(hdc,patrat2[0].x,patrat2[0].y);
MoveToEx(hdc,patrat1[1].x,patrat1[1].y,NULL);
LineTo(hdc,patrat2[1].x,patrat2[1].y);
MoveToEx(hdc,patrat1[2].x,patrat1[2].y,NULL);
LineTo(hdc,patrat2[2].x,patrat2[2].y);
MoveToEx(hdc,patrat1[3].x,patrat1[3].y,NULL);
LineTo(hdc,patrat2[3].x,patrat2[3].y);
Polygon(hdc,patrat2,4);
}
MoveToEx(hdc,patrat1[1].x,patrat1[1].y,NULL);
LineTo(hdc,500,250);
MoveToEx(hdc,patrat1[2].x,patrat1[2].y,NULL);
LineTo(hdc,500,250);
MoveToEx(hdc,patrat1[3].x,patrat1[3].y,NULL);
LineTo(hdc,500,250);
}
/////////////////////////// TRANSFORMARE ////////////
if (iCheck[2]==1)
{// fata de sus
patrat1[0].x=coordx-x_1; patrat1[0].y=coordy-y_1;
patrat1[1].x=coordx+x_2; patrat1[1].y=coordy+y_2;
patrat1[2].x=coordx+x_1; patrat1[2].y=coordy+y_1;
patrat1[3].x=coordx-x_2; patrat1[3].y=coordy-y_2;
Polygon(hdc,patrat1,4);
// fata de jos
patrat2[0].x=coordx-x_11; patrat2[0].y=coordy-100-y_11;
patrat2[1].x=coordx+x_22; patrat2[1].y=coordy-100+y_22;
patrat2[2].x=coordx+x_11; patrat2[2].y=coordy-100+y_11;
patrat2[3].x=coordx-x_22; patrat2[3].y=coordy-100-y_22;
MoveToEx(hdc,patrat1[0].x,patrat1[0].y,NULL);
LineTo(hdc,patrat2[0].x,patrat2[0].y);
MoveToEx(hdc,patrat1[1].x,patrat1[1].y,NULL);
LineTo(hdc,patrat2[1].x,patrat2[1].y);
MoveToEx(hdc,patrat1[2].x,patrat1[2].y,NULL);
LineTo(hdc,patrat2[2].x,patrat2[2].y);
MoveToEx(hdc,patrat1[3].x,patrat1[3].y,NULL);
LineTo(hdc,patrat2[3].x,patrat2[3].y);
Polygon(hdc,patrat2,4);
}
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_TIMER:
switch (wParam)
{
case TIME1:
if((iCheck[0]==1)||(iCheck[1]==1)||(iCheck[2]==1))
if(iCheck[6]!=0)
{ // zona de redesenare
rect.bottom=500;
rect.left=250;
rect.right=750;
rect.top=200;
//coordonatele patrulaterului de jos
x_1=lengthx*cos(angle);
y_1=lengthy*sin(angle);
x_2=lengthx*cos(angle+PI/2);
y_2=lengthy*sin(angle+PI/2);
angle=angle+angle_stepsize;
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;
}
3. Rezultatul final:
3.1 Cubul
3.2 Piramida:
3.2 Efectul (aici, baza de sus a cubului se roteste in sens opus in comparative cu baza de jos):
4. Concluzie: În timpul efectuării acestei lucrări am facut cunostinta cu principiile
de baza al lucrului cu ferestrele descendente. Am studiat functiile si procedurile
principale(EnableWindow, SendMessage,) care raspund de functionalitatea acestor ferestre.
5. Bibliografie:
1. http://msdn.microsoft.com/;
4. „Indrumar de laborator PW, editura Chisinau UTM 2006” Victor Besliu, Cristina Panu.