Advertisement

Screen-Mate and f***ing Windows-Painting

Started by June 19, 2001 02:26 AM
8 comments, last by Chefbrenner 23 years, 7 months ago
Hi Folks! I''m currently trying to create my own screen mate...you know, the silly bitmap cats/dogs/guys/etc. that walk around on your desktop and do some silly stuff. My major problem is the drawing of the bitmaps! I need an algorithm to draw the bitmaps TRANSPARENT onto the desktop (with a transparent color I decide and without some ugly cloning effects when I move the window...) Any ideas? Thx
Greetings,ChefbrennerRemember: If it breaths it can be killed!
Maybe the tutorial at www.winprog.org will answer your question
since it covers animation with win32 programming without any
other external graphic libraries.
Red.
Advertisement
Look for something on "Masking in GDI". It isn''t really fast, but it''s not too slow.

[Resist Windows XP''s Invasive Production Activation Technology!]
Thanx for the tip! Got anything more specific about this?
Greetings,ChefbrennerRemember: If it breaths it can be killed!
I think there is an example of something like this in the DD SDK.

Called, um, Donut? It was in the DD6 SDK anyway.

thi sis my si gitzt hebezt
thi sis my si gitzt hebezt
Transperant blitting...

What you need is a mask. To make a mask, in paintbrush(or where-ever) color any areas you want transparent as a crazy color you don''t want to use. (most use bright pink). Now, when you load that in, create a same size buffer. IE, for a 32x32 image, make another 32x32 area in memory. Now, go through the original pixel by pixel. If it''s the crazy color, paint the buffer white, and color the original pixel black. If it''s not the crazy color, paint the buffer black, and leave the original alone. Now, you have to blit them both down on top of each other, in a certain order with a certain blit command. (ie AND vs OR vs XOR etc...). I forget which one you blit down first (the original or the buffer/mask), and which blit command you use (and i''m too dumb right now to guess with authority). I''ll get back to you.
Advertisement
Hey,

I made a cute little doggy walking on the desktop, climbing on windows and menu''s myself.

The technique I use was windows Regions. (look them up in msdn or some other win32api help resource you got). This is the same technique that is used for the Office Agent.

The DirectX Donut example mentioned in an earlier post, works fine if your agent doesn''t move, neither the background will be changed (minimizing a windorw orso...wich probably will happen!)

DirectX also includes overlay''s, which do the same, but they don''t work on all videocards (actually on very few) so don''t use them.

The regions work fine, although the ''magic'' sheep (you''ll certainly know that one) doesn''t make use of them. But yeah...that one did already work on windows 3.11....

One Region tip: when you assign a region to a window, you will loose it!!! So make a copy of it before assigning, otherwise weird bugs will come up!

BoRReL
Thanx, anonymous one!
Windows Regions? Hmm... I'll try to find something about that!

By the way...would you be so kind and write me a mail with some info how I can contact you if I can't solve some problems?
THX!

Edited by - Chefbrenner on June 20, 2001 4:38:08 AM
Greetings,ChefbrennerRemember: If it breaths it can be killed!
P.S.: Of course I'm still happy about any other suggestions how to draw transparent and moving bitmaps without any weird graphic bugs (without using of DX or anything similar).

Edited by - Chefbrenner on June 20, 2001 5:08:25 AM
Greetings,ChefbrennerRemember: If it breaths it can be killed!
Hey,

de code I used for blitting:

CAgent::DrawBitmap(HDC hdc, int x, int y, HBITMAP hbm, int frame)
{
HDC hdcMem; /* Handle of memory context to use in drawing bitmap */
HBITMAP oldBm;
POINT ptSize, ptOrg;
BITMAP bm;

hdcMem = CreateCompatibleDC(hdc);
if (hdcMem != (HDC)NULL)
{
// Select bitmap to be draw into memory context
oldBm = (HBITMAP)SelectObject(hdcMem, hbm);


// Set the mapping mode for the memory context to match the
// target device context.
SetMapMode(hdcMem, GetMapMode(hdc));


// Get the details of the bitmap being drawn
GetObject(hbm, sizeof(BITMAP), (LPSTR)&bm);


// Adjust height and width for mapping mode
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
DPtoLP(hdc, (LPPOINT)&ptSize, 1);

// Adjust origin for mapping mode
ptOrg.x = frame*32;
ptOrg.y = 0;
DPtoLP(hdcMem, (LPPOINT)&ptOrg, 1);


// Draw the bitmap
BitBlt(hdc, x, y, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y, SRCCOPY);


// Clean up
SelectObject(hdcMem, oldBm);
DeleteDC(hdcMem);

return TRUE;
}
return FALSE;
}

hdc is the device context of the window you want to blit to.
The function is used this way:

HDC hdc=GetDC(WindowHandle);
DrawBitmap( hdc, 0, 0, Bitmap, frame);
ReleaseDC(WindowHandle,hdc);

frame is used as an offset in the bitmap to specify which 32x32 block is going to be blitted.

Initialize the bitmap like this (from resource):
Bitmap = (HBITMAP) LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_DOGGY), IMAGE_BITMAP, 0,
0, LR_CREATEDIBSECTION);

That''s it! (Any comments?!?)

GR,
BoRReL

This topic is closed to new replies.

Advertisement