William Chan
William Chan

Reputation: 297

C++ WinAPI Display bitmaps on the custom window frame using DWM

I have created a window with custom window frame using DWM with the reference to Custom Window Frame Using DWM. I tried to add a bitmap to the title bar using StretchBlt. Yet, it did not show properly. The image will be brightened if it is drawn on the frame:

enter image description here

If the frame is black, the image shows properly. How do you solve this problem?

HDC hdc;
PAINTSTRUCT ps;
HBITMAP hbm=(HBITMAP)LoadImage(NULL,"C:\\Users\\admin\\Desktop\\Bitmap32.bmp",
                               IMAGE_BITMAP,166,160,LR_LOADFROMFILE);
hdc=BeginPaint(hWnd,&ps);
HDC hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hbm);
StretchBlt(hdc,0,0,166,160,hdcMem,0,0,166,160,SRCCOPY);
DeleteDC(hdcMem);
EndPaint(hWnd,&ps);

Upvotes: 2

Views: 1035

Answers (1)

William Chan
William Chan

Reputation: 297

Use GDI+ DrawImage()

Graphics graphics(hdc);
Image image(L"image link");
graphics.DrawImage(&image,0,0);

To solve the real problem, use SetLayeredWindowAttributes() to set the transparency key.

SetWindowLong(hWnd,GWL_EXSTYLE,WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd,RGB(200,201,202),0,LWA_COLORKEY);

Upvotes: 2

Related Questions