🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Win32 GDI - Need help Adding a bitmap to this example

Started by
37 comments, last by aston2 4 years, 2 months ago

In regards to the message pump and painting, this is how I do it on my 2d game engine.

    // Run the message loop
    while(GetMessage(&msg,NULL,0,0))
    {
        // process messages
        TranslateMessage(&msg);
        DispatchMessage(&msg);

        // always force a redraw for the game loop
        if(GetFocus()==hWnd)InvalidateRect(hWnd,NULL,false);
    }

As long as the window is active, it gets invalidated, forcing a redraw. When the window goes out of focus, the game engine stops rendering because WM_PAINT messages stop. This is the simplest way to do it.

The other message pump I tried involved PeekMessage() but was much more sophisticated.

Advertisement

@aston2 I think you are using some old code that I posted before. I haven't done anything which requires keyboard input from the user so I can't help much with that. Have a look at these sources. They demonstrate how to get input, use a global double buffer and DirectSound. I pretty much re-did my program based on the Frogger code.

@rafaelsantana I'm using PeekMessage in my program, but the GetFocus line doesn't work anymore. The program continues to run and use resources even when another window has focus.

None

@Airbatz…

That is my problem about global double bufering for sprite ,i don't need DirectSound

yet . I get it to work another sprite moving with arrow keys and that part work.

@hplus-google suggested me using INVALID_HANDLE_VALUE ..i cannot figured what is that constant or integer value mean ???

As far I understand that i need to paint each bitmap and bitmap(mask) at a same time

and looks to me that this method work with standard message loop.

I use PeekMessage in another compiler and also work well but only for game type

programs ( also work well in toy interpreters etc).

@Airbatz…

I already loked at vaz-games but they are in C++ not in C and few examples are not

simple to understand for someone like me.

Do you maybe know for some other sites where i can found more win32 GDI examples in C (migw-version not MS )

@aston2

I'm still trying to get my head around the global double buffer implementation even though I've done it, but the concept is simple enough. It is much simpler to use TransparentBlt instead of BitBlt with mask, and it will save you a lot of headaches!

I use PeekMessage because the program is constantly looping an animation. I'll post my current code at some stage, as it's much cleaner than the original.

The code by Phil Vaz is in C, but he makes some C++ calls to DirectSound. The reason the files have a .cpp extension is because the code was written in VC++6.0 which doesn't seem to like files ending with a .c extension. The majority of stuff you will find on the internet is unfortunately in C++ but the concepts are the same.

I compile all my code in CodeBlocks with Mingw because VC++6.0 tends to produce larger executables, even when compiling to a release target. Take a look at CodeProject and CodeGuru. These websites have examples (still mostly in C++). Also do a search for Win32 GDI on GitHub and filter the search to show only C results.

None

Hello Airbatz

Yes unfortunatelly most of examples are in C++ , which are somehow confusing to me .

As i said before i am using another basic compiler called Oxygen Basic which compile

also directly to standalone exe and i have few sources with double buffering where

work very well …for me is easier convert C program then C++ which i don't like because is to much OOP centric.

For TransparentBlt…i don't know why but my verison of MingW with Falcon IDE not

work with that function ,i constantly get some errors so that is why i use BitBlt.

For TransparentBlt, you need to link to libmsimg32 in your compiler settings, otherwise it won't work.

None

Thanks Airbatz…

Ok i will try first to translate this program in Oxygen Basic ,and if there work then should work in C too..i hope!

This topic is closed to new replies.

Advertisement