ReactOS  0.4.14-dev-342-gdc047f9
EmptyClipboard.c File Reference
#include "precomp.h"
Include dependency graph for EmptyClipboard.c:

Go to the source code of this file.

Functions

static int get_iwnd (HWND hWnd)
 
LRESULT CALLBACK ClipTestProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
static void RecordAndDispatch (MSG *pmsg)
 
static void FlushMessages ()
 
static DWORD WINAPI ClipThread (PVOID Parameter)
 
void TestMessages ()
 
void TestOwnership ()
 
 START_TEST (EmptyClipboard)
 

Variables

HWND hWnd1
 
HWND hWnd2
 
CRITICAL_SECTION CritSect
 
MSG_ENTRY EmptyClipboard_chain []
 

Function Documentation

◆ ClipTestProc()

LRESULT CALLBACK ClipTestProc ( HWND  hWnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 22 of file EmptyClipboard.c.

23 {
24  int iwnd = get_iwnd(hWnd);
25 
26  if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message))
28 
29  switch(message)
30  {
31  case WM_GETICON :
32  case WM_SETICON:
33  break;
35  Sleep(1000);
36  default:
38  RECORD_MESSAGE(iwnd, message, SENT, 0,0);
40  }
42 }
Definition: tftpd.h:59
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
CRITICAL_SECTION CritSect
HWND hWnd
Definition: settings.c:17
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
WPARAM wParam
Definition: combotst.c:138
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
#define DefWindowProc
Definition: ros2win.h:31
#define WM_USER
Definition: winuser.h:1877
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
static int get_iwnd(HWND hWnd)
Definition: msgtrace.h:6
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1850
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
LPARAM lParam
Definition: combotst.c:139

Referenced by TestMessages().

◆ ClipThread()

static DWORD WINAPI ClipThread ( PVOID  Parameter)
static

Definition at line 63 of file EmptyClipboard.c.

64 {
65  BOOL ret;
66 
67  hWnd2 = CreateWindowW(L"clipstest", L"clipstest", WS_OVERLAPPEDWINDOW,
68  20, 20, 300, 300, NULL, NULL, 0, NULL);
69 
70  /* Get ownership of the clipboard and record the messages we get */
72  ok (ret, "OpenClipboard failed\n");
73 
77 
78  ret = EmptyClipboard();
79  ok (ret, "EmptyClipboard failed\n");
80 
84 
85  ret = CloseClipboard();
86  ok (ret, "CloseClipboard failed\n");
87 
88  /* Record if we got any post messages */
89  FlushMessages();
90 
91  /* Force the parent thread out of its loop */
92  PostMessageW(hWnd1, WM_QUIT, 0, 0);
93 
94  return 0;
95 }
static void FlushMessages()
CRITICAL_SECTION CritSect
HWND hWnd2
#define WM_QUIT
Definition: winuser.h:1605
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4217
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1850
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
HWND hWnd1

Referenced by TestMessages().

◆ FlushMessages()

static void FlushMessages ( )
static

Definition at line 56 of file EmptyClipboard.c.

57 {
58  MSG msg;
59  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
61 }
static void RecordAndDispatch(MSG *pmsg)
#define PeekMessage
Definition: winuser.h:5731
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define msg(x)
Definition: auth_time.c:54
#define PM_REMOVE
Definition: winuser.h:1182

Referenced by ClipThread(), and TestMessages().

◆ get_iwnd()

static int get_iwnd ( HWND  hWnd)
static

Definition at line 15 of file EmptyClipboard.c.

16 {
17  if(hWnd == hWnd1) return 1;
18  else if(hWnd2 && hWnd == hWnd2) return 2;
19  else return 0;
20 }
HWND hWnd2
HWND hWnd
Definition: settings.c:17
HWND hWnd1

Referenced by ClipTestProc(), and RecordAndDispatch().

◆ RecordAndDispatch()

static void RecordAndDispatch ( MSG pmsg)
static

Definition at line 44 of file EmptyClipboard.c.

45 {
46  int iwnd = get_iwnd(pmsg->hwnd);
47  if(!(pmsg->message > WM_USER || !iwnd || IsDWmMsg(pmsg->message) || IseKeyMsg(pmsg->message)))
48  {
50  RECORD_MESSAGE(iwnd, pmsg->message, POST,0,0);
52  }
53  DispatchMessageA( pmsg );
54 }
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
CRITICAL_SECTION CritSect
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
Definition: msgtrace.h:7
#define WM_USER
Definition: winuser.h:1877
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
static int get_iwnd(HWND hWnd)
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by FlushMessages(), and TestMessages().

◆ START_TEST()

START_TEST ( EmptyClipboard  )

Definition at line 185 of file EmptyClipboard.c.

