4 ULONG
DbgPrint(PCH Format
,...);
6 typedef struct _THRDCREATEWIN
16 } THRDCREATEWIN
, *PTHRDCREATEWIN
;
18 static HINSTANCE hAppInstance
;
19 static HANDLE WinCreatedEvent
;
20 static THRDCREATEWIN wnds
[3];
22 LRESULT WINAPI
MultiWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
25 WindowThreadProc(LPVOID lpParameter
)
29 PTHRDCREATEWIN cw
= (PTHRDCREATEWIN
)lpParameter
;
31 sprintf(caption
, cw
->Caption
, GetCurrentThreadId());
33 cw
->Window
= CreateWindow("MultiClass",
35 cw
->Style
| WS_VISIBLE
,
40 (cw
->Parent
? *(cw
->Parent
) : 0),
45 SetEvent(WinCreatedEvent
);
49 fprintf(stderr
, "CreateWindow failed (last error 0x%lX)\n",
53 CreateWindow("BUTTON","Sleep",WS_CHILD
|WS_VISIBLE
|WS_TABSTOP
|WS_GROUP
|BS_PUSHBUTTON
, 10, 10, 70, 23, cw
->Window
, (PVOID
)1, hAppInstance
, NULL
);
54 CreateWindow("BUTTON","1",WS_CHILD
|WS_VISIBLE
|WS_TABSTOP
|WS_GROUP
|BS_PUSHBUTTON
, 83, 10, 20, 23, cw
->Window
, (PVOID
)2, hAppInstance
, NULL
);
55 CreateWindow("BUTTON","2",WS_CHILD
|WS_VISIBLE
|WS_TABSTOP
|WS_GROUP
|BS_PUSHBUTTON
, 105, 10, 20, 23, cw
->Window
, (PVOID
)3, hAppInstance
, NULL
);
56 CreateWindow("BUTTON","3",WS_CHILD
|WS_VISIBLE
|WS_TABSTOP
|WS_GROUP
|BS_PUSHBUTTON
, 127, 10, 20, 23, cw
->Window
, (PVOID
)4, hAppInstance
, NULL
);
57 while(GetMessage(&msg
, NULL
, 0, 0))
59 TranslateMessage(&msg
);
60 DispatchMessage(&msg
);
67 WinMain(HINSTANCE hInstance
,
68 HINSTANCE hPrevInstance
,
76 hAppInstance
= hInstance
;
78 WinCreatedEvent
= CreateEvent(NULL
,
85 fprintf(stderr
, "Failed to create event (last error 0x%lX)\n",
90 wc
.lpszClassName
= "MultiClass";
91 wc
.lpfnWndProc
= MultiWndProc
;
92 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
93 wc
.hInstance
= hInstance
;
94 wc
.hIcon
= LoadIcon(NULL
, (LPCTSTR
) IDI_APPLICATION
);
95 wc
.hCursor
= LoadCursor(NULL
, (LPCTSTR
) IDC_ARROW
);
96 wc
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
97 wc
.lpszMenuName
= NULL
;
100 if (RegisterClass(&wc
) == 0)
102 fprintf(stderr
, "RegisterClass failed (last error 0x%lX)\n",
107 wnds
[0].Caption
= "TopLevel1 (ThreadID: %d)";
108 wnds
[0].Parent
= NULL
;
109 wnds
[0].Style
= WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
110 wnds
[0].Position
.x
= wnds
[0].Position
.y
= 0;
111 wnds
[0].Size
.cx
= 320;
112 wnds
[0].Size
.cy
= 240;
114 wnds
[1].Caption
= "Child1 of TopLevel1 (ThreadID: %d)";
115 wnds
[1].Parent
= &wnds
[0].Window
;
116 wnds
[1].Style
= WS_CHILD
| WS_BORDER
| WS_CAPTION
| WS_VISIBLE
| WS_SYSMENU
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
117 wnds
[1].Position
.x
= 20;
118 wnds
[1].Position
.y
= 120;
119 wnds
[1].Size
.cx
= wnds
[1].Size
.cy
= 240;
121 wnds
[2].Caption
= "TopLevel2 (ThreadID: %d)";
122 wnds
[2].Parent
= NULL
;
123 wnds
[2].Style
= WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
124 wnds
[2].Position
.x
= 400;
125 wnds
[2].Position
.y
= 0;
126 wnds
[2].Size
.cx
= 160;
127 wnds
[2].Size
.cy
= 490;
129 for(i
= 0; i
< (sizeof(wnds
) / sizeof(THRDCREATEWIN
)); i
++)
131 wnds
[i
].hThread
= CreateThread(NULL
,
137 Threads
[i
] = wnds
[i
].hThread
;
140 fprintf(stderr
, "CreateThread #%i failed (last error 0x%lX)\n",
144 WaitForSingleObject(WinCreatedEvent
, INFINITE
);
147 WaitForMultipleObjects(sizeof(Threads
) / sizeof(HANDLE
), &Threads
[0], TRUE
, INFINITE
);
149 UnregisterClass("MultiClass", hInstance
);
154 LRESULT CALLBACK
MultiWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
162 static COLORREF Colors
[] =
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)
180 static unsigned CurrentColor
= 0;
185 hDC
= BeginPaint(hWnd
, &ps
);
186 GetClientRect(hWnd
, &Client
);
187 Brush
= CreateSolidBrush(Colors
[CurrentColor
]);
188 FillRect(hDC
, &Client
, Brush
);
191 if (sizeof(Colors
) / sizeof(Colors
[0]) <= CurrentColor
)
199 switch(LOWORD(wParam
))
207 if(SendMessageTimeout(wnds
[LOWORD(wParam
) - 2].Window
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 1000, &Ret
))
209 DbgPrint("SendMessageTimeout() OK");
210 MessageBox(hWnd
, "SendMessageTimeout() OK", NULL
, 0);
214 if(GetLastError() == ERROR_TIMEOUT
)
216 DbgPrint("SendMessageTimeout() Timeout");
217 MessageBox(hWnd
, "SendMessageTimeout() Timeout", NULL
, 0);
221 DbgPrint("SendMessageTimeout() Failed");
222 MessageBox(hWnd
, "SendMessageTimeout() Failed", NULL
, 0);
234 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);