16,548
社区成员




hBitmap=(HBITMAP)LoadImage(GetModuleHandle(NULL),ofn.lpstrFile,0,0,IMAGE_BITMAP,LR_LOADFROMFILE);
if(hBitmap==NULL)
{
::MessageBox(hWnd,_T("加载图片失败,可能是错误的bmp"),NULL,MB_ICONWARNING);
return 0;
}
ZeroMemory(&bitmap,sizeof(BITMAP));
GetObject(hBitmap,sizeof(BITMAP),&bitmap);
m_nHorzMaxSize=bitmap.bmWidth;
m_nVertMaxSize=bitmap.bmHeight;
m_nHorzPos=m_nVertPos=0;
//判断图片与客户区域的大小,分4种,高度多出,宽度多出,高、宽都多出,高宽都没有大于客户区域
RECT rect;
GetClientRect(hWnd,&rect);
if( (bitmap.bmHeight>rect.bottom) && (bitmap.bmWidth>rect.right))
uFlag=BOTH_ABOVE;
else if((bitmap.bmHeight<rect.bottom) && (bitmap.bmWidth>rect.right))
uFlag=ONLY_WIDTH_ABOVE;
else if((bitmap.bmHeight>rect.bottom) && (bitmap.bmWidth<rect.right))
uFlag=ONLY_HEIGHT_ABOVE;
else
uFlag=BOTH_BELOW;
//设置水平滚动条
SCROLLINFO si;
ZeroMemory(&si,sizeof(SCROLLINFO));
si.cbSize=sizeof(SCROLLINFO);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMax=m_nHorzMaxSize-1;
si.nMin=0;
si.nPage=m_nHorzPageSize;
SetScrollInfo(hWnd,SB_HORZ,&si,TRUE);
//设置垂直滚动条
ZeroMemory(&si,sizeof(SCROLLINFO));
si.cbSize=sizeof(SCROLLINFO);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMax=m_nVertMaxSize-1;
si.nMin=0;
si.nPage=m_nVertPageSize;
SetScrollInfo(hWnd,SB_VERT,&si,TRUE);
hOldBitmap=(HBITMAP)SelectObject(hMemDc,hBitmap);
DarwPic(hWnd, hMemDc,m_nHorzPos, m_nVertPos,bitmap,uFlag);
return 0;
static void DarwPic(HWND hWnd, HDC hMemDc, int nHorzPos,int nVertPos,BITMAP bitmap,unsigned short uFlag)
{
HDC hdc=GetDC(hWnd);
SetStretchBltMode(hdc,STRETCH_HALFTONE);
RECT rect;
GetClientRect(hWnd,&rect);
switch(uFlag)
{
case ONLY_HEIGHT_ABOVE:
StretchBlt(hdc,0,0,bitmap.bmWidth,rect.bottom,hMemDc,nHorzPos,nVertPos,bitmap.bmWidth,rect.bottom,SRCCOPY);
break;
case ONLY_WIDTH_ABOVE:
StretchBlt(hdc,0,0,rect.right,bitmap.bmHeight,hMemDc,nHorzPos,nVertPos,rect.right,bitmap.bmHeight,SRCCOPY);
break;
case BOTH_ABOVE:
StretchBlt(hdc,0,0,rect.right,rect.bottom,hMemDc,nHorzPos,nVertPos,rect.right,rect.bottom,SRCCOPY);
break;
case BOTH_BELOW:
StretchBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hMemDc,nHorzPos,nVertPos,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
break;
default:
break;
}
ReleaseDC(hWnd,hdc);
}
所有源码在: http://pan.baidu.com/share/link?shareid=211351&uk=1913319109The WM_NCPAINT message is sent to a window when its frame must be painted.
A window receives this message through its WindowProc function.
C++
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
Parameters
wParam
A handle to the update region of the window. The update region is clipped to the window frame.
lParam
This parameter is not used.