Hi,
I want to run an animation(in essence). I want to draw multiple images (possibly .bmps, but I'd like other formats as well.) on to the screen each frame.
I tried to do this with some C++ code, but it isn't working as it should (As I'm expecting it to I guess.). Can anyone please help me?
Here's the class definition. Just for the variables. -
class CWorld
-
{
-
private:
-
-
//Window DC
-
HDC windowDC;
-
//This is the backbuffer. We incrementally draw onto this and paste to the actual window DC once. This reduces flicker.
-
HDC bufferDC;
-
//This is a utility DC that will be used to load bitmaps into and pasting them to the back buffer.
-
HDC memDC;
-
-
//The bitmap for the buffer.
-
HBITMAP hBufferBitMap;
-
-
public:
-
BOOL DrawFrame();
-
-
CWorld(HDC windowDC);
-
~CWorld(void);
-
};
-
ctor. -
CWorld::CWorld(HDC windowDC)
-
{
-
this->windowDC = windowDC;
-
-
this->bufferDC = NULL;
-
this->bufferDC = ::CreateCompatibleDC(windowDC);
-
-
this->memDC = NULL;
-
this->memDC = ::CreateCompatibleDC(this->bufferDC);
-
-
HBITMAP hbmBuffer = ::CreateCompatibleBitmap( this->bufferDC,
-
::GetDeviceCaps(this->bufferDC, HORZRES),
-
::GetDeviceCaps(this->bufferDC, VERTRES));
-
HBITMAP h = (HBITMAP)::SelectObject(this->bufferDC, hbmBuffer);
-
-
//Check for errors.
-
}
-
The drawing code. -
BOOL CWorld::DrawFrame()
-
{
-
static HBITMAP testBmp = (HBITMAP)::LoadImageA(NULL, "C:\\dota.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
-
-
HBITMAP memOld = (HBITMAP)::SelectObject(this->memDC, testBmp);
-
-
//A white background.
-
::PatBlt( this->bufferDC, 0, 0,
-
GetDeviceCaps(this->bufferDC, HORZRES), GetDeviceCaps(this->bufferDC, VERTRES),
-
WHITENESS);
-
-
//BitBlt the .bmp onto the back buffer.
-
::BitBlt( this->bufferDC, 0, 0,
-
GetDeviceCaps(this->bufferDC, HORZRES), GetDeviceCaps(this->bufferDC, VERTRES),
-
this->memDC, 0, 0,
-
SRCCOPY);
-
-
//BitBlt the back buffer to the window DC.
-
::BitBlt( this->windowDC, 0, 0,
-
GetDeviceCaps(this->windowDC, HORZRES), GetDeviceCaps(this->windowDC, VERTRES),
-
this->bufferDC, 0, 0,
-
SRCCOPY);
-
-
-
::SelectObject(this->memDC, memOld);
-
-
return TRUE;
-
}
-
I fiddled around with the code for sometime but couldn't get it done.
I have couple of questions on this. I'd be grateful if anyone can help me.
1. Why doesn't my code show the .bmp on the screen?(Of course) All I see is a white window.
2. As you may have noticed, I used 3 DCs. One is the actual DC of the window.
I have a DC, bufferDC which I use for drawing behind. The other, memDC is just something I used for loading the bmp onto. I wouldn't have needed this if I only wanted to paint one image. But, as I want to draw more than one image, I thought I needed this to load the bmp into, and then to paste it onto the bufferDC. Is this the way to do this? Or is there a better way?
3. I saw somewhere that HBITMAPs use OS resources. That sounds bad. So, if I want lots of images in my app, would that create a problem? If so, is there any way around it? Without of course, using OpenGL or some lib.
Thanks!
2 2862
Hi DumRat,
I'm actually working on similar types of stuff at the moment for the first time. Having never really done any windows handle based drawing I'm trying to understand it and have now decided to try and replicate the functionality with some simple cross-platform graphics libraries.
Now unfortunately I'm not good enough to tell you where your program is wrong, but can I suggest that you:
a) Check the bufferDC bits to see if you've managed to get any data into it.
b) Try setting the colour of a pixel, or drawing a primative (e.g. line, point) to your display handle to check that its working...
In answer to question 3, as that is almost exactly what I'm working on, one way of improving performance is through tiling the images. Once tiled you can then store them in memory, or to files and through caching can actually obtain pretty decent results.
Heres a couple suggestions (please note i haven't done WIN32 in a while). I don't know why you need to draw multiple bitmaps at one time. The animation should only display 1 image a frame (unless your trying transparent bitmaps, but thats another topic). Then at a certain rate (what fps you want the animation to run) you will replace that image with the next one in the animation.
First i would load the bitmaps into memory (unless your talking about 100's of bitmaps) something like: HBITMAP AnimationBitmap s[10]; Then i would load the bitmaps into the array. You will need a timer to run on the system and replace the bitmap on the screen with the next one in the AnimationBitmap array.
Also try what Ian said. Try drawing simple shapes to the MemDC, then try drawing just 1 bitmap. If those work, then work on getting the animation working.
Is there a reason why you are doing this in WIN32 or can you use other libraries?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Me Mine |
last post by:
i,
I have trying to code a small console app that will
allow a user to select a window and then create a
screen capture of the window. I haven't been able to
figure out how to do the screen capture part. The
code is as follows, the commented out lines at the end
are things I have tried, but don't work. Whenever I
try to create a compatibe Bitmap or DC it comes back
with an error as
win32ui: CreateCompatibleDC failed
|
by: gregory_may |
last post by:
Is there a way to grab a "Screen Shot" that includes "Tool Tips"? I saw
this code someplace, cant remember where. But it doesnt grab "Tool Tips".
Is there a better way to do this in .net?
Thanks!
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, ByVal lpInitData As String) As Integer
|
by: Johan |
last post by:
Hello,
I'm trying to get a part of the regular screen onto my own dialog
box....
Does anyone know how to do this?? (I guess i have to BitBlt something
to something (HDC handle; handle= GetDC(NULL); for screen?? and
then??)
Thanks for ANY help (tried to do this all day now!)
|
by: xc |
last post by:
Greetings.
I encountered a wield problem when grabing screen images.
Sometimes in some computers I can capture the screen, but other times not
so.
In some computer I cannot capture the screen image, but when I change its
color bits, say from 32bits to 24 or 16bits, the program can capture the
image.
Can anyone kindly examine my following code, and point out the flaw:
|
by: Wayne |
last post by:
In a Delphi application I would use GetDC passing the handle of the window I
wanted to capture, then with the handle and a caption I would be able to
convert the image to a bitmap. I would like to be able to do this in
C#/.net, but I don't know where to start.
Can someone point me in the right direction?
Thanks
Wayne
| |
by: Rajat Tandon |
last post by:
Hello there,
I am relatively new to the newsgroups and C#. I have never been disappointed
with the groups and always got the prompt replies to my queries.This is yet
another strange issue, I am facing. Please please help me to solve this as
soon as possible.
So here we go ...
I am not able to take the screen shot of the windows form based "Smart
|
by: fong01 |
last post by:
Hi,
Below source code I have try on Win 2k, XP & 2003 is work, but I try on
win 98 & ME the screen is capture black screen.
Dim dInt_dwRop As Integer = &HCC0020
Dim dImg As New
System.Drawing.Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
System.Drawing.Imaging.PixelFormat.Format16bppRgb565)
|
by: Eddie Dunn |
last post by:
I have one here that I cannot find anything on in my searching.
I am implementing a screen capture functionality into my Visual Basic
..NET application.
The code I am using calls the bitblt function in gdi32.dll to achieve
its magic as follows:
Public Function CreateScreenshot() As Bitmap
|
by: Steven |
last post by:
Hi,
I want to create an image that looks exactly the same as the things I see in
my application.
I have an application in which you can create some controls, drag them
anywhere you like.
Now I want to export these controls to an image. The image should reflect
the position of the controls and the controls should look the same in the
picture as they do on the screen.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |