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 |
// Win32Project3.cpp : 응용 프로그램에 대한 진입점을 정의합니다. // #include “stdafx.h” #include “Win32Project3.h” #define MAX_LOADSTRING 100 // 전역 변수: HINSTANCE hInst; // 현재 인스턴스입니다. HWND hEditWnd; //Edit 핸들 TCHAR szTitle[MAX_LOADSTRING]; // 제목 표시줄 텍스트입니다. TCHAR szWindowClass[MAX_LOADSTRING]; // 기본 창 클래스 이름입니다. // 이 코드 모듈에 들어 있는 함수의 정방향 선언입니다. ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 여기에 코드를 입력합니다. MSG msg; HACCEL hAccelTable; // 전역 문자열을 초기화합니다. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_WIN32PROJECT3, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 응용 프로그램 초기화를 수행합니다. if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT3)); // 기본 메시지 루프입니다. while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } // // 함수: MyRegisterClass() // // 목적: 창 클래스를 등록합니다. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT3)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32PROJECT3); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); } // // 함수: InitInstance(HINSTANCE, int) // // 목적: 인스턴스 핸들을 저장하고 주 창을 만듭니다. // // 설명: // // 이 함수를 통해 인스턴스 핸들을 전역 변수에 저장하고 // 주 프로그램 창을 만든 다음 표시합니다. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // 인스턴스 핸들을 전역 변수에 저장합니다. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // 함수: WndProc(HWND, UINT, WPARAM, LPARAM) // // 목적: 주 창의 메시지를 처리합니다. // // WM_COMMAND – 응용 프로그램 메뉴를 처리합니다. // WM_PAINT – 주 창을 그립니다. // WM_DESTROY – 종료 메시지를 게시하고 반환합니다. // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; BOOL fSystemMenu = (BOOL)HIWORD(lParam); UINT uPos = (UINT)LOWORD(lParam); HMENU hmenuPopup = (HMENU) wParam; switch (message) { case WM_CREATE: RECT Rect; GetClientRect(hWnd, (LPRECT)&Rect); hEditWnd = CreateWindow(TEXT(“Edit”), NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL | WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL , 0, 0, (Rect.right – Rect.left), (Rect.bottom – Rect.top), hWnd, NULL, hInst, NULL); if (!hEditWnd) { DestroyWindow(hWnd); return -1; } break; case WM_INITMENUPOPUP: if (fSystemMenu) break; if (uPos == 1) { BOOL bClip = FALSE, bSel = FALSE; DWORD dwSel; if (SendMessage(hEditWnd, EM_CANUNDO, 0, 0)) EnableMenuItem(hmenuPopup, ID_UNDO, MF_BYCOMMAND | MF_ENABLED); else EnableMenuItem(hmenuPopup, ID_UNDO, MF_BYCOMMAND | MF_GRAYED); if (OpenClipboard(hWnd)) { HANDLE hClipData; hClipData = GetClipboardData(CF_TEXT); if (hClipData) { bClip = TRUE; CloseClipboard(); } else bClip = FALSE; } EnableMenuItem(hmenuPopup, ID_PASTE, MF_BYCOMMAND | (bClip) ? MF_ENABLED : MF_GRAYED); dwSel = SendMessage(hEditWnd, EM_GETSEL, NULL, NULL); bSel = (LOWORD(dwSel) != HIWORD(dwSel)); EnableMenuItem(hmenuPopup, ID_COPY, MF_BYCOMMAND | (bSel) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(hmenuPopup, ID_CUT, MF_BYCOMMAND | (bSel) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(hmenuPopup, ID_DELETE, MF_BYCOMMAND | (bSel) ? MF_ENABLED : MF_GRAYED); } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 메뉴 선택을 구문 분석합니다. switch (wmId) { case ID_NEW: break; case ID_OPEN: break; case ID_SAVE: break; case ID_SAVEAS: break; case ID_PRINT: MessageBox(hWnd, TEXT(“명령이 구현 안됨”), TEXT(“Editor Sample”), MB_ICONASTERISK | MB_OK); break; case ID_UNDO: SendMessage(hEditWnd, WM_UNDO, 0, 0); break; case ID_CUT: SendMessage(hEditWnd, WM_CUT, 0, 0); break; case ID_COPY: SendMessage(hEditWnd, WM_COPY, 0, 0); break; case ID_PASTE: SendMessage(hEditWnd, WM_PASTE, 0, 0); break; case ID_DELETE: SendMessage(hEditWnd, WM_CLEAR, 0, 0); break; case IDC_WIN32PROJECT3: if (HIWORD(wParam) == EN_ERRSPACE) MessageBox(hWnd, TEXT(“메모리 부족”), TEXT(“Editor Sample”), MB_ICONHAND | MB_OK); break; case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_SETFOCUS: SetFocus(hEditWnd); break; case WM_SIZE: MoveWindow(hEditWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 여기에 그리기 코드를 추가합니다. EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // 정보 대화 상자의 메시지 처리기입니다. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; } |