ReactOS  0.4.14-dev-98-gb0d4763
carets.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 #include "resource.h"
4 
5 static int CaretWidth = 2;
6 static int CaretHeight = 16;
7 static int CharWidth = 10;
8 static int CharHeight = 16;
10 
12 
14 
15 int 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";
30  wc.hInstance = hInstance;
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,
53  hInstance,
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");
145  PostQuitMessage(0);
146  break;
147 
148  default:
149  return DefWindowProc(hWnd, msg, wParam, lParam);
150  }
151  return 0;
152 }
#define IN
Definition: typedefs.h:38
#define DispatchMessage
Definition: winuser.h:5666
BOOL WINAPI TranslateMessage(_In_ const MSG *)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
#define CreateWindow
Definition: winuser.h:5655
#define __cdecl
Definition: accygwin.h:79
#define pt(x, y)
Definition: drawing.c:79
static int CaretHeight
Definition: carets.c:6
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
#define VK_LEFT
Definition: winuser.h:2199
int cbClsExtra
Definition: winuser.h:3139
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3145
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
#define VK_DOWN
Definition: winuser.h:2202
HBRUSH hbrBackground
Definition: winuser.h:3144
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
static int CaretWidth
Definition: carets.c:5
char * LPSTR
Definition: xmlstorage.h:182
#define COLOR_WINDOW
Definition: winuser.h:908
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: carets.c:16
WPARAM wParam
Definition: combotst.c:138
static HBITMAP CaretBitmap
Definition: carets.c:9
int cbWndExtra
Definition: winuser.h:3140
HINSTANCE hInstance
Definition: charmap.c:20
#define VK_UP
Definition: winuser.h:2200
BOOL WINAPI HideCaret(_In_opt_ HWND)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
BOOL WINAPI CreateCaret(_In_ HWND, _In_opt_ HBITMAP, _In_ int, _In_ int)
HCURSOR hCursor
Definition: winuser.h:3143
CHAR * PCH
Definition: ntbasedef.h:398
smooth NULL
Definition: ftsmooth.c:416
#define WM_KEYDOWN
Definition: winuser.h:1697
LONG_PTR LPARAM
Definition: windef.h:208
ULONG __cdecl DbgPrint(IN PCH Format, IN ...)
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
static int CharHeight
Definition: carets.c:8
#define LoadBitmap
Definition: winuser.h:5712
#define CS_VREDRAW
Definition: winuser.h:653
#define IDB_CARET
Definition: resource.h:1
#define WA_ACTIVE
Definition: winuser.h:2598
#define WINAPI
Definition: msvc.h:8
#define WA_CLICKACTIVE
Definition: winuser.h:2599
static int CharWidth
Definition: carets.c:7
LPCSTR lpszClassName
Definition: winuser.h:3146
#define LoadCursor
Definition: winuser.h:5713
#define VK_RIGHT
Definition: winuser.h:2201
UINT style
Definition: winuser.h:3137
#define WM_ACTIVATE
Definition: winuser.h:1594
HINSTANCE hInstance
Definition: winuser.h:3141
BOOL WINAPI DestroyCaret(void)
Definition: caret.c:35
unsigned int UINT
Definition: ndis.h:50
#define GetMessage
Definition: winuser.h:5691
WNDPROC lpfnWndProc
Definition: winuser.h:3138
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WM_CREATE
Definition: winuser.h:1590
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
unsigned int ULONG
Definition: retypes.h:1
FILE * stderr
BOOL WINAPI GetCaretPos(_Out_ LPPOINT)
BOOL WINAPI ShowCaret(_In_opt_ HWND)
#define WA_INACTIVE
Definition: winuser.h:2597
static HBITMAP
Definition: button.c:44
#define RegisterClass
Definition: winuser.h:5737
#define LoadIcon
Definition: winuser.h:5714
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
BOOL WINAPI SetCaretPos(_In_ int, _In_ int)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: carets.c:73
HICON hIcon
Definition: winuser.h:3142