반응형
상단 메뉴를 통해서 불러온 비트맵 사진을 관리하는 실습용 프로그램입니다
이미지를 창 크기에 맞춰 보여주고 메뉴의 source, 3x3, 4x4 메뉴 이벤트를 통해
사진을 9등분하거나 16등분하여 무작위 배치합니다.
2시간만에 끝내야해서 빠르게 코딩하다보니 초기에 급하게 잘못짠 자료구조에 껴맞춤 감이 있네요ㅜㅠ
ID_IMAGE_SOURCE = 원본사진
ID_IMAGE_3BY3 = 3x3분할 무작위배치
ID_IMAGE_4BY4 = 4x4분할 무작위배치
ID_IMAGE_EXIT = 프로그램 종료
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include "resource.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
void GenerateRand();
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS WndClass;
hInst = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
WndClass.lpszClassName = "Window Class Name";
RegisterClass(&WndClass);
hwnd = CreateWindow("Window Class Name",
"Window Title Name",
WS_OVERLAPPEDWINDOW,
0,
0,
1000,
800,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
enum STATE
{
RESOURCE,
S3BY3 = 3,
S4BY4 = 4
};
int state;
int RandPos[4][4];
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HDC memdc;
static HBITMAP hBitmap;
static BITMAP BitData;
static RECT WinSize;
switch (iMsg)
{
case WM_CREATE:
hBitmap = (HBITMAP)LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
state = STATE::RESOURCE;
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
memdc = CreateCompatibleDC(hdc);
GetClientRect(hwnd, &WinSize);
/* Draw */
SelectObject(memdc, hBitmap);
GetObject(hBitmap, sizeof(BITMAP), &BitData);
//StretchBlt(hdc, 0, 0, WinSize.right, WinSize.bottom, memdc, 0, 0, BitData.bmWidth, BitData.bmHeight, SRCCOPY);
switch (state)
{
case STATE::RESOURCE:
StretchBlt(hdc, 0, 0, WinSize.right, WinSize.bottom, memdc, 0, 0, BitData.bmWidth, BitData.bmHeight, SRCCOPY);
break;
case STATE::S3BY3:
case STATE::S4BY4:
GenerateRand();
for (int yPos = 0; yPos < state; yPos++)
{
for (int xPos = 0; xPos < state; xPos++)
{
StretchBlt(hdc, WinSize.right / state * xPos, WinSize.bottom / state * yPos, WinSize.right / state, WinSize.bottom / state, memdc, (BitData.bmWidth / state) * (RandPos[xPos][yPos] % state), (BitData.bmHeight / state) * (RandPos[xPos][yPos] / state), BitData.bmWidth / state, BitData.bmHeight / state, SRCCOPY);
}
}
break;
}
DeleteDC(memdc);
EndPaint(hwnd, &ps);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_IMAGE_SOURCE:
state = STATE::RESOURCE;
InvalidateRgn(hwnd, NULL, true);
break;
case ID_IMAGE_3BY3:
state = STATE::S3BY3;
InvalidateRgn(hwnd, NULL, true);
break;
case ID_IMAGE_4BY4:
state = STATE::S4BY4;
InvalidateRgn(hwnd, NULL, true);
break;
case ID_IMAGE_EXIT:
PostQuitMessage(0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
void GenerateRand()
{
bool check[4][4] = { false, };
srand(clock());
for (int yID = 0; yID < state; yID++)
{
for (int xID = 0; xID < state; xID++)
{
RandPos[xID][yID] = (rand() % (state * state));
if (!check[RandPos[xID][yID] % state][RandPos[xID][yID] / state])
{
check[RandPos[xID][yID] % state][RandPos[xID][yID] / state] = true;
}
else if (check[RandPos[xID][yID] % state][RandPos[xID][yID] / state])
{
xID -= 1;
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
참고하실 분이 계시다면 리소스 파일을 따로 만들어 ID값 수정해야해요
반응형
'개발 > 게임\그래픽스' 카테고리의 다른 글
게임 수학 C++ | 2. 벡터 (0) | 2020.05.22 |
---|---|
게임 수학 C++ | 1. 기반 (0) | 2020.05.22 |
WinApi 메모장 (0) | 2019.11.08 |
2019_Under the Chamber (0) | 2019.10.26 |
2018_2D 로그라이크 게임 (0) | 2019.10.26 |