일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- MFC 윈도우 프로그래밍
- 그래픽스기초
- OpenGL
- Win32 API
- 베지에 곡선
- MFC
- 컴퓨터 구조
- win32
- 그래픽스
- Geometry Modeling
- 윈도우
- 렌더링
- Graphics
- denoising
- bezier curve
- Mesh Processing
- 윈도우 구조
- modeling
- 윈도우프로그래밍
- shader
- c4d
- shader programming
- 셰이더프로그래밍
- 핵심 API로 배우는 윈도우프로그래밍
- 운영체제
- 컴퓨터 아키텍쳐
- window programming
- 윈도우 프로그래밍
- 셰이더
- 오픈지엘
Archives
- Today
- Total
오다기리 박의 알고리즘 노트
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 6장 9~10번 풀이 본문
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | #include <Windows.h> #include<tchar.h> #include<string.h> #include<math.h> #include"resource.h" #include<CommCtrl.h> //#pragma comment(linker,"/entry:WinMainCRTStartup /subsystem:console") LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK DlgFunc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam); HINSTANCE hInst; void MakeColumn(HWND hDlg); void InsertData(HWND hDlg); int SelectItem(HWND hDlg, LPARAM lParam); void DeleteData(HWND hDlg, int selection); void ModifyData(HWND hDlg, int selection); static int SEX = 1; static bool trigger = false; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS WndClass; hInst = hInstance; 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"); RegisterClass(&WndClass); hwnd = CreateWindow( _T("Window Class Name"), _T("박정호"), WS_OVERLAPPEDWINDOW, 50, 50, 1000, 700, 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; switch (iMsg) { case WM_CREATE: break; case WM_LBUTTONDOWN: DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG8), hwnd, DlgFunc); break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hwnd, iMsg, wParam, lParam); } BOOL CALLBACK DlgFunc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) { static HWND hCombo, hList; static TCHAR InitBirth[20][10]; TCHAR InsertString[100]; static int selection = -1; LPNMHDR hdr; switch (iMsg) { case WM_INITDIALOG: hCombo = GetDlgItem(hDlg, IDC_COMBO1); hList = GetDlgItem(hDlg, IDC_LIST2); for (int i = 0; i < 20; i++) { _stprintf_s(InitBirth[i], 10, _T("%d"), 1990 + i); SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)InitBirth[i]); } CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1); MakeColumn(hDlg); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUTTON1://새회원 SetDlgItemText(hDlg, IDC_EDIT1, _T("")); SetDlgItemText(hDlg, IDC_EDIT2, _T("")); SendMessage(hCombo, CB_SETCURSEL, 0, 0); break; case IDC_BUTTON2://가입 InsertData(hDlg); break; case IDC_BUTTON3://탈퇴 DeleteData(hDlg, selection); break; case IDC_BUTTON6://수정 trigger = true; if (selection == -1)break; ModifyData(hDlg, selection); trigger = false; selection = -1; break; case IDC_RADIO1: SEX = 1; break; case IDC_RADIO2: SEX = 2; break; case IDC_COMBO1: break; case IDCANCEL: EndDialog(hDlg, 0); break; } break; case WM_NOTIFY: hdr = (LPNMHDR)lParam; hList = GetDlgItem(hDlg, IDC_LIST2); if (hdr->hwndFrom == hList&&hdr->code == LVN_ITEMCHANGED&&trigger == false) selection = SelectItem(hDlg, lParam); break; } return 0; } void MakeColumn(HWND hDlg) { LVCOLUMN lvCol = { 0, }; HWND hList; RECT rect; LPTSTR name[4] = { _T("이름"),_T("전화번호"),_T("성별"),_T("출생연도") }; hList = GetDlgItem(hDlg, IDC_LIST2); memset(&lvCol, 0, sizeof(LVCOLUMN)); GetClientRect(hList, &rect); lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvCol.fmt = LVCFMT_LEFT; for (int i = 0; i < 4; i++) { lvCol.cx = rect.right / 4; lvCol.iSubItem = i; lvCol.pszText = name[i]; SendMessage(hList, LVM_INSERTCOLUMN, (WPARAM)i, (LPARAM)&lvCol); } } void InsertData(HWND hDlg) { TCHAR name[20], phone[20], birth[10]; HWND hCombo; LVITEM item; int count; HWND hList; hList = GetDlgItem(hDlg, IDC_LIST2); hCombo = GetDlgItem(hDlg, IDC_COMBO1); count = ListView_GetItemCount(hList); GetDlgItemText(hDlg, IDC_EDIT1, name, 20); if (_tcscmp(name, _T("")) == 0) return; SetDlgItemText(hDlg, IDC_EDIT1, _T("")); GetDlgItemText(hDlg, IDC_EDIT2, phone, 20); SetDlgItemText(hDlg, IDC_EDIT2, _T("")); GetDlgItemText(hDlg, IDC_COMBO1, birth, 10); SetDlgItemText(hDlg, IDC_COMBO1, _T("")); SendMessage(hCombo, CB_SETCURSEL, 0, 0); item.mask = LVIF_TEXT; item.iItem = count; item.iSubItem = 0; item.pszText = name; ListView_InsertItem(hList, &item); ListView_SetItemText(hList, count, 1, phone); ListView_SetItemText(hList, count, 2, SEX == 1 ? _T("여자") : _T("남자")); ListView_SetItemText(hList, count, 3, birth); } int SelectItem(HWND hDlg, LPARAM lParam) { LPNMLISTVIEW nlv; HWND hList, hCombo; TCHAR name[20], phone[20], birth[20], sex[20]; hCombo = GetDlgItem(hDlg, IDC_COMBO1); hList = GetDlgItem(hDlg, IDC_LIST2); int count; nlv = (LPNMLISTVIEW)lParam; ListView_GetItemText(hList, nlv->iItem, 0, name, 20); SetDlgItemText(hDlg, IDC_EDIT1, name); ListView_GetItemText(hList, nlv->iItem, 1, phone, 20); SetDlgItemText(hDlg, IDC_EDIT2, phone); ListView_GetItemText(hList, nlv->iItem, 2, sex, 20); if (_tcscmp(sex, _T("여자")) == 0) { CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1); SEX = 1; } else { CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2); SEX = 2; } ListView_GetItemText(hList, nlv->iItem, 3, birth, 20); count = SendMessage(hCombo, CB_FINDSTRING, 0, (LPARAM)birth); SendMessage(hCombo, CB_SETCURSEL, count, 0); return nlv->iItem; } void DeleteData(HWND hDlg, int selection) { HWND hList, hCombo; hList = GetDlgItem(hDlg, IDC_LIST2); hCombo = GetDlgItem(hDlg, IDC_COMBO1); ListView_DeleteItem(hList, selection); SetDlgItemText(hDlg, IDC_EDIT1, _T("")); SetDlgItemText(hDlg, IDC_EDIT2, _T("")); SendMessage(hCombo, CB_SETCURSEL, 0, 0); } void ModifyData(HWND hDlg, int selection) { TCHAR name[20], phone[20], birth[20], sex[20]; HWND hList, hCombo; int count; hCombo = GetDlgItem(hDlg, IDC_COMBO1); hList = GetDlgItem(hDlg, IDC_LIST2); GetDlgItemText(hDlg, IDC_EDIT1, name, 20); if (_tcscmp(name, _T("")) == 0) return; GetDlgItemText(hDlg, IDC_EDIT2, phone, 20); GetDlgItemText(hDlg, IDC_COMBO1, birth, 10); ListView_SetItemText(hList, selection, 0, name); ListView_SetItemText(hList, selection, 1, phone); if (SEX == 1) { ListView_SetItemText(hList, selection, 2, _T("여자"), 20); } else if (SEX == 2) { ListView_SetItemText(hList, selection, 2, _T("남자"), 20); } //ListView_SetItemText(hList, selection, 2, SEX == 1 ? _T("여자") : _T("남자")); ListView_SetItemText(hList, selection, 3, birth); SetDlgItemText(hDlg, IDC_EDIT1, name); SetDlgItemText(hDlg, IDC_EDIT2, phone); count = SendMessage(hCombo, CB_FINDSTRING, 0, (LPARAM)birth); SendMessage(hCombo, CB_SETCURSEL, count, 0); } | cs |
'WIN32 API' 카테고리의 다른 글
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 6장 12번 풀이 (0) | 2017.11.03 |
---|---|
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 6장 11번 풀이 (0) | 2017.11.03 |
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 6장 8번 풀이 (0) | 2017.11.03 |
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 6장 7번 풀이 (0) | 2017.11.03 |
[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 6장 6번 풀이 (0) | 2017.11.03 |