1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
| #include <windows.h>
LPCSTR lpszClassName = "MainClass";
LPCSTR lpszPopClass = "Pop-upClass";
LPCSTR lpszCaption = "Задание 15";
/*------------------*/
HINSTANCE hInst = NULL;
/*------------------*/
BOOL RegClass( WNDPROC, LPCSTR, UINT );
/*------------------*/
int width, height;
int x , y;
int corner = 1, corner_1 = 3 ; // начальные позиции окон
LRESULT CALLBACK lpfnMainProcc( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK lpfnPopUpProcc( HWND, UINT, WPARAM, LPARAM );
/*------------------*/
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
MSG message;
HWND hWnd;
hInst = hInstance;
if( !RegClass( lpfnMainProcc, lpszClassName, COLOR_3DHIGHLIGHT))
return FALSE;
if( !RegClass( lpfnPopUpProcc, lpszPopClass, COLOR_DESKTOP))
return FALSE;
/*------------------*/
width = GetSystemMetrics( SM_CXSCREEN );
width /= 2;
height = GetSystemMetrics( SM_CYSCREEN );
height /= 2;
/*-----------------*/
if( ( hWnd = CreateWindow( lpszClassName, lpszCaption, WS_OVERLAPPEDWINDOW, 0, 0, width, height , NULL, NULL, hInst, NULL)) == NULL )
return FALSE;
ShowWindow( hWnd, nCmdShow );
while( GetMessage( &message, NULL, 0, 0))
DispatchMessage( &message );
return message.wParam;
}
BOOL RegClass( WNDPROC lpfnProcc, LPCSTR lpszClassName, UINT hbrBackground )
{
WNDCLASS class_name;
class_name.cbClsExtra = class_name.cbWndExtra = 0;
class_name.hbrBackground = ( HBRUSH)( hbrBackground + 1 );
class_name.hCursor = LoadCursor( NULL, IDC_ARROW );
class_name.hIcon = LoadIcon( NULL, IDI_APPLICATION );
class_name.hInstance = hInst;
class_name.lpfnWndProc = lpfnProcc;
class_name.lpszClassName = lpszClassName;
class_name.lpszMenuName = NULL;
class_name.style = CS_VREDRAW | CS_HREDRAW |CS_DBLCLKS;
return ( RegisterClass( &class_name) != 0 );
}
LRESULT CALLBACK lpfnMainProcc( HWND hWnd, UINT messages, WPARAM wParam, LPARAM lParam )
{
static HWND hWndPopUp;
switch( messages )
{
case WM_CREATE:
{
if( ( hWndPopUp = CreateWindow( lpszPopClass, lpszCaption, WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE, x + width, y + height, width, height , hWnd, NULL, hInst, NULL)) == NULL )
{
MessageBox( hWnd, "Не удалось создать временное окно", "Ошибка", MB_OK | MB_ICONSTOP );
return FALSE;
}
return 0;
}
case WM_LBUTTONDOWN:
{
if( corner != corner_1 - 1 )
if( corner != 4 || corner_1 != 1 )
{
corner = ( corner == 4)? 0: corner;
x = ( corner == 1 || corner == 2)*width;
y = ( corner >= 2)*height;
SetWindowPos( hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE );
corner++;
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage( 0 );
return 0;
}
default: return DefWindowProc( hWnd, messages, wParam, lParam );
}
}
LRESULT CALLBACK lpfnPopUpProcc( HWND hWnd, UINT messages, WPARAM wParam, LPARAM lParam )
{
switch( messages )
{
case WM_LBUTTONDOWN:
{
if( corner_1 != corner - 1 )
if( corner_1 != 4 || corner != 1)
{
corner_1 = ( corner_1 == 4)? 0: corner_1;
x = ( corner_1 == 1 || corner_1 == 2)*width;
y = ( corner_1 >= 2)*height;
SetWindowPos( hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE );
corner_1++;
}
return 0;
}
default: return DefWindowProc( hWnd, messages, wParam, lParam );
}
} |