📄 collage.cpp
字号:
image_idb+=1;
if(image_idb >= (level_num+1))
image_idb = 0;
hMemDC=CreateCompatibleDC(hdc);
for(i = 0; i < 9; i++)
{
switch(temp_buf1[i])
{
case 0:
hStep=hNull;
break;
case 1:
hStep=element[image_idb][0];
break;
case 2:
hStep=element[image_idb][1];
break;
case 3:
hStep=element[image_idb][2];
break;
case 4:
hStep=element[image_idb][3];
break;
case 5:
hStep=element[image_idb][4];
break;
case 6:
hStep=element[image_idb][5];
break;
case 7:
hStep=element[image_idb][6];
break;
case 8:
hStep=element[image_idb][7];
break;
case 9:
hStep=element[image_idb][8];
break;
}
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
if(i < 3)
StretchBlt(hdc,WIDTH*i+SCREEN_X,SCREEN_Y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
if((i>=3)&&(i<6))
StretchBlt(hdc,WIDTH*(i-3)+SCREEN_X,WIDTH+SCREEN_Y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
if((i>=6)&&(i<9))
StretchBlt(hdc,WIDTH*(i-6)+SCREEN_X,WIDTH*2+SCREEN_Y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}
for(i = 0; i < 9; i++)
{
switch(temp_buf2[i])
{
case 0:
hStep=hN;
break;
case 1:
hStep=element[image_idb+3][0];
break;
case 2:
hStep=element[image_idb+3][1];
break;
case 3:
hStep=element[image_idb+3][2];
break;
case 4:
hStep=element[image_idb+3][3];
break;
case 5:
hStep=element[image_idb+3][4];
break;
case 6:
hStep=element[image_idb+3][5];
break;
case 7:
hStep=element[image_idb+3][6];
break;
case 8:
hStep=element[image_idb+3][7];
break;
case 9:
hStep=element[image_idb+3][8];
break;
}
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
if(i < 3)
StretchBlt(hdc,WI*i+SC_X,SC_Y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
if((i>=3)&&(i<6))
StretchBlt(hdc,WI*(i-3)+SC_X,WI+SC_Y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
if((i>=6)&&(i<9))
StretchBlt(hdc,WI*(i-6)+SC_X,WI*2+SC_Y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}
if(down_flag == 1)
{
hStep=element[image_idb+3][temp_num-1];
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hdc,xPos-STEP,yPos-STEP,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}
DeleteDC(hMemDC);
}
void DownImage(HWND hwnd,HDC hdc)
{
int i,j;
RECT rect;
for(i=0; i<3; i++)
{
if((xPos>=(WIDTH*i+SCREEN_X))&&(xPos<(WIDTH*(i+1)+SCREEN_X)))
{
for(j=0; j<3; j++)
{
if((yPos>=(WIDTH*j+SCREEN_Y))&&(yPos<(WIDTH*(j+1)+SCREEN_Y)))
{
if(j==0)
temp_pos = i+j;
if(j==1)
temp_pos = i+j+2;
if(j==2)
temp_pos = i+j+4;
if(temp_buf1[temp_pos]!=0)
{
down_flag = 1;
move_num = temp_pos;
ZoomIn(hdc);
rect.left = WIDTH*i+SCREEN_X;
rect.right = WIDTH*(i+1) + SCREEN_X;
rect.top = WIDTH*j+SCREEN_Y;
rect.bottom = WIDTH*(j+1) + SCREEN_Y;
InvalidateRect(hwnd,&rect,TRUE);
}
}
}
}
}
for(i=0; i<3; i++)
{
if((xPos>=(WI*i+SC_X))&&(xPos<(WI*(i+1)+SC_X)))
{
for(j=0; j<3; j++)
{
if((yPos>=(WI*j+SC_Y))&&(yPos<(WI*(j+1)+SC_Y)))
{
if(j==0)
temp_pos = i+j;
if(j==1)
temp_pos = i+j+2;
if(j==2)
temp_pos = i+j+4;
if(temp_buf2[temp_pos]!=0)
{
down_flag = 2;
rect.left = WI*i + SC_X;
rect.right = WI*(i+1) + SC_X;
rect.top = WI*j + SC_Y;
rect.bottom = WI*(j+1) + SC_Y;
InvalidateRect(hwnd,&rect,TRUE);
ZoomIn(hdc);
}
}
}
}
}
}
void ZoomIn(HDC hdc)
{
HDC hMemDC;
BITMAP bm;
hMemDC=CreateCompatibleDC(hdc);
if(down_flag == 1)
{
temp_num = temp_buf1[temp_pos];
temp_buf1[temp_pos] = 0;
hStep=element[image_idb+3][temp_num-1];
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hdc,xPos-STEP,yPos-STEP,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}
if(down_flag == 2)
{
temp_num = temp_buf2[temp_pos];
temp_buf2[temp_pos] = 0;
hStep=element[image_idb+3][temp_num-1];
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hdc,xPos-STEP,yPos-STEP,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
down_flag = 1;
}
DeleteDC(hMemDC);
}
void MoveImage(HWND hwnd)
{
int temp_x,temp_y;
int move_x,move_y;
RECT rect,rect1,rect2,rect3,rect4;
temp_x = abs(xPos-last_x);
temp_y = abs(yPos-last_y);
move_x = (xPos-last_x);
move_y = (yPos-last_y);
GetClientRect(hwnd,&rect);
rect1.left = last_x - STEP;
rect1.right = last_x - STEP + WI;
rect1.top = last_y - STEP;
rect1.bottom = last_y - STEP + WI;
ScrollWindowEx(hwnd,move_x,0,&rect1,&rect,NULL,&rect,SW_INVALIDATE);
if((temp_x <= WI)&&(temp_y <=WI))
{
rect3.left = last_x - STEP;
rect3.right = xPos - STEP;
rect3.top = last_y - STEP;
rect3.bottom = last_y - STEP + WI;
InvalidateRect(hwnd,&rect3,TRUE);
}
else{
InvalidateRect(hwnd,&rect1,TRUE);
// UpdateWindow(hwnd);
}
GetClientRect(hwnd,&rect);
rect2.left = xPos - STEP;
rect2.right = xPos - STEP + WI;
rect2.top = last_y - STEP;
rect2.bottom = last_y - STEP + WI;
ScrollWindowEx(hwnd,0,move_y,&rect2,&rect,NULL,&rect,SW_INVALIDATE);
if((temp_x <= WI)&&(temp_y <=WI))
{
rect4.left = xPos - STEP;
rect4.right = xPos - STEP + WI;
rect4.top = last_y - STEP;
rect4.bottom = yPos - STEP;
InvalidateRect(hwnd,&rect4,TRUE);
}
else
{
InvalidateRect(hwnd,&rect2,TRUE);
}
}
void ImageUpdate(HDC hdc)
{
HDC hMemDC;
BITMAP bm;
hMemDC=CreateCompatibleDC(hdc);
if((down_flag == 1)&&(up_flag == 0))
{
hStep=element[image_idb+3][temp_num-1];
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hdc,xPos-STEP,yPos-STEP,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}
DeleteDC(hMemDC);
}
void UpImage(HWND hwnd,HDC hdc)
{
int i,j;
unsigned char flag=FALSE;
RECT rect;
rect.left = xPos - STEP;
rect.right = xPos - STEP + WI;
rect.top = yPos - STEP;
rect.bottom = yPos - STEP + WI;
for(i=0; i<3; i++)
{
if((xPos>=(WI*i+SC_X))&&(xPos<(WI*(i+1)+SC_X)))
{
for(j=0; j<3; j++)
{
if((yPos>=(WI*j+SC_Y))&&(yPos<(WI*(j+1)+SC_Y)))
{
if(j==0)
temp_pos = i+j;
if(j==1)
temp_pos = i+j+2;
if(j==2)
temp_pos = i+j+4;
up_flag = 1;
flag = TRUE;
InvalidateRect(hwnd,&rect,TRUE);
ImageJudge(hdc);
}
}
}
}
if(flag == FALSE)
{
ZoomOut(hdc);
InvalidateRect(hwnd,&rect,TRUE);
}
}
void ZoomOut(HDC hdc)
{
int j;
int temp_x,temp_y;
HDC hMemDC;
BITMAP bm;
hMemDC=CreateCompatibleDC(hdc);
up_flag = 2; // don't move to target space;
for(j=0;j<9;j++)
{
if(num_buf1[j] == temp_num)
{
temp_pos = j;
temp_buf1[temp_pos] = temp_num;
}
}
if(temp_pos<3)
{
temp_x = temp_pos*WIDTH + SCREEN_X;
temp_y = SCREEN_Y;
}
else
{
if(temp_pos<6)
{
temp_x = (temp_pos-3)*WIDTH + SCREEN_X;
temp_y = SCREEN_Y + WIDTH;
}
else
{
temp_x = (temp_pos-6)*WIDTH + SCREEN_X;
temp_y = SCREEN_Y + WIDTH*2;
}
}
hStep=element[image_idb][temp_num-1];
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hdc,temp_x,temp_y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteDC(hMemDC);
}
void ImageJudge(HDC hdc)
{
int temp_x,temp_y;
HDC hMemDC;
BITMAP bm;
hMemDC=CreateCompatibleDC(hdc);
up_flag = 1; // move to target space;
if(temp_buf2[temp_pos] == 0)
{
temp_buf2[temp_pos] = temp_num;
if(temp_pos<3)
{
temp_x = temp_pos*WI + SC_X;
temp_y = SC_Y;
}
else
{
if(temp_pos<6)
{
temp_x = (temp_pos-3)*WI + SC_X;
temp_y = SC_Y + WI;
}
else
{
temp_x = (temp_pos-6)*WI + SC_X;
temp_y = SC_Y + WI*2;
}
}
hStep=element[image_idb+3][temp_num-1];
SelectObject(hMemDC,hStep);
GetObject(hStep,sizeof(BITMAP),(LPSTR)&bm);
StretchBlt(hdc,temp_x,temp_y,bm.bmWidth,bm.bmHeight,
hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteDC(hMemDC);
}
else
{
temp_pos = move_num;
ZoomOut(hdc);
}
}
int HappyJudge()
{
int i;
for(i=0;i<9;i++)
{
if(temp_buf2[i] != (i+1))
{
return FALSE;
}
}
return TRUE;
}
void ClearBuffer()
{
int i;
for(i=0;i<9;i++)
{
num_buf1[i] = 0;
temp_buf2[i] = 0;
}
}
LRESULT CALLBACK AboutCollage(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_COMMAND:
switch (LOWORD(wp))
{
case IDOK:
EndDialog(hwnd, TRUE);
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hwnd,TRUE);
return TRUE;
}
return (FALSE);
} // AboutCollage().
LRESULT CALLBACK HappyShow(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_CLOSE:
EndDialog(hwnd,TRUE);
return TRUE;
}
return (FALSE);
} // HappyShow().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -