Archived

This topic is now archived and is closed to further replies.

Daishim

Win GDI functions?

Recommended Posts

I have a few questions about the WinGDI. 1. Does the WinGDI have a transparent blit function or do I have to do an SRCAND and then SRCPAINT all the time? 2. Does the WinGDI have a way to do alpha blending? Or do I have to somehow do the blending myself? How? 3. Is there a way to use buffers with winGDI? Thanks in advance...

Share this post


Link to post
Share on other sites
The Win32 GDI has several functions to do what you want:

TransparentBlt() will do transparent blits:

BOOL TransparentBlt(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int hHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
UINT crTransparent
);

AlphaBlend() will do alpha blending:

AlphaBlend(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int hHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
BLENDFUNCTION blendFunction
);

AlphaBlend() may not work properly if you try to use it on a large area, like the whole screen. But it does work on small parts of the screen.

I don''t recommend either of these two functions because they are slow. But if you did your alpha blending using GDI, it''d still probably be just as slow.

As for the buffers question, yes you can, sort of:

  
HDC hWindowDC;
HDC hMemoryDC;
RECT rect;
HBITMAP hbitmap;

hWindowDC = GetDC(hwnd);
hMemoryDC = CreateCompatibleDC(hWindowDC);
GetClientRect(hwnd, &rect);
hbitmap = CreateCompatibleBitmap(hWindowDC, rect.right, rect.bottom);
SelectObject(hMemoryDC, hbitmap);
PatBlt(hMemoryDC, 0, 0, rect.right, rect.bottom, WHITENESS);
//You can now use MemoryDC to draw stuff.

//Draw what you want, and then do this:

BitBlt(hWindowDC, 0, 0, rect.right, rect.bottom, hMemoryDC, 0, 0, SRCCOPY);
ReleaseDC(hwnd, hWindowDC);
DeleteDC(hMemoryDC);
DeleteObject(hbitmap);

Share this post


Link to post
Share on other sites
Those API functions require Windows 98 or later, or Windows 2000 or later. If your app runs on any other system, it will fail; to avoid this, you''ll need to dynamically link to them.

Share this post


Link to post
Share on other sites