15,979
社区成员
发帖
与我相关
我的任务
分享
#include<windows.h>
#define ImageBase (HINSTANCE)0x400000
#define BinBox(Value){wchar_t __Buffer[34];_ltow((long)(Value),__Buffer,2);MessageBoxW(0,__Buffer,0,MB_TASKMODAL);}
#define DecBox(Value){wchar_t __Buffer[32];_ltow((long)(Value),__Buffer,10);MessageBoxW(0,__Buffer,0,MB_TASKMODAL);}
#define PrintDec(Value){char __Buffer[32];_ltoa((long)(Value),__Buffer,10);OutputDebugStringA(__Buffer);}
#define PrintHex(Value){char __Buffer[32];_ltoa((long)(Value),__Buffer,16);OutputDebugStringA(__Buffer);}
#define HexBox(Value){wchar_t __Buffer[32];_ltow((long)(Value),__Buffer,16);MessageBoxW(0,__Buffer,0,0);}
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int stop;
unsigned long __stdcall ThreadProc(void**Parameters)
{
unsigned long*Buffer=(unsigned long*)(Parameters[0]);
HWND hwnd=(HWND)Parameters[1];
static unsigned long c,i=0;
while(!stop)
{
for(c=0;c<400*400;++c)
{
Buffer[c]=0xFF000000|(rand()*rand());
}
WindowProc(hwnd,WM_USER,0,0);
SwitchToThread();
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
static HBITMAP hBitmap;static void*Buffer;HDC hDC;static HDC memDC;BITMAPINFO bmpinfo;PAINTSTRUCT ps;RECT Rect;
static HANDLE hThread;static HWND hwndStart,hwndStop;
switch(uMsg)
{
case WM_ERASEBKGND:
return 0;
case WM_USER:
hDC=GetDC(hwnd);
BitBlt(hDC,0,20,400,400,memDC,0,0,SRCCOPY);
ReleaseDC(hwnd,hDC);
return 0;
case WM_PAINT:
if(GetUpdateRect(hwnd,&Rect,0)){
hDC=BeginPaint(hwnd,&ps);
BitBlt(hDC,Rect.left,Rect.top+20,Rect.right-Rect.left,Rect.bottom-Rect.top,memDC,Rect.left,Rect.top,SRCCOPY);
EndPaint(hwnd,&ps);}
return 0;
case WM_COMMAND:
if(LOWORD(wParam)==0)
{
static void*Parameters[2];
Parameters[0]=Buffer;
Parameters[1]=hwnd;
stop=0;
hThread=CreateRemoteThread((HANDLE)-1,0,0,(LPTHREAD_START_ROUTINE)ThreadProc,(void*)Parameters,0,0);
EnableWindow(hwndStart,0);
EnableWindow(hwndStop,1);
}else if(LOWORD(wParam)==1)
{
stop=1;
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
EnableWindow(hwndStart,1);
EnableWindow(hwndStop,0);
}
return 0;
case WM_CREATE:
srand(GetTickCount());
hDC=GetDC(hwnd);
memset(&bmpinfo,0,sizeof(BITMAPINFO));
bmpinfo.bmiHeader.biBitCount=32;
bmpinfo.bmiHeader.biCompression=BI_RGB;
bmpinfo.bmiHeader.biHeight=400;
bmpinfo.bmiHeader.biPlanes=1;
bmpinfo.bmiHeader.biSizeImage=0;
bmpinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth=400;
hBitmap=CreateDIBSection(0,&bmpinfo,0,&Buffer,0,0);
{
unsigned long c;
for(c=0;c<400*400;c++)((unsigned long*)Buffer)[c]=0xFF000000|c;
}
memDC=CreateCompatibleDC(hDC);
SelectObject(memDC,hBitmap);
ReleaseDC(hwnd,hDC);
hwndStart=CreateWindowExW(0,L"Button",L"start",WS_VISIBLE|WS_CHILD,30,0,40,20,hwnd,0,0,0);
hwndStop=CreateWindowExW(0,L"Button",L"stop",WS_VISIBLE|WS_CHILD|WS_DISABLED,70,0,40,20,hwnd,(HMENU)1,0,0);
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:return DefWindowProcW(hwnd,uMsg,wParam,lParam);
}
}
unsigned long __stdcall EntryPoint(void)
{
static WNDCLASSEXW WindowClass = {
sizeof(WNDCLASSEXW),0,WindowProc,0,0,ImageBase,0,0,0,0,L"Class",0
};
int r;
HWND hwnd;
MSG msg;
WindowClass.hCursor=LoadCursorW(0,(wchar_t*)IDC_ARROW);
hwnd = CreateWindowExW(0,(LPWSTR)(unsigned long)RegisterClassExW(&WindowClass),L"c",WS_SYSMENU|WS_MINIMIZEBOX,0,0,400,420,0,0,0,0);
if(hwnd == 0) return;
ShowWindow(hwnd,1);
while((r=GetMessageW(&msg,0,0,0))!=-1){
if(r==0)break;
DispatchMessageW(&msg);
}ExitProcess(0);
}