ReactOS 0.4.16-dev-92-g0c2cdca
carets.c
Go to the documentation of this file.
1#include <windows.h>
2#include <stdio.h>
3#include "resource.h"
4
5static int CaretWidth = 2;
6static int CaretHeight = 16;
7static int CharWidth = 10;
8static int CharHeight = 16;
10
12
14
15int WINAPI
17 HINSTANCE hPrevInstance,
18 LPSTR lpszCmdLine,
19 int nCmdShow)
20{
21 WNDCLASS wc;
22 MSG msg;
23 HWND hWnd;
24
26
27 wc.lpszClassName = "CaretTestClass";
33 wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
34 wc.lpszMenuName = NULL;
35 wc.cbClsExtra = 0;
36 wc.cbWndExtra = 0;
37 if (RegisterClass(&wc) == 0)
38 {
39 fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
40 GetLastError());
41 return(1);
42 }
43
45 "Caret Test",
47 0,
48 0,
49 200,
50 250,
51 NULL,
52 NULL,
54 NULL);
55 if (hWnd == NULL)
56 {
57 fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
58 GetLastError());
59 return(1);
60 }
61
62 ShowWindow(hWnd, nCmdShow);
63
64 while(GetMessage(&msg, NULL, 0, 0))
65 {
68 }
69
70 return msg.wParam;
71}
72
74{
75 POINT pt;
76 switch(msg)
77 {
78 case WM_ACTIVATE:
79 switch(LOWORD(wParam))
80 {
81 case WA_ACTIVE:
82 case WA_CLICKACTIVE:
83 if(!ShowCaret(hWnd))
84 DbgPrint("ShowCaret(0x%x)\n", hWnd);
85 break;
86 case WA_INACTIVE:
87 if(!HideCaret(hWnd))
88 DbgPrint("HideCaret(0x%x)\n", hWnd);
89 break;
90 }
91 break;
92
93 case WM_KEYDOWN:
94 if(!GetCaretPos(&pt))
95 {
96 DbgPrint("GetCaretPos() failed!\n");
97 break;
98 }
99 switch(wParam)
100 {
101 case VK_LEFT:
102 pt.x -= CharWidth;
103 break;
104 case VK_UP:
105 pt.y -= CharHeight;
106 break;
107 case VK_RIGHT:
108 pt.x += CharWidth;
109 break;
110 case VK_DOWN:
111 pt.y += CharHeight;
112 break;
113 }
114 if(!SetCaretPos(pt.x, pt.y))
115 DbgPrint("SetCaretPos() failed!\n");
116 break;
117
118 case WM_RBUTTONDOWN:
119 if(!CreateCaret(hWnd, CaretBitmap, 0, 0))
120 DbgPrint("CreateCaret() for window 0x%x failed!\n", hWnd);
121 else
122 if(!ShowCaret(hWnd))
123 DbgPrint("ShowCaret(0x%x)\n", hWnd);
124 break;
125
126 case WM_LBUTTONDOWN:
128 DbgPrint("CreateCaret() for window 0x%x failed!\n", hWnd);
129 else
130 if(!ShowCaret(hWnd))
131 DbgPrint("ShowCaret(0x%x)\n", hWnd);
132 break;
133
134 case WM_CREATE:
136 DbgPrint("CreateCaret() for window 0x%x failed!\n", hWnd);
137 else
138 if(!SetCaretPos(1, 1))
139 DbgPrint("SetCaretPos(%i, %i) failed!\n", 1, 1);
140 break;
141
142 case WM_DESTROY:
143 if(!DestroyCaret())
144 DbgPrint("DestroyCaret() failed!\n");
146 break;
147
148 default:
150 }
151 return 0;
152}
#define __cdecl
Definition: accygwin.h:79
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
static int CaretHeight
Definition: carets.c:6
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: carets.c:16
static int CharWidth
Definition: carets.c:7
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: carets.c:73
static int CharHeight
Definition: carets.c:8
static int CaretWidth
Definition: carets.c:5
static HBITMAP CaretBitmap
Definition: carets.c:9
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define CALLBACK
Definition: compat.h:35
#define pt(x, y)
Definition: drawing.c:79
#define DbgPrint
Definition: hal.h:12
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define IDB_CARET
Definition: resource.h:1
static HBITMAP
Definition: button.c:44
unsigned int UINT
Definition: ndis.h:50
CHAR * PCH
Definition: ntbasedef.h:391
#define LOWORD(l)
Definition: pedump.c:82
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define DefWindowProc
Definition: ros2win.h:31
HBRUSH hbrBackground
Definition: winuser.h:3173
HICON hIcon
Definition: winuser.h:3171
HINSTANCE hInstance
Definition: winuser.h:3170
HCURSOR hCursor
Definition: winuser.h:3172
int cbWndExtra
Definition: winuser.h:3169
UINT style
Definition: winuser.h:3166
LPCSTR lpszMenuName
Definition: winuser.h:3174
LPCSTR lpszClassName
Definition: winuser.h:3175
WNDPROC lpfnWndProc
Definition: winuser.h:3167
int cbClsExtra
Definition: winuser.h:3168
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI ShowCaret(_In_opt_ HWND)
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:921
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define LoadBitmap
Definition: winuser.h:5823
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define VK_UP
Definition: winuser.h:2228
#define WA_INACTIVE
Definition: winuser.h:2625
#define WM_LBUTTONDOWN
Definition: winuser.h:1779
#define IDI_APPLICATION
Definition: winuser.h:704
#define CreateWindow
Definition: winuser.h:5766
#define WM_ACTIVATE
Definition: winuser.h:1615
#define WM_RBUTTONDOWN
Definition: winuser.h:1782
#define GetMessage
Definition: winuser.h:5802
#define LoadIcon
Definition: winuser.h:5825
BOOL WINAPI GetCaretPos(_Out_ LPPOINT)
#define LoadCursor
Definition: winuser.h:5824
#define WA_ACTIVE
Definition: winuser.h:2626
#define VK_LEFT
Definition: winuser.h:2227
#define VK_RIGHT
Definition: winuser.h:2229
#define VK_DOWN
Definition: winuser.h:2230
#define WA_CLICKACTIVE
Definition: winuser.h:2627
#define RegisterClass
Definition: winuser.h:5848
#define WM_DESTROY
Definition: winuser.h:1612
#define WM_KEYDOWN
Definition: winuser.h:1718
#define DispatchMessage
Definition: winuser.h:5777
BOOL WINAPI SetCaretPos(_In_ int, _In_ int)
BOOL WINAPI CreateCaret(_In_ HWND, _In_opt_ HBITMAP, _In_ int, _In_ int)
BOOL WINAPI DestroyCaret(void)
Definition: caret.c:35
BOOL WINAPI HideCaret(_In_opt_ HWND)
char * LPSTR
Definition: xmlstorage.h:182
const CHAR * LPCTSTR
Definition: xmlstorage.h:193