, , , , , . .

 

 

!

 

:

:

 

 

 

?

StudentHelp, , MS Word. , , antiplagiat.ru, etxt.ru advego.ru. StudentHelp , Word .


:


:

: . : 05.06.2012. : 2010. : 10. antiplagiat.ru: < 30%

():





1

k , , k=4,,7. k , . ; , , . , . , , ( ).
() Win32.






2

C++ (Win32 API), .
, .. () .
, , ( ), , .
. , .
, , (.. ), .
, ( ).




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

#include "stdafx.h"
#include "PP2.h"
#include "commctrl.h"

#define MAX_LOADSTRING100
#define ID_START3300
#define EV_BARIERL"EV_BARIER"

#define think_time2000
#define eat_time20000
#define wait_time5000

// Global Variables:
HINSTANCE hInst;// current instance
TCHAR szTitle[MAX_LOADSTRING];// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];// the main window class name

HFONThFont;//

HWND hWnd;
HWNDhEdCount,//
hButStart,//
hTable;

HANDLEh_ev,//
*h_thr;//

int*indexes=NULL;
intcount = 0;
boolstarted = false;

int Y[5] = {0,0,0,0,0};


CRITICAL_SECTION *vilki;//

CRITICAL_SECTION main_sect;

RECT rect;

// Forward declarations of functions included in this code module:
ATOMMyRegisterClass(HINSTANCE hInstance);
BOOLInitInstance(HINSTANCE, int);
LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACKAbout(HWND, UINT, WPARAM, LPARAM);

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
int id = *((int*)lpParameter);
TCHAR id_str[5];
_itow(id, id_str, 10);
WaitForSingleObject(h_ev, INFINITE);
srand( GetTickCount());
int time=0;
bool eated = false;

TCHAR str[200]=L"";

TCHAR str_time[200]=L"";
TCHAR str_time1[200]=L"";
SYSTEMTIME sys_time;
SYSTEMTIME sys_time1;

while(1)
{

time = (rand()*think_time)/RAND_MAX;
GetLocalTime(&sys_time);
Sleep(time);//
{
GetLocalTime(&sys_time1);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time, L"HH':'mm':'ss':'ms", str_time, 200);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time1, L"HH':'mm':'ss':'ms", str_time1, 200);
swprintf(str, L"(%s) %s (%s ms)",str_time, id_str, str_time1);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

}
eated = false;

while(!eated)
{
if(TryEnterCriticalSection(&(vilki[id])) !=0 )//
{
wcscpy(str,L"");
swprintf(str, L" %s %d", id_str, id);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

if(id == count-1)//
{
if (TryEnterCriticalSection(&(vilki[0])) ==0 )// -
{
LeaveCriticalSection(&(vilki[id]) );
swprintf(str, L" %s %d", id_str, id);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);
}
else
{
swprintf(str, L" %s 0", id_str);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

time = (rand()*eat_time)/RAND_MAX;
GetLocalTime(&sys_time);
Y[id] = 10;
InvalidateRect(hWnd, &rect, true);
Sleep(time);//
{
GetLocalTime(&sys_time1);
Y[id] = 0;
InvalidateRect(hWnd, &rect, true);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time, L"HH':'mm':'ss':'ms", str_time, 200);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time1, L"HH':'mm':'ss':'ms", str_time1, 200);
swprintf(str, L"(%s) %s (%s ms)",str_time, id_str, str_time1);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

eated = true;

}
LeaveCriticalSection(&(vilki[id]) );//
swprintf(str, L" %s %d", id_str, id);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

LeaveCriticalSection(&(vilki[0]) );
swprintf(str, L" %s 0", id_str);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);
}
}
else
{
if (TryEnterCriticalSection(&(vilki[id+1])) == 0)// -
{
LeaveCriticalSection(&(vilki[id]) );
swprintf(str, L" %s %d", id_str, id);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);
}
else
{
swprintf(str, L" %s %d", id_str, id+1);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

GetLocalTime(&sys_time);
Y[id] = 10;
InvalidateRect(hWnd, &rect, true);
Sleep(time);//
{
Y[id] = 0;
InvalidateRect(hWnd, &rect, true);
GetLocalTime(&sys_time1);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time, L"HH':'mm':'ss':'ms", str_time, 200);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time1, L"HH':'mm':'ss':'ms", str_time1, 200);
swprintf(str, L"(%s) %s (%s ms)",str_time, id_str, str_time1);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

eated = true;

}
LeaveCriticalSection(&vilki[id]);//
swprintf(str, L" %s %d", id_str, id);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);

LeaveCriticalSection(&vilki[id+1]);
swprintf(str, L" %s %d", id_str, id+1);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);
}
}

}
time = (rand()*wait_time)/RAND_MAX;
GetLocalTime(&sys_time);
Sleep(time);//
GetLocalTime(&sys_time1);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time, L"HH':'mm':'ss':'ms", str_time, 200);
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &sys_time1, L"HH':'mm':'ss':'ms", str_time1, 200);
swprintf(str, L"(%s) %s (%s ms)",str_time, id_str, str_time1);

EnterCriticalSection(&main_sect);
SendMessage(hTable, LB_ADDSTRING, 0, (LPARAM)&str);
LeaveCriticalSection(&main_sect);
}

}

}


int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_PP2, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PP2));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX 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_PP2));
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName= MAKEINTRESOURCE(IDC_PP2);
wcex.lpszClassName= szWindowClass;
wcex.hIconSm= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}


LOGFONT lf;

lf.lfCharSet = DEFAULT_CHARSET;
lf.lfPitchAndFamily = DEFAULT_PITCH;
wcscpy_s(lf.lfFaceName, L"Arial");
lf.lfHeight = -15;
lf.lfStrikeOut = 0;
lf.lfUnderline = 0;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
lf.lfWeight = FW_NORMAL;
lf.lfWidth = 6;
lf.lfOrientation = lf.lfEscapement = 0;
lf.lfItalic = FALSE;
hFont = CreateFontIndirect(&lf);

hEdCount = CreateWindow(L"Edit", L"5", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_NUMBER,
100, 50, 100, 22, hWnd, NULL, hInstance, NULL);
SendMessage(hEdCount, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);

hButStart = CreateWindow(L"Button", L"", WS_VISIBLE | WS_CHILD,
100, 100, 100, 22, hWnd, (HMENU)ID_START, hInstance, NULL);
SendMessage(hButStart, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);


hTable = CreateWindow(L"Listbox", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_HASSTRINGS | LBS_NOSEL | WS_VSCROLL,
250, 50, 500, 300, hWnd, NULL, hInstance, NULL);

SendMessage(hTable, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);

InitializeCriticalSection(&main_sect);


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

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR str[11];

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_START:
if(!started)
{
GetWindowText(hEdCount, str, 10);
count = _wtoi(str);
if(count <= 2)
{
MessageBox(hWnd, L" !", L"", 0);
}
else
{
SendMessage(hTable, LVM_DELETEALLITEMS, 0, 0);
//vilki = new CRITICAL_SECTION[count];
vilki = (CRITICAL_SECTION*)malloc(count*sizeof(CRITICAL_SECTION));
for(int i=0; i<count; i++)
{
InitializeCriticalSection(&vilki[i]);
..................



90% antiplagiat.ru, etxt.ru advego.ru




* . , .