ReactOS 0.4.15-dev-7942-gd23573b
multithrdwin.c
Go to the documentation of this file.
1#include <windows.h>
2#include <stdio.h>
3
5
6typedef struct _THRDCREATEWIN
7{
17
21
23
26{
27 MSG msg;
28 char caption[64];
29 PTHRDCREATEWIN cw = (PTHRDCREATEWIN)lpParameter;
30
31 sprintf(caption, cw->Caption, GetCurrentThreadId());
32
33 cw->Window = CreateWindow("MultiClass",
34 caption,
35 cw->Style | WS_VISIBLE,
36 cw->Position.x,
37 cw->Position.y,
38 cw->Size.cx,
39 cw->Size.cy,
40 (cw->Parent ? *(cw->Parent) : 0),
41 NULL,
43 NULL);
44
46
47 if(!cw->Window)
48 {
49 fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
50 GetLastError());
51 return 1;
52 }
53 CreateWindow("BUTTON","Sleep",WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|BS_PUSHBUTTON, 10, 10, 70, 23, cw->Window, (PVOID)1, hAppInstance, NULL);
57 while(GetMessage(&msg, NULL, 0, 0))
58 {
61 }
62
63 return 0;
64}
65
66int WINAPI
68 HINSTANCE hPrevInstance,
69 LPSTR lpszCmdLine,
70 int nCmdShow)
71{
72 WNDCLASS wc;
73 int i;
74 HANDLE Threads[3];
75
77
79 FALSE,
80 FALSE,
81 NULL);
82
84 {
85 fprintf(stderr, "Failed to create event (last error 0x%lX)\n",
86 GetLastError());
87 return 1;
88 }
89
90 wc.lpszClassName = "MultiClass";
96 wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
97 wc.lpszMenuName = NULL;
98 wc.cbClsExtra = 0;
99 wc.cbWndExtra = 0;
100 if (RegisterClass(&wc) == 0)
101 {
102 fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
103 GetLastError());
104 return(1);
105 }
106
107 wnds[0].Caption = "TopLevel1 (ThreadID: %d)";
108 wnds[0].Parent = NULL;
110 wnds[0].Position.x = wnds[0].Position.y = 0;
111 wnds[0].Size.cx = 320;
112 wnds[0].Size.cy = 240;
113
114 wnds[1].Caption = "Child1 of TopLevel1 (ThreadID: %d)";
115 wnds[1].Parent = &wnds[0].Window;
117 wnds[1].Position.x = 20;
118 wnds[1].Position.y = 120;
119 wnds[1].Size.cx = wnds[1].Size.cy = 240;
120
121 wnds[2].Caption = "TopLevel2 (ThreadID: %d)";
122 wnds[2].Parent = NULL;
124 wnds[2].Position.x = 400;
125 wnds[2].Position.y = 0;
126 wnds[2].Size.cx = 160;
127 wnds[2].Size.cy = 490;
128
129 for(i = 0; i < (sizeof(wnds) / sizeof(THRDCREATEWIN)); i++)
130 {
132 0,
134 &wnds[i],
135 0,
136 &wnds[i].ThreadId);
137 Threads[i] = wnds[i].hThread;
138 if(!wnds[i].hThread)
139 {
140 fprintf(stderr, "CreateThread #%i failed (last error 0x%lX)\n",
141 i, GetLastError());
142 return 1;
143 }
145 }
146
147 WaitForMultipleObjects(sizeof(Threads) / sizeof(HANDLE), &Threads[0], TRUE, INFINITE);
148
149 UnregisterClass("MultiClass", hInstance);
150
151 return 0;
152}
153
155{
156 PAINTSTRUCT ps;
157 HDC hDC;
158 RECT Client;
159 HBRUSH Brush;
160 DWORD_PTR Ret;
161
162 static COLORREF Colors[] =
163 {
164 RGB(0x00, 0x00, 0x00),
165 RGB(0x80, 0x00, 0x00),
166 RGB(0x00, 0x80, 0x00),
167 RGB(0x00, 0x00, 0x80),
168 RGB(0x80, 0x80, 0x00),
169 RGB(0x80, 0x00, 0x80),
170 RGB(0x00, 0x80, 0x80),
171 RGB(0x80, 0x80, 0x80),
172 RGB(0xff, 0x00, 0x00),
173 RGB(0x00, 0xff, 0x00),
174 RGB(0x00, 0x00, 0xff),
175 RGB(0xff, 0xff, 0x00),
176 RGB(0xff, 0x00, 0xff),
177 RGB(0x00, 0xff, 0xff),
178 RGB(0xff, 0xff, 0xff)
179 };
180 static unsigned CurrentColor = 0;
181
182 switch(msg)
183 {
184 case WM_PAINT:
185 hDC = BeginPaint(hWnd, &ps);
187 Brush = CreateSolidBrush(Colors[CurrentColor]);
190 CurrentColor++;
191 if (sizeof(Colors) / sizeof(Colors[0]) <= CurrentColor)
192 {
193 CurrentColor = 0;
194 }
195 EndPaint(hWnd, &ps);
196 break;
197
198 case WM_COMMAND:
199 switch(LOWORD(wParam))
200 {
201 case 1:
202 Sleep(20000);
203 break;
204 case 2:
205 case 3:
206 case 4:
207 if(SendMessageTimeout(wnds[LOWORD(wParam) - 2].Window, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 1000, &Ret))
208 {
209 DbgPrint("SendMessageTimeout() OK");
210 MessageBox(hWnd, "SendMessageTimeout() OK", NULL, 0);
211 }
212 else
213 {
215 {
216 DbgPrint("SendMessageTimeout() Timeout");
217 MessageBox(hWnd, "SendMessageTimeout() Timeout", NULL, 0);
218 }
219 else
220 {
221 DbgPrint("SendMessageTimeout() Failed");
222 MessageBox(hWnd, "SendMessageTimeout() Failed", NULL, 0);
223 }
224 }
225 break;
226 }
227 break;
228
229 case WM_DESTROY:
231 break;
232
233 default:
235 }
236
237 return 0;
238}
static HDC hDC
Definition: 3dtext.c:33
Colors
Definition: ansiprsr.h:4
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
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 TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
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
#define RGB(r, g, b)
Definition: precomp.h:71
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#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 sprintf(buf, format,...)
Definition: sprintf.c:55
static HDC
Definition: imagelist.c:92
DWORD WINAPI WindowThreadProc(LPVOID lpParameter)
Definition: multithrdwin.c:25
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: multithrdwin.c:67
struct _THRDCREATEWIN THRDCREATEWIN
struct _THRDCREATEWIN * PTHRDCREATEWIN
LRESULT WINAPI MultiWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: multithrdwin.c:154
static HINSTANCE hAppInstance
Definition: multithrdwin.c:18
static THRDCREATEWIN wnds[3]
Definition: multithrdwin.c:20
static HANDLE WinCreatedEvent
Definition: multithrdwin.c:19
unsigned int UINT
Definition: ndis.h:50
HANDLE hThread
Definition: wizard.c:28
CHAR * PCH
Definition: ntbasedef.h:391
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_TABSTOP
Definition: pedump.c:634
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_BORDER
Definition: pedump.c:625
#define WS_GROUP
Definition: pedump.c:633
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define BS_PUSHBUTTON
Definition: pedump.c:651
#define DefWindowProc
Definition: ros2win.h:31
Definition: client.c:28
Definition: window.c:28
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
HANDLE hThread
Definition: multithrdwin.c:8
HBRUSH hbrBackground
Definition: winuser.h:3170
HICON hIcon
Definition: winuser.h:3168
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
int cbWndExtra
Definition: winuser.h:3166
UINT style
Definition: winuser.h:3163
LPCSTR lpszMenuName
Definition: winuser.h:3171
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
int cbClsExtra
Definition: winuser.h:3165
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
#define CreateEvent
Definition: winbase.h:3748
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
#define WINAPI
Definition: msvc.h:6
#define ERROR_TIMEOUT
Definition: winerror.h:941
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define WM_PAINT
Definition: winuser.h:1620
#define CS_VREDRAW
Definition: winuser.h:658
#define SendMessageTimeout
Definition: winuser.h:5845
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define COLOR_WINDOW
Definition: winuser.h:918
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_COMMAND
Definition: winuser.h:1740
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define UnregisterClass
Definition: winuser.h:5861
#define IDI_APPLICATION
Definition: winuser.h:704
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadIcon
Definition: winuser.h:5813
#define WM_NULL
Definition: winuser.h:1607
#define LoadCursor
Definition: winuser.h:5812
#define SMTO_ABORTIFHUNG
Definition: winuser.h:1223
#define MessageBox
Definition: winuser.h:5822
#define RegisterClass
Definition: winuser.h:5836
#define WM_DESTROY
Definition: winuser.h:1609
#define DispatchMessage
Definition: winuser.h:5765
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
char * LPSTR
Definition: xmlstorage.h:182
const CHAR * LPCTSTR
Definition: xmlstorage.h:193