如何从元素中卸载图片 [英] how can I unload a picture from an element
本文介绍了如何从元素中卸载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 SendMessage 从元素中卸载图片我试图这样做:
how can I unload a picture from an element using SendMessage I tried to do this:
SendMessage(hWnd, BM_SETIMAGE, IMAGE_BITMAP, 0);
但没有帮助
HBITMAP mLoadImg(const WCHAR* szFilename)
{
HBITMAP result = NULL;
Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename, false);
bitmap->GetHBITMAP(NULL, &result);
delete bitmap;
return result;
}
void displayImage(HBITMAP mBmp, HWND mHwnd)
{
RECT myRect;
BITMAP bm;
HDC screenDC, memDC;
HBITMAP oldBmp;
BLENDFUNCTION bf;
GetObject(mBmp, sizeof(bm), &bm);
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0xff;
bf.AlphaFormat = AC_SRC_ALPHA;
screenDC = GetDC(mHwnd);
GetClientRect(mHwnd, &myRect);
if (mBmp == NULL)
FillRect(screenDC, &myRect, (HBRUSH(CreateSolidBrush(RGB(50, 151, 151)))));
else
{
memDC = CreateCompatibleDC(screenDC);
oldBmp = (HBITMAP)SelectObject(memDC, mBmp);
AlphaBlend(screenDC, 0, 0, myRect.right, myRect.bottom, memDC, 0, 0, bm.bmWidth, bm.bmHeight, bf);
SelectObject(memDC, oldBmp);
DeleteDC(memDC);
ReleaseDC(mHwnd, screenDC);
}
}
放置图像的代码.我需要在将鼠标悬停在按钮上时更改图像,我决定这样做,以便删除旧图像并放置新图像
code for put image. I need to change the image when hovering over the button, I decided to do this so that the old image is removed and a new one is placed
推荐答案
正如@IInspectable 在 您的另一个问题,您只需要使用 BS_BITMAP
或 BS_ICON
窗口样式和 BM_SETIMAGE 消息.
以下代码片段对我有用.
As @IInspectable said in your another question, you just need to use the BS_BITMAP
or BS_ICON
window styles and BM_SETIMAGE message.
Following code snippet works for me.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
HWND d = CreateWindow(L"BUTTON", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP | BS_NOTIFY,
10, 10, 180, 180, hWnd, (HMENU)BUTTON_ID, hInst, 0);
HBITMAP hbit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
SendMessage(d, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbit);
}
break;
case WM_COMMAND:
{
switch (HIWORD(wParam))
{
case BN_SETFOCUS:
SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_BITMAP, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
这篇关于如何从元素中卸载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文