오다기리 박의 알고리즘 노트

[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 7장 11번 풀이 본문

WIN32 API

[핵심 API로 배우는 윈도우프로그래밍(강경우, 한빛아카데미)] 7장 11번 풀이

오다기리 박 2017. 11. 3. 22:04
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
#include <Windows.h>
#include<tchar.h>
#include<string.h>
#include<math.h>
#include<Richedit.h>
#include"resource.h"
//#pragma comment(linker,"/entry:WinMainCRTStartup /subsystem:console")
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
HINSTANCE hInst;
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    HWND hwnd;
    MSG msg;
    WNDCLASS WndClass;
    HINSTANCE hRichedit;
    
    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 = MAKEINTRESOURCE(IDR_MENU3);
    WndClass.lpszClassName = _T("Window Class Name");
 
    RegisterClass(&WndClass);
    hRichedit = LoadLibrary(_T("RICHED20.DLL"));
    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, NULL00))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    FreeLibrary(hRichedit);
    return (int)msg.wParam;
}
#define IDC_RICHEDIT 100
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    static HWND hRichedit;
    RECT rect;
    CHOOSEFONT FONT;
    static LOGFONT logfont;
    CHARFORMAT cf;
 
    switch (iMsg)
    {
    case WM_CREATE:
        GetClientRect(hwnd, &rect);
        hRichedit = CreateWindow(_T("RichEdit20W"), _T("RichEdit Control Font"),
            WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | WS_BORDER,
            00, rect.right, rect.bottom, hwnd, (HMENU)IDC_RICHEDIT, hInst, 0);
        break;
    case WM_SIZE:
        GetClientRect(hwnd, &rect);
        MoveWindow(hRichedit, 00, rect.right, rect.bottom, TRUE);
        break;
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case ID_FONT:
            memset(&FONT, 0sizeof(CHOOSEFONT));
            FONT.lStructSize = sizeof(CHOOSEFONT);
            FONT.hwndOwner = hwnd;
            FONT.iPointSize = 100;
            FONT.Flags = CF_EFFECTS | CF_SCREENFONTS;
            FONT.lpLogFont = &logfont;
            if (ChooseFont(&FONT) != 0)
            {
                cf.cbSize = sizeof(CHARFORMAT);
                cf.dwMask = CFM_FACE | CFM_SIZE | CFM_COLOR;
                cf.yHeight = FONT.iPointSize * 2;
                cf.crTextColor = FONT.rgbColors;
                _tcscpy_s(cf.szFaceName, logfont.lfFaceName);
                SendMessage(hRichedit, EM_SETCHARFORMAT, (WPARAM)(UINT)SCF_SELECTION, (LPARAM)&cf);
            }
            break;
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
 
    }
    return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
cs