tags:

views:

3078

answers:

8

What's a simple way to implement a c++ Win32 program to...
- display an 800x600x24 uncompressed bitmap image
- in a window without borders (the only thing visible is the image)
- that closes after ten seconds
- and doesn't use MFC

Thanks in advance for your help!

A: 

What part of the problem is that you're having problems with?

Lasse V. Karlsen
+1  A: 
  • Use LoadImage to load the bitmap
  • Use CreateWindowEx to create the window.
  • In the window proc capture the WM_PAINT. Use BitBlt to paint the bitmap.
Ken
+2  A: 

Register a class for the splash window and create a window using these styles:

  • WS_POPUPWINDOW: will make sure your window has no caption/sysmenu
  • WS_EX_TOPMOST: will keep the splash screen on top of everything. Note that this is a bit intrusive. It might be better to just make the splash window a child of your main window. You may have to manipulate the z-order, though, to keep any other popup windows (if you create any) below the splash screen.

Use CreateDIBSection to load the bitmap. It should be easy, since BMP files are essentially dumps of DIB structures. Or do what Ken said and use LoadImage.

Handle the WM_PAINT or WM_ERASEBKGND message to draw the bitmap on the window.

On WM_CREATE set a timer of 10 seconds and when Windows sends the WM_TIMER message, have the window destroy itself.

efotinis
+2  A: 

The key point here is to use layered window.

You can start with a win32 wizard generated project and change CreateWindow call to CreateWindowEx and set WS_EX_LAYERED as extended window style and combination of WS_POPUP and WS_SYSMENU as window style. When you do that launch your application it will be invisible. Then you should use UpdateLayeredWindow to paint your image. You may also need AlphaBlend function if you want use PNG image with alpha layer.

Hope this helps!

Serge
+1  A: 

It's a Win32 api FAQ

See professional Win32api forum news://194.177.96.26/comp.os.ms-windows.programmer.win32 where it has been answered hundreds of times for 20 years..

+1  A: 

You can:

  • Create a dialog in your resource file
  • Have it contain a Picture control
  • Set the picture control type to Bitmap
  • Create/import your bitmap in the resource file and set that bitmap ID to the picture control in your dialog
  • Create the window by using CreateDialogParam
  • Handle the WM_INITDIALOG in order to set a timer for 10 seconds (use SetTimer)
  • Handle WM_TIMER to catch your timer event and to destroy the window (use DestroyWindow)
Dan Cristoloveanu
+3  A: 

If you're targeting modern versions of Windows (Windows 2000) and above, you can use the UpdateLayeredWindow function to display any bitmap (including one with an alpha channel, if so desired).

I blogged a four-part series on how to write a C++ Win32 app that does this. If you need to wait for exactly ten seconds to close the splash screen (instead of until the main window is ready), you would need to use Dan Cristoloveanu's suggested technique of a timer that calls DestroyWindow.

Bradley Grainger
A: 

Hi

But i have successfuly create the splash screen but it is not getting displayed in window vista. And i am confermed that this is due to the use of UpdateLayeredWindow and AlphaBlend functions. I am trying to display the PNG inage as a splash screen and its working awesome on windows XP. Can anybody help me on this issue as i have waste a lot of my time and effort.

Thanks in advance

Deepak

Deepak