일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 윈도우프로그래밍
- 컴퓨터 아키텍쳐
- c4d
- bezier curve
- 그래픽스기초
- shader
- win32
- Mesh Processing
- 베지에 곡선
- modeling
- Geometry Modeling
- OpenGL
- 렌더링
- Graphics
- 그래픽스
- 윈도우
- denoising
- 셰이더프로그래밍
- 컴퓨터 구조
- MFC 윈도우 프로그래밍
- 윈도우 프로그래밍
- MFC
- 윈도우 구조
- 운영체제
- shader programming
- 핵심 API로 배우는 윈도우프로그래밍
- 오픈지엘
- Win32 API
- 셰이더
- window programming
Archives
- Today
- Total
오다기리 박의 알고리즘 노트
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 4장 8번 풀이 본문
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | #include <Windows.h> #include<tchar.h> #include<string.h> #include<math.h> #include"resource.h" LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS WndClass; WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.lpfnWndProc = WndProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = hInstance; WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.lpszMenuName = NULL; WndClass.lpszClassName = _T("Window Class Name"); WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); RegisterClass(&WndClass); hwnd = CreateWindow( _T("Window Class Name"), _T("홍길동의 첫 번째 윈도우"), WS_OVERLAPPEDWINDOW, 100, 100, 1000, 1000, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HPEN hPen,orgPen; HBRUSH hBrush,orgBrush; CHOOSECOLOR COLOR; static COLORREF temp[16], PenColor = RGB(0, 0, 0), FaceColor = RGB(255, 255, 255); static bool isClick = false; static int mX1, mY1, mX2, mY2, mX3, mY3; static int FigureCount = 0; struct Object { int X1, Y1, X2, Y2; int Figure = 0; bool Selected = false; COLORREF PenColor = RGB(0, 0, 0), FaceColor = RGB(255, 255, 255); }; static Object object[100]; switch (iMsg) { case WM_CREATE: break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_PENCOLOR: for (int i = 0; i < 16; i++) temp[i] = RGB(rand() % 256, rand() % 256, rand() % 256); memset(&COLOR, 0, sizeof(CHOOSECOLOR)); COLOR.lStructSize = sizeof(CHOOSECOLOR); COLOR.hwndOwner = hwnd; COLOR.lpCustColors = temp; COLOR.Flags = CC_FULLOPEN; if (ChooseColor(&COLOR) != 0) { for (int i = FigureCount; i < 100; i++) object[i].PenColor = COLOR.rgbResult; for (int i = 0; i < FigureCount; i++) { if (object[i].Selected) { object[i].PenColor = COLOR.rgbResult; break; } } } InvalidateRgn(hwnd, NULL, TRUE); break; case ID_FACECOLOR: for (int i = 0; i < 16; i++) temp[i] = RGB(rand() % 256, rand() % 256, rand() % 256); memset(&COLOR, 0, sizeof(CHOOSECOLOR)); COLOR.lStructSize = sizeof(CHOOSECOLOR); COLOR.hwndOwner = hwnd; COLOR.lpCustColors = temp; COLOR.Flags = CC_FULLOPEN; if (ChooseColor(&COLOR) != 0) { for (int i = FigureCount; i < 100; i++) object[i].FaceColor = COLOR.rgbResult; for (int i = 0; i < FigureCount; i++) { if (object[i].Selected) { object[i].FaceColor = COLOR.rgbResult; break; } } } InvalidateRgn(hwnd, NULL, TRUE); break; case ID_LINE: for (int i = FigureCount; i < 100; i++) object[i].Figure = 1; break; case ID_ELLIPSE: for (int i = FigureCount; i < 100; i++) object[i].Figure = 2; break; case ID_RECTANGLE: for (int i = FigureCount; i < 100; i++) object[i].Figure = 3; break; } break; case WM_LBUTTONDOWN: object[FigureCount].X1 = mX1 = LOWORD(lParam); object[FigureCount].Y1 = mY1 = HIWORD(lParam); isClick = true; break; case WM_LBUTTONUP: //isClick = false; object[FigureCount].X2 = mX2 = LOWORD(lParam); object[FigureCount].Y2 = mY2 = HIWORD(lParam); InvalidateRgn(hwnd, NULL, TRUE); FigureCount++; break; case WM_RBUTTONDOWN: mX3 = LOWORD(lParam); mY3 = HIWORD(lParam); for (int i = 0; i < FigureCount; i++) object[i].Selected = false; for (int i = 0; i < FigureCount; i++) { if (object[i].Figure == 3 && mX3 > object[i].X1&&mX3<object[i].X2&&mY3>object[i].Y1&&mY3 < object[i].Y2)//사각형안을 클릭하면 { object[i].Selected = object[i].Selected?false:true; break; } } InvalidateRgn(hwnd, NULL, TRUE); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); for (int i = 0; i <= FigureCount; i++) { hPen = CreatePen(PS_SOLID, 1, object[i].PenColor); SelectObject(hdc, hPen); hBrush = CreateSolidBrush(object[i].FaceColor); SelectObject(hdc, hBrush); switch (object[i].Figure) { case 1: MoveToEx(hdc, object[i].X1, object[i].Y1, NULL); LineTo(hdc, object[i].X2, object[i].Y2); break; case 2: Ellipse(hdc, object[i].X1, object[i].Y1, object[i].X2, object[i].Y2); break; case 3: Rectangle(hdc, object[i].X1, object[i].Y1, object[i].X2, object[i].Y2); break; } if (object[i].Selected) { orgPen = CreatePen(PS_SOLID, 1, RGB(0,0,0)); SelectObject(hdc, orgPen); orgBrush = CreateSolidBrush(RGB(255, 255, 255)); SelectObject(hdc, orgBrush); Rectangle(hdc, object[i].X1 - 10, object[i].Y1 - 10, object[i].X1, object[i].Y1); Rectangle(hdc, object[i].X2, object[i].Y1 - 10, object[i].X2 + 10, object[i].Y1); Rectangle(hdc, object[i].X1 - 10, object[i].Y2, object[i].X1, object[i].Y2 + 10); Rectangle(hdc, object[i].X2, object[i].Y2, object[i].X2 + 10, object[i].Y2 + 10); } } EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hwnd, iMsg, wParam, lParam); } | cs |
'WIN32 API' 카테고리의 다른 글
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 4장 10번 풀이(미완성) (0) | 2017.11.03 |
---|---|
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 4장 9번 풀이 (0) | 2017.11.03 |
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 4장 7번 풀이(미완성) (0) | 2017.11.03 |
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 4장 6번 풀이 (0) | 2017.11.03 |
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 4장 5번 풀이 (0) | 2017.11.03 |