ReactOS 0.4.15-dev-8236-g99f0937
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

static HWND hWnd1
 
static HWND hWnd2
 
static CRITICAL_SECTION CritSect
 
static 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}
static int get_iwnd(HWND hWnd)
static CRITICAL_SECTION CritSect
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
@ SENT
Definition: msgtrace.h:6
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
#define DefWindowProc
Definition: ros2win.h:31
Definition: tftpd.h:60
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define WM_DESTROYCLIPBOARD
Definition: winuser.h:1868
#define WM_USER
Definition: winuser.h:1895

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
79 ok (ret, "EmptyClipboard failed\n");
80
84
86 ok (ret, "CloseClipboard failed\n");
87
88 /* Record if we got any post messages */
90
91 /* Force the parent thread out of its loop */
93
94 return 0;
95}
static void FlushMessages()
static HWND hWnd1
static HWND hWnd2
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
@ MARKER
Definition: msgtrace.h:11
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
int ret
#define WM_QUIT
Definition: winuser.h:1623
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4316

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 msg(x)
Definition: auth_time.c:54
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define PM_REMOVE
Definition: winuser.h:1196
#define PeekMessage
Definition: winuser.h:5839

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}

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}
@ POST
Definition: msgtrace.h:7
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)

Referenced by FlushMessages(), and TestMessages().

◆ START_TEST()

START_TEST ( EmptyClipboard  )

Definition at line 185 of file EmptyClipboard.c.

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

◆ TestMessages()

void TestMessages ( )

Definition at line 103 of file EmptyClipboard.c.

104{
106 DWORD dwThread;
107 BOOL ret;
108 MSG msg;
109
110 /* Initialize the test */
112
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
127 ok (ret, "EmptyClipboard failed\n");
128
130 ok (ret, "CloseClipboard failed\n");
131
132 /* Record posted messages */
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}
LRESULT CALLBACK ClipTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
static DWORD WINAPI ClipThread(PVOID Parameter)
static MSG_ENTRY EmptyClipboard_chain[]
#define CloseHandle
Definition: compat.h:739
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:137
unsigned long DWORD
Definition: ntddk_ex.h:95
MSG_ENTRY empty_chain[]
Definition: msgtrace.c:20
#define EMPTY_CACHE()
Definition: msgtrace.h:59
#define COMPARE_CACHE(msg_chain)
Definition: msgtrace.h:57
HANDLE hThread
Definition: wizard.c:28
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
#define GetMessage
Definition: winuser.h:5799

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
156 ok (ret, "EmptyClipboard failed\n");
157
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
174 ok (ret, "EmptyClipboard failed\n");
175
177 ok (ret, "CloseClipboard failed\n");
178
179 hWndClipOwner = GetClipboardOwner();
180 ok (hWndClipOwner == hWnd, "Expected hWnd owner\n");
181
183}
HWND WINAPI GetClipboardOwner(void)
Definition: ntwrapper.h:196
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

Variable Documentation

◆ CritSect

CRITICAL_SECTION CritSect
static

Definition at line 12 of file EmptyClipboard.c.

Referenced by ClipTestProc(), ClipThread(), RecordAndDispatch(), and TestMessages().

◆ EmptyClipboard_chain

MSG_ENTRY EmptyClipboard_chain[]
static
Initial value:

Definition at line 97 of file EmptyClipboard.c.

Referenced by TestMessages().

◆ hWnd1

HWND hWnd1
static

Definition at line 10 of file EmptyClipboard.c.

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

◆ hWnd2

HWND hWnd2
static

Definition at line 10 of file EmptyClipboard.c.

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