增加以下功能:
1:启动画面不用默认,使用黑色背景,400*300大小,居中显示
wndclass.hbrBackground = (HBRUSH)(GetStockObject (BLACK_BRUSH));
dl=(GetSystemMetrics(SM_CXFULLSCREEN)-400)/2;
dt=(GetSystemMetrics(SM_CYFULLSCREEN)-300)/2;
dx=400;
dy=300;
hWnd = CreateWindow ("MyWindowClass","LoadPic",
WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SYSMENU|WS_SIZEBOX,
dl,dt,dx,dy,NULL,NULL,hInstance,NULL);
2:支持拖放
DragAcceptFiles(hWnd,TRUE);
if (!GetOpenFileName(&ofn))
{
break;
}
case WM_DROPFILES:
if(message==WM_DROPFILES)
{
DragQueryFile((HDROP)wParam, 0, szFileName, 255);
}
LoadPictureFile(szFileName);
break;
3:全图显示
sx=SrcX;
sy=SrcY;
dx=GetSystemMetrics(SM_CXFULLSCREEN);
dy=GetSystemMetrics(SM_CYFULLSCREEN);
while((sx>dx)&&(sy>dy))
{
sx=sx>>1;
sy=sy>>1;
}
dl=-4;
dt=-4;
if(dx>sx)
{
dl=(dx-sx-8)>>1;
dx= sx;
}
if(dy>sy)
{
dt=(dy-sy)>>1;
dy=sy;
}
dx=dx+8;
dy=dy+27;
EndDeferWindowPos(DeferWindowPos(BeginDeferWindowPos(1),hWnd,HWND_TOP,dl,dt,dx,dy,SWP_NOZORDER));
gpPicture->Render(hDC, 0, 0, sx, sy, 0, hmHeight, hmWidth, -hmHeight, NULL);
4:窗口大小限制
case WM_GETMINMAXINFO:
((LPMINMAXINFO)lParam)->ptMaxPosition.x=dl;
((LPMINMAXINFO)lParam)->ptMaxPosition.y=dt;
((LPMINMAXINFO)lParam)->ptMaxSize.x=dx;
((LPMINMAXINFO)lParam)->ptMaxSize.y=dy;
((LPMINMAXINFO)lParam)->ptMaxTrackSize.x=dx;
((LPMINMAXINFO)lParam)->ptMaxTrackSize.y=dy;
break;
显示效果图:
编译后大小:2688字节
下载:
LoadPic.zip