#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
DWORD WINAPI yzx(LPVOID asd);//在兼容DC上绘图的(专用)线程
char szClassName[ ]="WTF";
HBITMAP hbitmap;
HDC hdcm;
HANDLE hev;//控制(绘图)线程的开关
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"hjdl", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
0, /* Windows decides the position */
0, /* where the window ends up on the screen */
1000, /* The programs width */
800, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message) /* handle the messages */
{
case WM_CREATE:
hdc=GetDC(hwnd);
hdcm=CreateCompatibleDC(hdc);
hbitmap=CreateCompatibleBitmap(hdc,500,500);
SelectObject(hdcm,hbitmap);
ReleaseDC(hwnd,hdc);
hev=CreateEvent(NULL,0,0,NULL);
CreateThread(NULL,0,yzx,hwnd,0,NULL);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
BitBlt(hdc,0,0,500,500,hdcm,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONUP:
SetEvent(hev);
break;
case WM_DESTROY:
CloseHandle(hev);
DeleteObject(hdcm);
DeleteObject(hbitmap);
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
DWORD WINAPI yzx(LPVOID asd)
{
char temp[111];
int k=0;
while(1)
{
WaitForSingleObject(hev,INFINITE);
Rectangle(hdcm,0,0,500,500);
sprintf(temp,"%d",++k);
TextOut(hdcm,10,10,temp,strlen(temp));
}
return 0;
}