📄 timewindow.cpp
字号:
#include "TimeWindow.h"
#define ID_TIMER14 14
#define ID_TIMER15 15
LRESULT CALLBACK TimeWindowProc(HWND,UINT,WPARAM,LPARAM);
TimeWindow::TimeWindow(void)
{
}
TimeWindow::~TimeWindow(void)
{
}
BOOL TimeWindow::RegisterTimeWindow( TCHAR ClassName[] ,HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style =CS_HREDRAW|CS_VREDRAW,
wndclass.lpfnWndProc =TimeWindowProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =0;
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =CreateSolidBrush(RGB(0xff,0xff,0xff));
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =ClassName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("Can not register this window!"),
ClassName,MB_ICONERROR);
return FALSE;
}
return TRUE;
}
BOOL TimeWindow::CreateTimeWindow(HINSTANCE hInstance,HWND hwnd,HWND *TimeWindowhwnd,TCHAR ClassName[],TCHAR WindowName[],DWORD style,int Left,int Top,int cx,int cy)
{
*TimeWindowhwnd = CreateWindow(ClassName,
WindowName,
style,
Left,
Top,
cx,
cy,
hwnd,
NULL,
hInstance,
NULL);
return *TimeWindowhwnd==0? FALSE:TRUE;
}
void TimeWindow::DisplayDigit(HDC hdc,int iNumber)
{
static BOOL fSevenSegment[10][7]={
1,1,1,0,1,1,1,
0,0,1,0,0,1,0,
1,0,1,1,1,0,1,
1,0,1,1,0,1,1,
0,1,1,1,0,1,0,
1,1,0,1,0,1,1,
1,1,0,1,1,1,1,
1,0,1,0,0,1,0,
1,1,1,1,1,1,1,
1,1,1,1,0,1,1};
static POINT ptSegment[7][6]={
7, 6, 11, 2, 31, 2, 35, 6, 31, 10, 11, 10,
6, 7, 10, 11, 10, 31, 6, 35, 2, 31, 2, 11,
36, 7, 40, 11, 40, 31, 36, 35, 32, 31, 32, 11,
7, 36, 11, 32, 31, 32, 35, 36, 31, 40, 11, 40,
6, 37, 10, 41, 10, 61, 6, 65, 2, 61, 2, 41,
36, 37, 40, 41, 40, 61, 36, 65, 32, 61, 32, 41,
7, 66, 11, 62, 31, 62, 35, 66, 31, 70, 11, 70};
int iSeg;
for(iSeg=0;iSeg<7;iSeg++)
if(fSevenSegment[iNumber][iSeg])
Polygon(hdc,ptSegment[iSeg],6);
}
void TimeWindow::DisplayTwoDigits(HDC hdc,int iNumber,BOOL fSuppress)
{
if(!fSuppress||(iNumber/10!=0))
DisplayDigit(hdc,iNumber/10);
OffsetWindowOrgEx(hdc,-42,0,NULL);
DisplayDigit(hdc,iNumber%10);
OffsetWindowOrgEx(hdc,-42,0,NULL);
}
void TimeWindow::DisplayColon(HDC hdc)
{
POINT ptColon[2][4]={2, 21, 6, 17, 10, 21, 6, 25,
2, 51, 6, 47, 10, 51, 6, 55};
Polygon(hdc,ptColon[0],4);
Polygon(hdc,ptColon[1],4);
OffsetWindowOrgEx(hdc,-12,0,NULL);
}
void TimeWindow::DisplayTime(HDC hdc,BOOL f24Hour,BOOL fSuppress,long GameTime)
{
int Hour=GameTime/(1000*60*60);
int Minute=(GameTime-Hour*1000*60*60)/(1000*60);
int Second=(GameTime-Hour*1000*60*60-Minute*1000*60)/1000;
if(f24Hour)
DisplayTwoDigits(hdc,Hour,fSuppress);
DisplayColon(hdc);
DisplayTwoDigits(hdc,Minute,FALSE);
DisplayColon(hdc);
DisplayTwoDigits(hdc,Second,FALSE);
}
void TimeWindow::DisplayFigure(HDC hdc,long Figure)
{
char temp[15];
int i,j;
ltoa(Figure,temp,10);
j=strlen(temp);
for(i=0;i<j;i++)
{
DisplayDigit(hdc,temp[i]-'0');
OffsetWindowOrgEx(hdc,-42,0,NULL);
}
}
extern int BigSmallWriteFlag;
LRESULT CALLBACK TimeWindowProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
static HDC hMem;
static HBITMAP hBitmap;
static int cx[2];
static int cy[2];
PAINTSTRUCT ps;
static HINSTANCE hInst;
RECT rect;
static BOOL f24Hour,fSuppress;
static HBRUSH hBrushBlue;
static HBRUSH hBrushYellow;
TCHAR szBuffer[2];
TimeWindow timewindow;
TimeWindow BurstWindow;
static long Time14;
static long GameStartTime;
long GameTime;
static long GamePause;
static long TempGamePause;
static int WindowID;
int i;
static long BurstBalloonNumber;
switch(message)
{
case WM_CREATE:
hInst=((LPCREATESTRUCT)lParam)->hInstance;
hMem=CreateCompatibleDC(NULL);
hBitmap=LoadBitmap(hInst,MAKEINTRESOURCE(159));
SelectObject(hMem,hBitmap);
hBrushBlue=CreateSolidBrush(RGB(0x00,0x00,0xff));
hBrushYellow=CreateSolidBrush(RGB(0xff,0xff,0x00));
WindowID++;
SetWindowLong(hwnd,GWL_ID,WindowID);
case WM_SETTINGCHANGE:
GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_ITIME,szBuffer,2);
f24Hour=(szBuffer[0]=='1');
GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_ITLZERO,szBuffer,2);
fSuppress=(szBuffer[0]=='0');
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_SIZE:
i=GetWindowLong(hwnd,GWL_ID)==1?0:1;
cx[i]=LOWORD(lParam);
cy[i]=HIWORD(lParam);
return 0;
case WM_COMMAND:
if(wParam==0)
{
if(Time14>0)
GamePause=GetTickCount()-TempGamePause+GamePause;
SetTimer(hwnd,ID_TIMER14,1000,NULL);
}
if(wParam==1)
{
TempGamePause=GetTickCount();
KillTimer(hwnd,ID_TIMER14);
}
return 0;
case WM_TIMER:
switch(wParam)
{
case 14:
Time14++;
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case 15:
if(BigSmallWriteFlag==1)
BurstBalloonNumber++;
else if(BigSmallWriteFlag==2)
BurstBalloonNumber+=2;
InvalidateRect(hwnd,NULL,TRUE);
return 0;
}
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(GetParent(hwnd),&rect);
if(GetWindowLong(hwnd,GWL_ID)==1)
{
BitBlt(hdc,0,0,cx[0],cy[0],hMem,rect.right-150,10,SRCAND);
SetMapMode(hdc,MM_ISOTROPIC);
SetWindowExtEx(hdc,276,72,NULL);
SetViewportExtEx(hdc,cx[0],cy[0],NULL);
SetWindowOrgEx(hdc,138,36,NULL);
SetViewportOrgEx(hdc,cx[0]/2,cy[0]/2,NULL);
SelectObject(hdc,GetStockObject(NULL_PEN));
SelectObject(hdc,hBrushBlue);
if(Time14==1)
{
GameStartTime=GetTickCount();
timewindow.DisplayTime(hdc,f24Hour,fSuppress,0);
}
if(Time14>1)
{
GameTime=GetTickCount()-GameStartTime-GamePause;
timewindow.DisplayTime(hdc,f24Hour,fSuppress,GameTime);
}
}
if(GetWindowLong(hwnd,GWL_ID)==2)
{
BitBlt(hdc,0,0,cx[1],cy[1],hMem,rect.left+10,10,SRCCOPY);
SetMapMode(hdc,MM_ISOTROPIC);
SetWindowExtEx(hdc,420,72,NULL);
SetViewportExtEx(hdc,cx[1],cy[1],NULL);
SetWindowOrgEx(hdc,210,36,NULL);
SetViewportOrgEx(hdc,cx[1]/2,cy[1]/2,NULL);
SelectObject(hdc,GetStockObject(NULL_PEN));
SelectObject(hdc,hBrushYellow);
if(BurstBalloonNumber)
BurstWindow.DisplayFigure(hdc,BurstBalloonNumber);
}
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
KillTimer(hwnd,ID_TIMER14);
DeleteObject(hBrushBlue);
DeleteObject(hBrushYellow);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -