◎ Part 3: CreateControls 함수 (UI 생성)
| // ------------ CreateControls (WM_CREATE 분리) ------------ // ============ 텍스트 교체 함수 ============ void replaceTextInInput(HWND hInputEdit, const char* findText, const char* replaceText) { if (!findText || !replaceText || strlen(findText) == 0) { MessageBoxA(NULL, "Please enter text to find.", "Error", MB_OK | MB_ICONWARNING); return; } static char input[MAX_BUFFER] = { 0 }; static char output[MAX_BUFFER] = { 0 }; GetWindowTextA(hInputEdit, input, MAX_BUFFER - 1); if (strlen(input) == 0) { MessageBoxA(NULL, "Input is empty.", "Error", MB_OK | MB_ICONWARNING); return; } output[0] = '\0'; char* src = input; char* dst = output; size_t findLen = strlen(findText); size_t replaceLen = strlen(replaceText); int replaceCount = 0; while (*src) { // findText와 일치하는지 확인 if (strncmp(src, findText, findLen) == 0) { // 버퍼 오버플로우 체크 if (dst - output + replaceLen >= MAX_BUFFER - 1) { MessageBoxA(NULL, "Output buffer overflow!", "Error", MB_OK | MB_ICONERROR); return; } // replaceText로 교체 strcpy_s(dst, MAX_BUFFER - (dst - output), replaceText); dst += replaceLen; src += findLen; replaceCount++; } else { // 버퍼 오버플로우 체크 if (dst - output >= MAX_BUFFER - 1) { MessageBoxA(NULL, "Output buffer overflow!", "Error", MB_OK | MB_ICONERROR); return; } *dst++ = *src++; } } *dst = '\0'; if (replaceCount > 0) { SetWindowTextA(hInputEdit, output); char msg[128]; sprintf_s(msg, sizeof(msg), "Replaced %d occurrence(s).", replaceCount); MessageBoxA(NULL, msg, "Success", MB_OK | MB_ICONINFORMATION); } else { MessageBoxA(NULL, "Text not found.", "Info", MB_OK | MB_ICONINFORMATION); } } void CreateControls(HWND hwnd) { HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); // Input label HWND hStatic1 = CreateWindowW(L"STATIC", L"Input", WS_CHILD | WS_VISIBLE, 10, 10, 100, 20, hwnd, NULL, NULL, NULL); if (hStatic1 && hFont) { SendMessage(hStatic1, WM_SETFONT, (WPARAM)hFont, TRUE); } // Input edit hInputEdit = CreateWindowExW( WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL, 10, 30, 405, 230, hwnd, (HMENU)(INT_PTR)IDC_INPUT_TEXT, NULL, NULL); if (hInputEdit && hFont) { SendMessage(hInputEdit, WM_SETFONT, (WPARAM)hFont, TRUE); } // Input 오른쪽에 "..." 버튼 추가 HWND hFileButton = CreateWindowW(L"BUTTON", L"...", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 47, 9, 20, 15, // x=47, 크기 20x15으로 변경 hwnd, (HMENU)(INT_PTR)IDC_FILE_SELECT, NULL, NULL); if (hFileButton && hFont) { SendMessage(hFileButton, WM_SETFONT, (WPARAM)hFont, TRUE); } // 텍스트 교체 UI 추가 (... 버튼 옆) int replaceX = 75; int replaceY = 9; // Text A 입력란 hTextA = CreateWindowExW( WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, replaceX, replaceY, 80, 20, hwnd, (HMENU)(INT_PTR)IDC_TEXT_A, NULL, NULL); if (hTextA && hFont) { SendMessage(hTextA, WM_SETFONT, (WPARAM)hFont, TRUE); SendMessage(hTextA, EM_SETLIMITTEXT, 10, 0); // 최대 10자 } // "->" 라벨 HWND hArrowLabel = CreateWindowW(L"STATIC", L"→", WS_CHILD | WS_VISIBLE | SS_CENTER, replaceX + 85, replaceY, 20, 20, hwnd, NULL, NULL, NULL); if (hArrowLabel && hFont) { SendMessage(hArrowLabel, WM_SETFONT, (WPARAM)hFont, TRUE); } // Text B 입력란 hTextB = CreateWindowExW( WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, replaceX + 110, replaceY, 80, 20, hwnd, (HMENU)(INT_PTR)IDC_TEXT_B, NULL, NULL); if (hTextB && hFont) { SendMessage(hTextB, WM_SETFONT, (WPARAM)hFont, TRUE); SendMessage(hTextB, EM_SETLIMITTEXT, 10, 0); // 최대 10자 } // GO 버튼 HWND hReplaceGo = CreateWindowW(L"BUTTON", L"GO", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, replaceX + 195, replaceY, 35, 20, hwnd, (HMENU)(INT_PTR)IDC_REPLACE_GO, NULL, NULL); if (hReplaceGo && hFont) { SendMessage(hReplaceGo, WM_SETFONT, (WPARAM)hFont, TRUE); } // Output label HWND hStatic2 = CreateWindowW(L"STATIC", L"Output", WS_CHILD | WS_VISIBLE, 10, 270, 100, 20, hwnd, NULL, NULL, NULL); if (hStatic2 && hFont) { SendMessage(hStatic2, WM_SETFONT, (WPARAM)hFont, TRUE); } // Output edit (너비 동일하게 조정) hOutputEdit = CreateWindowExW( WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY, 10, 290, 405, 230, // 너비를 405로 유지 hwnd, (HMENU)(INT_PTR)IDC_OUTPUT_TEXT, NULL, NULL); if (hOutputEdit && hFont) { SendMessage(hOutputEdit, WM_SETFONT, (WPARAM)hFont, TRUE); } // Group box (위치 조정: x=425로 이동) HWND hGroupBox = CreateWindowW(L"BUTTON", L"Conversion Options", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 425, 10, 235, 420, hwnd, NULL, NULL, NULL); if (hGroupBox && hFont) { SendMessage(hGroupBox, WM_SETFONT, (WPARAM)hFont, TRUE); } int x = 435, y = 30, w = 105, h = 24, gap = 4; // Row 1 HWND hBtn1 = CreateWindowW(L"BUTTON", L"Text to Hex", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_HEX, NULL, NULL); if (hBtn1 && hFont) SendMessage(hBtn1, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn2 = CreateWindowW(L"BUTTON", L"Hex to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_HEX_TO_TEXT, NULL, NULL); if (hBtn2 && hFont) SendMessage(hBtn2, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 2 HWND hBtn3 = CreateWindowW(L"BUTTON", L"Dec to Hex", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_DEC_TO_HEX, NULL, NULL); if (hBtn3 && hFont) SendMessage(hBtn3, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn4 = CreateWindowW(L"BUTTON", L"Hex to Dec", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_HEX_TO_DEC, NULL, NULL); if (hBtn4 && hFont) SendMessage(hBtn4, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 3 HWND hBtn5 = CreateWindowW(L"BUTTON", L"Text to Dec", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_DEC, NULL, NULL); if (hBtn5 && hFont) SendMessage(hBtn5, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn6 = CreateWindowW(L"BUTTON", L"Dec to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_DEC_TO_TEXT, NULL, NULL); if (hBtn6 && hFont) SendMessage(hBtn6, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 4 HWND hBtn7 = CreateWindowW(L"BUTTON", L"Dec to Octal", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_DEC_TO_OCTAL, NULL, NULL); if (hBtn7 && hFont) SendMessage(hBtn7, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn8 = CreateWindowW(L"BUTTON", L"Octal to Dec", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_OCTAL_TO_DEC, NULL, NULL); if (hBtn8 && hFont) SendMessage(hBtn8, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 5 HWND hBtn9 = CreateWindowW(L"BUTTON", L"Text to UTF7", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_UTF7, NULL, NULL); if (hBtn9 && hFont) SendMessage(hBtn9, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn10 = CreateWindowW(L"BUTTON", L"UTF7 to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_UTF7_TO_TEXT, NULL, NULL); if (hBtn10 && hFont) SendMessage(hBtn10, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 6 HWND hBtn11 = CreateWindowW(L"BUTTON", L"Hex to UCS2", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_HEX_TO_UCS2, NULL, NULL); if (hBtn11 && hFont) SendMessage(hBtn11, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn12 = CreateWindowW(L"BUTTON", L"UCS2 to Hex", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_UCS2_TO_HEX, NULL, NULL); if (hBtn12 && hFont) SendMessage(hBtn12, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 7 HWND hBtn13 = CreateWindowW(L"BUTTON", L"Text to Binary", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_BINARY, NULL, NULL); if (hBtn13 && hFont) SendMessage(hBtn13, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn14 = CreateWindowW(L"BUTTON", L"Binary to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_BINARY_TO_TEXT, NULL, NULL); if (hBtn14 && hFont) SendMessage(hBtn14, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 8 HWND hBtn15 = CreateWindowW(L"BUTTON", L"Escape", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_ESCAPE, NULL, NULL); if (hBtn15 && hFont) SendMessage(hBtn15, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn16 = CreateWindowW(L"BUTTON", L"Unescape", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_UNESCAPE, NULL, NULL); if (hBtn16 && hFont) SendMessage(hBtn16, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 9 HWND hBtn17 = CreateWindowW(L"BUTTON", L"Encode HTML", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_ENCODE_HTML, NULL, NULL); if (hBtn17 && hFont) SendMessage(hBtn17, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn18 = CreateWindowW(L"BUTTON", L"Decode HTML", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_DECODE_HTML, NULL, NULL); if (hBtn18 && hFont) SendMessage(hBtn18, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 10 HWND hBtn19 = CreateWindowW(L"BUTTON", L"Text to Base64", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_BASE64, NULL, NULL); if (hBtn19 && hFont) SendMessage(hBtn19, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn20 = CreateWindowW(L"BUTTON", L"Base64 to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_BASE64_TO_TEXT, NULL, NULL); if (hBtn20 && hFont) SendMessage(hBtn20, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 11 HWND hBtn21 = CreateWindowW(L"BUTTON", L"Hex to Base64", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_HEX_TO_BASE64, NULL, NULL); if (hBtn21 && hFont) SendMessage(hBtn21, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn22 = CreateWindowW(L"BUTTON", L"Base64 to Hex", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_BASE64_TO_HEX, NULL, NULL); if (hBtn22 && hFont) SendMessage(hBtn22, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 12 HWND hBtn23 = CreateWindowW(L"BUTTON", L"IP to Dec", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_IP_TO_DEC, NULL, NULL); if (hBtn23 && hFont) SendMessage(hBtn23, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn24 = CreateWindowW(L"BUTTON", L"Dec to IP", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_DEC_TO_IP, NULL, NULL); if (hBtn24 && hFont) SendMessage(hBtn24, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 13 HWND hBtn25 = CreateWindowW(L"BUTTON", L"IP to Hex", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_IP_TO_HEX, NULL, NULL); if (hBtn25 && hFont) SendMessage(hBtn25, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn26 = CreateWindowW(L"BUTTON", L"Hex to IP", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_HEX_TO_IP, NULL, NULL); if (hBtn26 && hFont) SendMessage(hBtn26, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; // Row 14 HWND hBtn27 = CreateWindowW(L"BUTTON", L"Text to URL", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_URL, NULL, NULL); if (hBtn27 && hFont) SendMessage(hBtn27, WM_SETFONT, (WPARAM)hFont, TRUE); HWND hBtn28 = CreateWindowW(L"BUTTON", L"URL to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_URL_TO_TEXT, NULL, NULL); if (hBtn28 && hFont) SendMessage(hBtn28, WM_SETFONT, (WPARAM)hFont, TRUE); // Utility buttons y = 440; HWND hBtn29 = CreateWindowW(L"BUTTON", L"Copy Output to Clipboard", WS_CHILD | WS_VISIBLE, 435, y, 200, h, hwnd, (HMENU)(INT_PTR)IDC_COPY_OUTPUT, NULL, NULL); if (hBtn29 && hFont) SendMessage(hBtn29, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; HWND hBtn30 = CreateWindowW(L"BUTTON", L"Copy Output to Input", WS_CHILD | WS_VISIBLE, 435, y, 200, h, hwnd, (HMENU)(INT_PTR)IDC_COPY_TO_INPUT, NULL, NULL); if (hBtn30 && hFont) SendMessage(hBtn30, WM_SETFONT, (WPARAM)hFont, TRUE); y += h + gap; HWND hBtn31 = CreateWindowW(L"BUTTON", L"Clear All", WS_CHILD | WS_VISIBLE, 435, y, 200, h, hwnd, (HMENU)(INT_PTR)IDC_CLEAR_ALL, NULL, NULL); if (hBtn31 && hFont) SendMessage(hBtn31, WM_SETFONT, (WPARAM)hFont, TRUE); } |
- 큰 스택 사용량을 CreateControls() 함수로 분리
| void CreateControls(HWND hwnd) { HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); |
- 기본 GUI 폰트 가져오기 (시스템 기본값).
- 모든 컨트롤에 동일한 폰트 적용.
- Input 영역 생성
| HWND hStatic1 = CreateWindowW(L"STATIC", L"Input", WS_CHILD | WS_VISIBLE, 10, 10, 100, 20, hwnd, NULL, NULL, NULL); if (hStatic1 && hFont) { SendMessage(hStatic1, WM_SETFONT, (WPARAM)hFont, TRUE); } |
- "Input" 레이블 생성.
- 위치: (10, 10), 크기: 100×20.
- SendMessage : 폰트 설정 메시지 전송.
| hInputEdit = CreateWindowExW( WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL, 10, 30, 400, 180, hwnd, (HMENU)(INT_PTR)IDC_INPUT_TEXT, NULL, NULL); |
- 입력 텍스트박스 생성.
- WS_EX_CLIENTEDGE : 테두리 스타일 (3D 효과).
- ES_MULTILINE : 여러 줄 입력 가능.
- ES_WANTRETURN : Enter 키로 줄바꿈 (실행이 아님).
- ES_AUTOVSCROLL : 자동 스크롤.
- 위치: (10, 30), 크기: 400×180.
- ID: IDC_INPUT_TEXT (101).
- Output 영역 생성
| hOutputEdit = CreateWindowExW( WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY, 10, 240, 400, 180, hwnd, (HMENU)(INT_PTR)IDC_OUTPUT_TEXT, NULL, NULL); |
- 출력 텍스트박스 (읽기 전용).
- ES_READONLY : 사용자가 수정할 수 없음.
- 변환 버튼들 생성
| int x = 430, y = 30, w = 105, h = 24, gap = 4; // Row 1 CreateWindowW(L"BUTTON", L"Text to Hex", WS_CHILD | WS_VISIBLE, x, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_TEXT_TO_HEX, NULL, NULL); CreateWindowW(L"BUTTON", L"Hex to Text", WS_CHILD | WS_VISIBLE, x + w + gap, y, w, h, hwnd, (HMENU)(INT_PTR)IDC_HEX_TO_TEXT, NULL, NULL); y += h + gap; |
- 변수 x, y, w, h, gap로 레이아웃 계산
>> x = 430 : 오른쪽 시작 위치.
>> y = 30 : 첫 행 위치.
>> w = 105 : 버튼 너비.
>> h = 24 : 버튼 높이.
>> gap = 4 : 버튼 간격.
- 첫 번째 버튼: (430, 30) 위치, 105×24 크기.
- 두 번째 버튼: (430 + 105 + 4, 30) = (539, 30) 위치 (옆에 배치).
- y += h + gap : 다음 행으로 이동 (24 + 4 = 28픽셀 아래).
- 이 패턴을 11개 행(각 2개 버튼)으로 반복
| Row 1: [Text to Hex] [Hex to Text] Row 2: [Dec to Hex] [Hex to Dec] Row 3: [Text to Dec] [Dec to Text] ... Row 11: [Hex to Base64] [Base64 to Hex] |
- 유틸리티 버튼들
| y = 350; CreateWindowW(L"BUTTON", L"Copy Output to Clipboard", WS_CHILD | WS_VISIBLE, 435, y, 200, h, hwnd, (HMENU)(INT_PTR)IDC_COPY_OUTPUT, NULL, NULL); y += h + gap; CreateWindowW(L"BUTTON", L"Copy Output to Input", WS_CHILD | WS_VISIBLE, 435, y, 200, h, hwnd, (HMENU)(INT_PTR)IDC_COPY_TO_INPUT, NULL, NULL); y += h + gap; CreateWindowW(L"BUTTON", L"Clear All", WS_CHILD | WS_VISIBLE, 435, y, 200, h, hwnd, (HMENU)(INT_PTR)IDC_CLEAR_ALL, NULL, NULL); |
- 세 개의 큰 버튼 (200픽셀 너비).
- y = 350 : 변환 버튼들 아래에 배치.
'IT > Coding' 카테고리의 다른 글
| [C언어] Data Conversion Tool - RawVera #04 (0) | 2025.12.16 |
|---|---|
| [C언어] Data Conversion Tool - RawVera #02 (0) | 2025.12.14 |
| [C언어] Data Conversion Tool - RawVera #01 (1) | 2025.12.14 |
| Python 3.14의 주요 개선사항 (0) | 2025.10.09 |
| [Python] 파이썬 2,3 가상환경 사용법 완전 가이드 (0) | 2025.10.03 |
