#include "pch.h"
#include "framework.h"
#include "Ex_974p_ReadFile.h"
LPCTSTR MyClassName = TEXT("ReadFile");
HINSTANCE g_hInst{};
HWND hWndMain{};
TCHAR buf[1024]{};
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
HWND hWnd{};
MSG msg{};
WNDCLASSEXW wndclassexw{};
g_hInst = hInstance;
wndclassexw.lpfnWndProc = WndProc;
wndclassexw.hInstance = hInstance;
wndclassexw.lpszClassName = MyClassName;
wndclassexw.hIconSm = NULL;
wndclassexw.cbSize = sizeof(WNDCLASSEX);
wndclassexw.cbClsExtra = 0;
wndclassexw.cbWndExtra = 0;
wndclassexw.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclassexw.hIcon = LoadIconW(NULL, IDI_APPLICATION);
wndclassexw.hCursor = LoadCursorW(NULL, IDC_ARROW);
wndclassexw.lpszMenuName = NULL;
wndclassexw.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassExW(&wndclassexw);
hWnd = CreateWindowExW(NULL, MyClassName, MyClassName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessageW(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return((int)msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
HDC hdc{};
PAINTSTRUCT ps{};
HANDLE hFile{};
DWORD dwRead{};
RECT rt{};
switch (iMessage) {
case WM_LBUTTONDOWN:
hFile = CreateFile(L"Test.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
if (ReadFile(hFile, buf, 1024, &dwRead, NULL)) {
CloseHandle(hFile);
InvalidateRect(hWnd, NULL, TRUE);
}
}
return(0);
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
DrawText(hdc, buf, -1, &rt, DT_WORDBREAK);
EndPaint(hWnd, &ps);
return(0);
case WM_DESTROY:
PostQuitMessage(0);
return(0);
}
return(DefWindowProcW(hWnd, iMessage, wParam, lParam));
}
------------------------------------------------------------------------------------------------------------------------------------------
위 예제를 실행할 시 Test.txt파일을 읽어올 시 한글이 깨지는 현상이 나타납니다.
영어로 텍스트 파일을 저장해도 마찬가지로 깨짐니다.
텍스트 파일을 읽어들일 시 깨지지 않게 하기위해 어떻게 해야하는지 궁금합니다.

김민수
error code: 522
error code: 522
|
|