NO

Author Topic: Splash Screen  (Read 4961 times)

czerny

  • Guest
Splash Screen
« on: December 24, 2014, 11:19:24 AM »
This example drives me crazy.  :'(

There should be a fade in splash screen at startup and when the button is pressed.
But nothing is seen.

I tried so many variants, but nothing worked.
It is not easy to debug the WM_TIMER code without disturb the timing. But it should be ok.

Can anybody bring some light in this ...

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Splash Screen
« Reply #1 on: December 24, 2014, 08:59:59 PM »
First problem: modeless dialog need an external message pump that routes the window messages.
You have used a dialog box that use a private message pump and don't routes the messages.
Have a look to IsDialogMessage.
The second problem seems to be that your bitmap is not an alpha channel bitmap. Long times ago I wrote a GDI library to handle images, sprites and basic 2D animation, but never pubblished it, I'll try to extract some basic code to make the conversion. Let me do some check.
Merry Xmas!

Edit: I added my routines for alpha channel conversion and modified some parts of the code. Now it works even without message pump!!!!!  ;D
« Last Edit: December 25, 2014, 12:38:59 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

czerny

  • Guest
Re: Splash Screen
« Reply #2 on: December 25, 2014, 12:51:31 AM »
First problem: modeless dialog need an external message pump that routes the window messages.
The parent is a modal dialog. So who could I do that?.
The second problem seems to be that your bitmap is not an alpha channel bitmap.
I do not need a per pixel alpha. The bitmap is from an MFC example and it works ok there. I have detected one error in my code, compared with the original: I have used AC_SRC_ALPHA for AlphaFormat. The original uses 0. But it does not work anyway.

Another thing I don't understand: Even a BitBlt instead of the AlphaBlend shows nothing!

I have appended the original mfc-project!

The fade in is a little bit smoother in the original, isn't it?

Lightfull days for you, Frankie!
« Last Edit: December 25, 2014, 01:51:10 AM by czerny »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Splash Screen
« Reply #3 on: December 25, 2014, 01:46:51 AM »
Well the modeless dialog is a child window of a dialogbox and receives messages from its message pump as side effect.
Try:
Code: [Select]
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
void *sd = SplashDlgNew(hInstance, NULL, IDB_SPLASH);
SplashDlgShow(sd, 5000);
for(;;);
return 0;
}
Nothing happen, it don't works because the timer message is not routed. No function called GetMessage so no messages queue will be created for this process.

But This Works (even if the process don't terminate):
Code: [Select]
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
void *sd = SplashDlgNew(hInstance, NULL, IDB_SPLASH);
SplashDlgShow(sd, 5000);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
return 0;
}

The bitmap is 32bits, but not alpha type. MFC will perform some transformation on the bitmap to make it compatible with alpha channel images.
Where is the original example?

Anyway I'm happy that my code solved your problem!
« Last Edit: December 25, 2014, 02:00:34 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Splash Screen
« Reply #4 on: December 25, 2014, 03:18:52 AM »
The second problem seems to be that your bitmap is not an alpha channel bitmap.
I do not need a per pixel alpha. The bitmap is from an MFC example and it works ok there. I have detected one error in my code, compared with the original: I have used AC_SRC_ALPHA for AlphaFormat. The original uses 0. But it does not work anyway.

Another thing I don't understand: Even a BitBlt instead of the AlphaBlend shows nothing!
The error is very simple (but I took a while to found it). In the SplashDlgProc the line:
Code: [Select]
HBITMAP old = SelectObject(dcmem, &d->bitmap);
is wrong. replace with:
Code: [Select]
HBITMAP old = SelectObject(dcmem, d->bitmap);
And even your original code will work  :D

The fade in is a little bit smoother in the original, isn't it?
The MFC code updates the window every millisecond (absolutely unusefull), but the brightness increments of uniits while in your code jumps 10 levels each cycle.

Lightfull days for you, Frankie!
Lightfull days to you too...
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

czerny

  • Guest
Re: Splash Screen
« Reply #5 on: December 25, 2014, 09:48:59 AM »
The error is very simple (but I took a while to found it). In the SplashDlgProc the line:
Code: [Select]
HBITMAP old = SelectObject(dcmem, &d->bitmap);
is wrong. replace with:
Code: [Select]
HBITMAP old = SelectObject(dcmem, d->bitmap);
And even your original code will work  :D

Lightfull days to you too...
Ahhh! Wonderful!