OSDN Git Service

fix typo in readme.txt
[yamy/yamy.git] / focus.cpp
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // focus.cpp
3
4
5 #include "focus.h"
6 #include "windowstool.h"
7
8
9 ///
10 static LRESULT CALLBACK WndProc(
11   HWND i_hwnd, UINT i_message, WPARAM i_wParam, LPARAM i_lParam)
12 {
13   switch (i_message)
14   {
15     case WM_KEYDOWN:
16     case WM_SYSKEYDOWN:
17     case WM_KEYUP:
18     case WM_SYSKEYUP:
19       SendMessage(GetParent(i_hwnd), WM_APP_notifyVKey, i_wParam, i_lParam);
20       return 0;
21     case WM_CHAR:
22     case WM_DEADCHAR:
23       return 0;
24     case WM_LBUTTONDOWN:
25     {
26       SetFocus(i_hwnd);
27       return 0;
28     }
29     case WM_SETFOCUS:
30     {
31       RECT rc;
32       GetClientRect(i_hwnd, &rc);
33       CreateCaret(i_hwnd, reinterpret_cast<HBITMAP>(NULL), 2,
34                   rcHeight(&rc) / 2);
35       ShowCaret(i_hwnd);
36       SetCaretPos(rcWidth(&rc) / 2, rcHeight(&rc) / 4);
37       SendMessage(GetParent(i_hwnd), WM_APP_notifyFocus,
38                   TRUE, (LPARAM)i_hwnd);
39       return 0;
40     }
41     case WM_KILLFOCUS:
42     {
43       HideCaret(i_hwnd);
44       DestroyCaret();
45       SendMessage(GetParent(i_hwnd), WM_APP_notifyFocus,
46                   FALSE, (LPARAM)i_hwnd);
47       return 0;
48     }
49     case WM_GETDLGCODE:
50       return DLGC_WANTALLKEYS;
51   }
52   return DefWindowProc(i_hwnd, i_message, i_wParam, i_lParam);
53 }
54
55
56 ATOM Register_focus()
57 {
58   WNDCLASS wc;
59   wc.style         = CS_HREDRAW | CS_VREDRAW;
60   wc.lpfnWndProc   = WndProc;
61   wc.cbClsExtra    = 0;
62   wc.cbWndExtra    = 0;
63   wc.hInstance     = g_hInst;
64   wc.hIcon         = NULL;
65   wc.hCursor       = LoadCursor(NULL, IDC_IBEAM);
66   wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
67   wc.lpszMenuName  = NULL;
68   wc.lpszClassName = _T("mayuFocus");
69   return RegisterClass(&wc);
70 }