캐럿이란, 우리가 윈도우스에서 글을 사용할때, 해당 글의 위치를 표시하는 것이다.


 대표적으로 메모장이나 그런 것이 있다.


 이걸 이용하면, 메모장처럼 출력하는 부분을 표현 할 수도 있게 된다.


 현재, 설정한 것에서는 내용물을 표시하는 것까지만 하고 메모장을 표현하는게 아닌 예제이다.


 이것과 함께 키보드의 특수 키까지 표현을 하도록 만든다면, 메모장을 간단하게 제작이 가능할 것이다.


 

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
#include <stdio.h>
#include <stdlib.h>
 
#include <tchar.h>
#include <windows.h>
 
#include <string.h>
 
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
 
WNDCLASS WndClass;
 
int numbers = 0;
 
int WINAPI WinMain(HINSTANCE hInstance,
            HINSTANCE hPrevInstance,
            LPSTR lpszCmdParam,
            int nCmdShow)
{
    HWND hWnd;
    MSG Message;
    g_hInst = hInstance;
 
    WndClass.cbClsExtra=0;
    WndClass.cbWndExtra=0;
    WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
    WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    WndClass.hInstance=hInstance;
    WndClass.lpfnWndProc=(WNDPROC)WndProc;
    WndClass.lpszClassName="ApiBase";
    WndClass.lpszMenuName=NULL;
    WndClass.style=CS_HREDRAW|CS_VREDRAW;
 
    RegisterClass(&WndClass);
    
    hWnd = CreateWindow("ApiBase",
                        "Test",
                        WS_OVERLAPPEDWINDOW,
                        10,// X
                        100,// Y
                        400,// Width
                        400,// Height
                        NULL,
                        (HMENU)NULL,
                        hInstance,
                        NULL);
 
                        
    ShowWindow(hWnd,nCmdShow);
    
    while(GetMessage(&Message,0,0,0))
    {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
    }
    
    return Message.wParam;
}
 
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{    
    HDC hdc;
    PAINTSTRUCT ps;
    static char strChar[MAX_PATH];
    int nlen = 0;
    static int pos = 0;
    SIZE size;
    
    switch(iMessage)
    {
        case WM_CREATE:
            strcpy(strChar, "");
            break;
        case WM_CHAR:
            //문자 크기 설정/내용 추가.
            nlen = strlen(strChar);
            strChar[nlen] = (char)wParam;
            strChar[nlen+1]=0;
            
            //문자 출력.
            pos++;
            hdc = GetDC(hWnd);
            GetTextExtentPoint(hdc, strChar, pos, &size);
            ReleaseDC(hWnd, hdc);
            
            //캐럿 위치 조절.
            SetCaretPos(size.cx + 100100);
            
            //다시 그리기 설정.
            InvalidateRect(hWnd, NULL, FALSE);
            break;
        case WM_SETFOCUS:
            hdc = GetDC(hWnd);
            CreateCaret(hWnd, NULL214); // 캐럿 생성
            ShowCaret(hWnd); // 캐럿 보이기
            SetCaretPos(100100); // 캐럿의 위치 설정
            break;
        case WM_KILLFOCUS:
            HideCaret(hWnd); // 캐럿 숨기기
            DestroyCaret(); // 캐럿 파괴
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            TextOut(hdc, 100100, strChar, strlen(strChar));
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    }
    return DefWindowProc(hWnd,iMessage,wParam, lParam);
}
 
 
cs


Posted by JunkMam
,