Bitmap

Please tell me how you press the button to download the picture:

1
2
3
4
5
6
7
      case WM_COMMAND:
        if (LOWORD(wParam)==100)
        {
            DestroyWindow(hButton);
            DestroyWindow(hButtonV);
            DestroyWindow(hButtonZ);
        }


That's all the code if needed. Thanks in advance.

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
121
122
123
124
125
126
127
128
#include <Windows.h>
#pragma comment(lib, "winmm.lib")

HWND hMainWnd, hButton, hButtonV, hButtonZ;
char szClassName[] = "MyClass";
MSG msg;
WNDCLASSEX wc;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	wc.cbSize = sizeof(wc);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = szClassName;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if (!RegisterClassEx(&wc)) {
		MessageBox(NULL, "Cannot register class", "Error", MB_OK);
		return 0;
	}

	hMainWnd = CreateWindow(
		szClassName, "Game", WS_POPUPWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
		(HWND)NULL, (HMENU)NULL,
		(HINSTANCE)hInstance, NULL
		);
	
	if (!hMainWnd) {
		MessageBox(NULL, "Cannot create main window", "Error", MB_OK);
		return 0;
	}

	ShowWindow(hMainWnd, SW_SHOWMAXIMIZED);//Окно во весь экран);

	hButton = CreateWindow("BUTTON", "Начать", WS_CHILD | WS_VISIBLE,
		(GetSystemMetrics(SM_CXSCREEN)/2-60), (GetSystemMetrics(SM_CYSCREEN)/3+40), 119, 20, hMainWnd, (HMENU)100, hInstance, 0);

	hButtonZ = CreateWindow("BUTTON", "Звук", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
		(GetSystemMetrics(SM_CXSCREEN)/2-62), (GetSystemMetrics(SM_CYSCREEN)/3+70), 119, 20, hMainWnd, (HMENU)101, hInstance, 0);

	hButtonV = CreateWindow("BUTTON", "Выход", WS_CHILD | WS_VISIBLE,
		(GetSystemMetrics(SM_CXSCREEN)/2-60), (GetSystemMetrics(SM_CYSCREEN)/3+100), 119, 20, hMainWnd, (HMENU)102, hInstance, 0);

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

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HDC hDC;
	PAINTSTRUCT ps;
        RECT rect; 
	static HBITMAP bmpSource = NULL;
	static HDC hdcSource = NULL;

	switch (msg)
	{
	case WM_CREATE:
			bmpSource = (HBITMAP)LoadImage(NULL, "images\\fon.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
			SelectObject(hdcSource, bmpSource);
			return 0;

	case WM_PAINT:
			hDC = BeginPaint(hWnd, &ps);
			BitBlt(hDC, 0, 0, 500, 500, hdcSource, 0, 0, SRCCOPY);
			StretchBlt(hDC,0 ,0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),hdcSource,0,0,600,375,SRCCOPY);
			EndPaint(hWnd, &ps);
			mciSendString("pause sound\\1.mp3", NULL, 0, NULL);
			return 0;
	
	case WM_COMMAND:
		if (LOWORD(wParam)==100)
		{
			ShowWindow(hButton,SW_HIDE);
			MoveWindow(hButtonZ, (GetSystemMetrics(SM_CXSCREEN)-140), 
				(GetSystemMetrics(SM_CYSCREEN)/GetSystemMetrics(SM_CYSCREEN)+20), 119, 20, WM_PAINT);
			MoveWindow(hButtonV, (GetSystemMetrics(SM_CXSCREEN)-140), 
				(GetSystemMetrics(SM_CYSCREEN)/GetSystemMetrics(SM_CYSCREEN)+50), 119, 20, WM_PAINT);
		}
		if(LOWORD(wParam)==102)
		{
			exit(1);
		}
		if(LOWORD(wParam)==101)
		{
				HWND hwndCheck = GetDlgItem(hWnd, 101);
				LRESULT res = SendMessage (hwndCheck, BM_GETCHECK, 0, 0);
				if(res == BST_CHECKED)
				{
					mciSendString("play sound\\1.mp3", NULL, 0, NULL);
				}
				if(res == BST_UNCHECKED)
				{
					mciSendString("pause sound\\1.mp3", NULL, 0, NULL);
				}
		}
		break;

	case WM_CLOSE:
		DestroyWindow(hWnd);
		return 0;
		break;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
		break;

	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}

	return 0;
}
Topic archived. No new replies allowed.