15,471
社区成员
发帖
与我相关
我的任务
分享
void threadChild1(PVOID pvoid) //窗口1的线程
{
HDC hdc;
int left,top,right,bottom;
HBRUSH hBrush,oldBrush;
PPARAMS pparams = (PPARAMS)pvoid; //_beginthread的第3个参数传给了pvoid
if(pparams->cxClient != 0 || pparams->cyClient != 0)//为什么要有这个判断
{
while(true)
{
hdc = GetDC(pparams->hwnd);
hBrush = CreateSolidBrush(RGB(0,0,255));
oldBrush = (HBRUSH)SelectObject(hdc,hBrush);
left = rand()%(pparams->cxClient);
right = rand()%(pparams->cxClient);
top = rand()%(pparams->cyClient);
bottom = rand()%(pparams->cyClient);
Rectangle(hdc,min(left,right),min(top,bottom),max(left,right),max(top,bottom));
SelectObject(hdc,oldBrush);
ReleaseDC(pparams->hwnd,hdc);
DeleteObject(hBrush);
Sleep(50);
}
}
}
LRESULT CALLBACK child1Proc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static PARAMS params;
switch(uMsg)
{
case WM_CREATE:
params.hwnd = hwnd;
//_beginthread(threadChild1,0,¶ms);
return 0;
case WM_SIZE:
params.cxClient = LOWORD(lParam);
params.cyClient = HIWORD(lParam);
_beginthread(threadChild1,0,¶ms);
return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}