This commit is contained in:
161
WinMain.cpp
Normal file
161
WinMain.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include <windows.h>
|
||||
#include "Define.h"
|
||||
#include "PatternChecker.h"
|
||||
#include <time.h>
|
||||
|
||||
HINSTANCE g_hInst;
|
||||
LPSTR lpszClass="PatternChecker";
|
||||
|
||||
CPatternChecker* pPC = NULL;
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
|
||||
{
|
||||
static HDC hDC = GetDC(hWnd);
|
||||
static HDC hMemDC = NULL;
|
||||
static HBITMAP hOldBitmap = NULL;
|
||||
static BOOL bLButtonDown = FALSE;
|
||||
static POINT LButtonPos;
|
||||
static BOOL bGenerate = TRUE;
|
||||
static int iTimerElapse = 100;
|
||||
|
||||
if(hMemDC == NULL)
|
||||
{
|
||||
HBITMAP hBit = CreateCompatibleBitmap(hDC, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
hMemDC = CreateCompatibleDC(hDC);
|
||||
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBit);
|
||||
}
|
||||
|
||||
|
||||
switch(iMessage)
|
||||
{
|
||||
case WM_CREATE:
|
||||
srand((int)time(NULL));
|
||||
SetTimer(hWnd, 0, iTimerElapse, NULL);
|
||||
SetFocus(hWnd);
|
||||
break;
|
||||
|
||||
case WM_TIMER:
|
||||
if(bGenerate == TRUE)
|
||||
pPC->GenerateOne();
|
||||
pPC->Draw(hMemDC);
|
||||
InvalidateRect(hWnd, NULL, FALSE);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
if(wParam == VK_ESCAPE)
|
||||
pPC->Reset();
|
||||
|
||||
if(wParam == VK_F5)
|
||||
bGenerate = !bGenerate;
|
||||
|
||||
if(wParam == VK_UP && iTimerElapse > 10)
|
||||
{
|
||||
iTimerElapse -= 10;
|
||||
SetTimer(hWnd, 0, iTimerElapse, NULL);
|
||||
}
|
||||
if(wParam == VK_DOWN && iTimerElapse < 1000)
|
||||
{
|
||||
iTimerElapse += 10;
|
||||
SetTimer(hWnd, 0, iTimerElapse, NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
BitBlt(hDC, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, hMemDC, 0, 0, SRCCOPY);
|
||||
break;
|
||||
|
||||
case WM_MOUSEWHEEL:
|
||||
{
|
||||
RECT WindowRect;
|
||||
GetWindowRect(hWnd, &WindowRect);
|
||||
|
||||
int xPos = LOWORD(lParam) - WindowRect.left;
|
||||
int yPos = HIWORD(lParam) - WindowRect.top;
|
||||
|
||||
short zDelta = (short)HIWORD(wParam);
|
||||
if(zDelta < 0)
|
||||
pPC->ScaleDown(xPos, yPos);
|
||||
else
|
||||
pPC->ScaleUp(xPos, yPos);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_MBUTTONDOWN:
|
||||
pPC->ResetScale();
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
bLButtonDown = TRUE;
|
||||
LButtonPos.x = (short)LOWORD(lParam);
|
||||
LButtonPos.y = (short)HIWORD(lParam);
|
||||
break;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
bLButtonDown = FALSE;
|
||||
break;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
if(bLButtonDown == TRUE)
|
||||
{
|
||||
int iX = (short)LOWORD(lParam);
|
||||
int iY = (short)HIWORD(lParam);
|
||||
|
||||
pPC->MoveScr(iX-LButtonPos.x, iY-LButtonPos.y);
|
||||
|
||||
LButtonPos.x = iX;
|
||||
LButtonPos.y = iY;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
SelectObject(hMemDC, hOldBitmap);
|
||||
DeleteObject(hOldBitmap);
|
||||
ReleaseDC(hWnd, hMemDC);
|
||||
|
||||
ReleaseDC(hWnd, hDC);
|
||||
KillTimer(hWnd, 0);
|
||||
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd,iMessage,wParam,lParam);
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
|
||||
,LPSTR lpszCmdParam,int nCmdShow)
|
||||
{
|
||||
HWND hWnd;
|
||||
MSG Message;
|
||||
WNDCLASS WndClass;
|
||||
g_hInst=hInstance;
|
||||
|
||||
WndClass.cbClsExtra=0;
|
||||
WndClass.cbWndExtra=0;
|
||||
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
|
||||
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
|
||||
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
|
||||
WndClass.hInstance=hInstance;
|
||||
WndClass.lpfnWndProc=(WNDPROC)WndProc;
|
||||
WndClass.lpszClassName=lpszClass;
|
||||
WndClass.lpszMenuName=NULL;
|
||||
WndClass.style=CS_HREDRAW | CS_VREDRAW;
|
||||
RegisterClass(&WndClass);
|
||||
|
||||
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT,
|
||||
NULL,(HMENU)NULL,hInstance,NULL);
|
||||
ShowWindow(hWnd,nCmdShow);
|
||||
|
||||
pPC = new CPatternChecker();
|
||||
|
||||
while(GetMessage(&Message,0,0,0)) {
|
||||
TranslateMessage(&Message);
|
||||
DispatchMessage(&Message);
|
||||
}
|
||||
|
||||
delete pPC;
|
||||
pPC = NULL;
|
||||
|
||||
return Message.wParam;
|
||||
}
|
||||
Reference in New Issue
Block a user