다음 코드를 임의의 이름으로 파일에 저장합니다(예: th.cpp
yc++에서는 Call th.cpp를 사용한 다음 th.cpp 실행
또는 dos에서는 다음과 같이 사용합니다. ycc th.cpp를 사용하여 th.exe를 생성한 다음 실행합니다.
또는 vc++에서는 cl th.cpp를 사용하여 th.exe를 생성한 다음 실행합니다.
/////////////////////////////////////////////////// /////////////////////////////////////////////////////////
#Yves YCC
#include & ltwindows.h & gt
#include "include\ycapi .h"
#pragma comment (lib, " gdi32.lib ")
#pragma comment (lib, " user32.lib ")
#pragma comment (lib, " yxbapi.lib ")
#pragma comment (lib, " user32.lib ") p>
#ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(h 인스턴스 h 인스턴스, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
//////// 메인 창을 생성합니다. 이 함수는 YC++ API 함수를 사용하여 생성되며 등록할 필요가 없습니다.
int WINAPI MainWndProc(HWND hwnd, UINT iMessage, UINT wParam, LONG lParam, void * puser data);
HWND HWND = YXB _ Window(MainWndProc. NULL, 0,
WS _ 겹쳐진 창 | WS _ CAPTION | WS _ SYSMENU,
"multithreaded", 110, 50, 800, 600, null, wt _ win);
MSG. MSG;
while(GetMessage(& amp; msg, NULL, 0, 0))
{
translate message(& amp MSG);
dispatch message(amp; MSG);
}
returns 0;
}
int WINAPI MainWndProc(HWND hwnd, UINT iMessage, UINT wParam, LONG lParam, void *pUserData)
{
static handle linep_thread_handle. rectp _ thread _ handle
토글 (iMessage)
{
Case WM_DESTROY:
termin ate thread(linep _ thread _ handle, 0);
close handle (linep _ thread _ handle);
termin ate thread(rectp _ thread _ handle, 0);
close handle(rectp _ thread _ handle);
PostQuitMessage (0);
Return FALSE
Case WM_CREATE:
DWORD linep _ thread _ ret, rectp _ thread _ ret
void draw _ linep(LPVOID * my _ buf), draw _ rectp( LPVOID * my _ buf);
linep _ thread _ handle = CreateThread(NULL, 0, (LPTHREAD _ START _ ROUTINE)draw _ linep, hwnd, 0, & amplinep _ thread _ ret);
rectp _ thread _ handle = CreateThread(NULL, 0, (LPTHREAD _ START _ ROUTINE)draw _ rectp, hwnd, 0, & amplinep _ thread _ ret);
Returns FALSE
case WM_PAINT:
PAINTSTRUCT ps
start drawing(hwnd & amp; PS);
One shot;
memset(& amp; yimg, 0, sizeof YIMG);
yimg . hdc = PS . hdc; // 이 설정을 사용하면 창의 클라이언트 영역을 이미지로 조작할 수 있습니다.
Mr RECT;
GetClientRect(hwnd & amp; mRect);
YXB _ image fill(& amp; yimg, 0, 0, mRect.right, mRect.bottom, RGB(130, 150, 160));< /p>
facepaint(hwnd & amp; PS);
returns FALSE
}
returns DefWindowProc(hwnd, iMessage, wParam, lParam);
}
const int mycolor[]={{ 0xff7766, 0xcc88ff, 0x6688aa, 0xcc9977, 0x88ff11, 0x779911, 0xdd88aa, 0x 55 ccff };
void draw_linep(LPVOID *my_buf)
{
static int xx0 = 388, yy0 = 200
HWND HWND = (HWND)my _ buf;
HDC HDC = GetDC(hwnd);
Mr RECT;
GetClientRect(hwnd & amp; mRect);
MoveToEx(hdc, 0, 0, NULL);
for(int ii = 0;; ii++)
{
HPEN hPen = CreatePen(PS_SOLID, 3, my colour[ii % 8]);
HPEN hPen save =( HPEN)select object(hdc, hPen);
LineTo(hdc, xx0, yy0);
xx0 = RAND()* m rect . right/2/RAND _ MAX;
yy0 = RAND()* m rect . bottom/RAND _ MAX;
SelectObject (hdc, hpen save);
delete object(hPen);
Sleep(10);
}
ReleaseDC(hwnd, hdc);
< p>}void draw_rectp(LPVOID *my_buf)
{
정적 int xx0 = 0, yy0 = 0;
HWND HWND = (HWND)my _ buf;
HDC HDC = GetDC(hwnd);
Mr RECT;
GetClientRect(hwnd & amp; mRect);
for(int ii = 0;; ii++)
{
HBR 브러시 HBR =(HBRUSH)select object(hdc. CreateSolidBrush(my colour[ii % 8]);
PatBlt(hdc, xx0, yy0, 30, 30, pat copy);
DeleteObject(SelectObject(hdc, HBR));
xx0 =. RAND()* mrect . right/2/RAND _ MAX+mRect.right/2;
yy0 = RAND()* mrect . bottom/RAND _ MAX;
Sleep(10);
}
ReleaseDC(hwnd, hdc);
}