Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions hw2_16.08.17/task1/main1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* �������� ����������, � ������� ����� ������������ ������ ����.��� ����
������ ����� ������ ��������� � ������ ���� ����.
�������� ���������� ����� �������, ����� ������ ����, ����� �������,
���������� �� �������. */

#include <Windows.h>

#define ID_TIMER1 100
#define ID_TIMER2 102
#define ID_TIMER3 103

HWND hWnd1;
HWND hWnd2;
HWND hWnd3;
HWND hWnd4;

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
SetTimer(hWnd, ID_TIMER1, 1000, NULL);
SetTimer(hWnd, ID_TIMER2, 2000, NULL);
SetTimer(hWnd, ID_TIMER3, 3000, NULL);
break;
case WM_TIMER:
switch(wParam)
{
case ID_TIMER1:
ShowWindow(hWnd2, 1);
KillTimer(hWnd, ID_TIMER1);
break;
case ID_TIMER2:
ShowWindow(hWnd3, 1);
KillTimer(hWnd, ID_TIMER2);
break;
case ID_TIMER3:
ShowWindow(hWnd4, 1);
KillTimer(hWnd, ID_TIMER3);
break;
default:
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
WNDCLASSEX wnd1;
WNDCLASSEX wnd2;
WNDCLASSEX wnd3;
WNDCLASSEX wnd4;

memset(&wnd1, 0, sizeof(wnd1));
wnd1.cbSize = sizeof(wnd1);
wnd1.lpszClassName = L"Window1";
wnd1.hbrBackground = CreateSolidBrush(RGB(255, 0, 0));
wnd1.lpfnWndProc = WndProc;
wnd1.hInstance = hInstance;

wnd2 = wnd1;
wnd2.lpszClassName = L"Window2";
wnd2.hbrBackground = CreateSolidBrush(RGB(0, 255, 0));

wnd3 = wnd1;
wnd3.lpszClassName = L"Window3";
wnd3.hbrBackground = CreateSolidBrush(RGB(0, 0, 255));

wnd4 = wnd1;
wnd4.lpszClassName = L"Window4";
wnd4.hbrBackground = CreateSolidBrush(RGB(255, 255, 0));


if (!(RegisterClassEx(&wnd1) && RegisterClassEx(&wnd2) && RegisterClassEx(&wnd3) && RegisterClassEx(&wnd4)))
{
return 1;
}

hWnd1 = CreateWindowEx(WS_EX_TOPMOST, wnd1.lpszClassName, L"1", WS_OVERLAPPEDWINDOW, 300, 100, 200, 200, NULL, NULL, hInstance, NULL);
hWnd2 = CreateWindowEx(WS_EX_TOPMOST, wnd2.lpszClassName, L"2", WS_OVERLAPPEDWINDOW, 500, 100, 200, 200, NULL, NULL, hInstance, NULL);
hWnd3 = CreateWindowEx(WS_EX_TOPMOST, wnd3.lpszClassName, L"3", WS_OVERLAPPEDWINDOW, 300, 300, 200, 200, NULL, NULL, hInstance, NULL);
hWnd4 = CreateWindowEx(WS_EX_TOPMOST, wnd4.lpszClassName, L"4", WS_OVERLAPPEDWINDOW, 500, 300, 200, 200, NULL, NULL, hInstance, NULL);

if (!(hWnd1 && hWnd2 && hWnd3 && hWnd1))
{
return 2;
}

ShowWindow(hWnd1, 1);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}
47 changes: 47 additions & 0 deletions hw2_16.08.17/task2/main2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* �������� ����������, ������� ���������� ���������� ������������� �����
�� 1 �� 100. ��� ������� � ������������ ����������� ���� ���������.�������� ��
���������� �������. */

#include <Windows.h>
#include <time.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
if (MessageBox(NULL, L"������� ����� �� 1 �� 100 � � ��� ������!", L"��������", MB_OKCANCEL) == IDOK)
{
srand(time(0));
wchar_t buff[50];
int botBorder = 1;
int topBorder = 99;
int count = 0;
int number;
int preBorder;
int id;

while(topBorder != 0)
{
number = botBorder + rand() % topBorder;
count++;
wsprintf(buff, L"��� ����� ������ %i ?", number);
id = MessageBox(NULL, buff, L"��������", MB_YESNOCANCEL);
if (id == IDYES)
{
preBorder = botBorder;
botBorder = number + 1;
topBorder -= botBorder - preBorder;

}
else if (id == IDNO)
{
topBorder = number - botBorder;
}
else
{
return 0;
}
}
wsprintf(buff, L"��� ����� %i!\n� ������ �� %i ������� =)", botBorder, count);
MessageBox(NULL, buff, L"��������", MB_OK);
}
return 0;
}