|
源码如下: m_static.Create("",WS_CHILD|WS_VISIBLE|WS_EX_STATICEDGE|WS_EX_TRANSPARENT| WS_EX_CLIENTEDGE,CRect(140,10,300,300),this,IDC_MYSTATIC)) 显示位图: hwnd=GetDlgItem(IDC_MYSTATIC); hwnd->GetClientRect(&rect); hDesDC = hwnd->GetDC()->m_hDC; hSrcDC = CreateCompatibleDC(hDesDC); hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(), "D:\\car.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); GetObject(hBitmap, sizeof(BITMAP), &bm); SelectObject(hSrcDC, hBitmap); hwnd->GetClientRect(&rect); ::SetStretchBltMode(hDesDC,COLORONCOLOR); ::StretchBlt(hDesDC, rect.left, rect.top, rect.right,rect.bottom, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,SRCCOPY); hwnd->GetClientRect(&rect); ::SetStretchBltMode(hDesDC,COLORONCOLOR); ::StretchBlt(hDesDC, rect.left, rect.top, rect.right,rect.bottom, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,SRCCOPY); |
|
|
|
你那些代码加在onpaint()里
干吗写两遍 hwnd->GetClientRect(&rect); ::SetStretchBltMode(hDesDC,COLORONCOLOR); ::StretchBlt(hDesDC, rect.left, rect.top, rect.right,rect.bottom, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,SRCCOPY); |
|
|
直接用PictureBox好了
|
|
|
直接用Picture控件好了
上面的代码应该写在OnPaint中 |
|
|
1.可能使风格设置有问题,去掉WS_EX_TRANSPARENT
2.建议用Picture控件 3.代码写在控件的父窗口的OnUpdate()中试一下 |
|