186 {
187  TestOwnership();
188  TestMessages();
189 }
void TestMessages()
void TestOwnership()

◆ TestMessages()

void TestMessages ( )

Definition at line 103 of file EmptyClipboard.c.

104 {
105  HANDLE hThread;
106  DWORD dwThread;
107  BOOL ret;
108  MSG msg;
109 
110  /* Initialize the test */
112 
113  RegisterSimpleClass(ClipTestProc, L"clipstest");
114 
115  hWnd2 = NULL;
116  hWnd1 = CreateWindowW(L"clipstest", L"clipstest", WS_OVERLAPPEDWINDOW,
117  20, 20, 300, 300, NULL, NULL, 0, NULL);
118  ok (hWnd1 != NULL, "CreateWindowW failed\n");
119 
120  EMPTY_CACHE();
121 
122  /* Get ownership of the clipboard and record the messages we get */
124  ok (ret, "OpenClipboard failed\n");
125 
126  ret = EmptyClipboard();
127  ok (ret, "EmptyClipboard failed\n");
128 
129  ret = CloseClipboard();
130  ok (ret, "CloseClipboard failed\n");
131 
132  /* Record posted messages */
133  FlushMessages();
135 
136  /* Create the child thread and record messages till we get the WM_QUIT */
137  hThread = CreateThread(NULL, 0, ClipThread, NULL, 0, &dwThread);
138 
139  while (GetMessage(&msg, 0, 0 ,0))
141 
143 
145 }
static void FlushMessages()
static void RecordAndDispatch(MSG *pmsg)
#define CloseHandle
Definition: compat.h:406
CRITICAL_SECTION CritSect
HWND hWnd2
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static DWORD WINAPI ClipThread(PVOID Parameter)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4217
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
#define COMPARE_CACHE(msg_chain)
Definition: msgtrace.h:57
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define EMPTY_CACHE()
Definition: msgtrace.h:59
#define ok(value,...)
Definition: atltest.h:57
#define GetMessage
Definition: winuser.h:5691
HANDLE hThread
Definition: wizard.c:27
#define msg(x)
Definition: auth_time.c:54
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
MSG_ENTRY empty_chain[]
Definition: msgtrace.c:20
LRESULT CALLBACK ClipTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HWND hWnd1
MSG_ENTRY EmptyClipboard_chain[]

Referenced by START_TEST().

◆ TestOwnership()

void TestOwnership ( )

Definition at line 147 of file EmptyClipboard.c.

148 {
149  BOOL ret;
150  HWND hWnd, hWndClipOwner;
151 
153  ok (ret, "OpenClipboard failed\n");
154 
155  ret = EmptyClipboard();
156  ok (ret, "EmptyClipboard failed\n");
157 
158  ret = CloseClipboard();
159  ok (ret, "CloseClipboard failed\n");
160 
161  hWndClipOwner = GetClipboardOwner();
162  ok (hWndClipOwner == NULL, "Expected NULL owner\n");
163 
164  hWnd = CreateWindowW(L"static", L"static", WS_OVERLAPPEDWINDOW, 20, 20, 300, 300, NULL, NULL, 0, NULL);
165  ok (hWnd != 0 , "CreateWindowW failed\n");
166 
168  ok (ret, "OpenClipboard failed\n");
169 
170  hWndClipOwner = GetClipboardOwner();
171  ok (hWndClipOwner == NULL, "Expected NULL owner\n");
172 
173  ret = EmptyClipboard();
174  ok (ret, "EmptyClipboard failed\n");
175 
176  ret = CloseClipboard();
177  ok (ret, "CloseClipboard failed\n");
178 
179  hWndClipOwner = GetClipboardOwner();
180  ok (hWndClipOwner == hWnd, "Expected hWnd owner\n");
181 
183 }
HWND hWnd
Definition: settings.c:17
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4217
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
int ret
static const WCHAR L[]
Definition: oid.c:1250
HWND WINAPI GetClipboardOwner(void)
Definition: ntwrapper.h:196
#define ok(value,...)
Definition: atltest.h:57
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
BOOL WINAPI OpenClipboard(_In_opt_ HWND)

Referenced by START_TEST().

Variable Documentation

◆ CritSect

◆ EmptyClipboard_chain

MSG_ENTRY EmptyClipboard_chain[]
Initial value:
={
{0,0}}
Definition: msgtrace.h:6
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1850

Definition at line 97 of file EmptyClipboard.c.

Referenced by TestMessages().

◆ hWnd1

HWND hWnd1

Definition at line 10 of file EmptyClipboard.c.

Referenced by ClipThread(), get_iwnd(), and TestMessages().

◆ hWnd2

HWND hWnd2

Definition at line 10 of file EmptyClipboard.c.

Referenced by ClipThread(), get_iwnd(), and TestMessages().